Skip to content

Commit

Permalink
Merge pull request #1390 from sapayth/enhance/add_visibility_to_the_c…
Browse files Browse the repository at this point in the history
…olumns_field

enhance: add visibility to the Columns field
  • Loading branch information
sapayth authored Jan 24, 2024
2 parents d551c9d + e755057 commit 180e0e9
Show file tree
Hide file tree
Showing 5 changed files with 464 additions and 49 deletions.
62 changes: 36 additions & 26 deletions includes/Admin/Upgrades.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ class Upgrades {
* @var array
*/
private static $upgrades = [
'2.1.9' => 'upgrades/upgrade-2.1.9.php',
'2.6.0' => 'upgrades/upgrade-2.6.0.php',
'2.7.0' => 'upgrades/upgrade-2.7.0.php',
'2.8.0' => 'upgrades/upgrade-2.8.0.php',
'2.8.2' => 'upgrades/upgrade-2.8.2.php',
'2.8.5' => 'upgrades/upgrade-2.8.5.php',
'2.9.2' => 'upgrades/upgrade-2.9.2.php',
'3.6.0' => 'upgrades/upgrade-3.6.0.php',
'2.1.9' => 'upgrades/upgrade-2.1.9.php',
'2.6.0' => 'upgrades/upgrade-2.6.0.php',
'2.7.0' => 'upgrades/upgrade-2.7.0.php',
'2.8.0' => 'upgrades/upgrade-2.8.0.php',
'2.8.2' => 'upgrades/upgrade-2.8.2.php',
'2.8.5' => 'upgrades/upgrade-2.8.5.php',
'2.9.2' => 'upgrades/upgrade-2.9.2.php',
'3.6.0' => 'upgrades/upgrade-3.6.0.php',
'4.0.4' => 'upgrades/upgrade-4.0.4.php',
];

/**
Expand Down Expand Up @@ -52,13 +53,13 @@ public function get_version() {
* @return bool
*/
public function needs_update() {

// may be it's the first install
if ( ! $this->get_version() ) {
return false;
}
//check if current version is greater then installed version and any update key is available
if ( version_compare( $this->get_version(), WPUF_VERSION, '<' ) && in_array( WPUF_VERSION,
array_keys( self::$upgrades ) ) ) {
// check if current version is greater than installed version and any update key is available
if ( version_compare( $this->get_version(), WPUF_VERSION, '<' ) && in_array( WPUF_VERSION, array_keys( self::$upgrades ), true ) ) {
return true;
}

Expand All @@ -71,20 +72,26 @@ public function needs_update() {
* @return void
*/
public function perform_updates() {
if ( empty( $_GET['wpuf_do_update'] ) ) {
if ( ! isset( $_GET['nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['nonce'] ) ), 'wpuf_do_update' ) ) {
return;
}
if ( ! sanitize_text_field( wp_unslash( $_GET['wpuf_do_update'] ) ) ) {

if ( empty( $_GET['wpuf_do_update'] ) || ! sanitize_text_field( wp_unslash( $_GET['wpuf_do_update'] ) ) ) {
return;
}

$installed_version = $this->get_version();
$path = trailingslashit( __DIR__ );

foreach ( self::$upgrades as $version => $file ) {
if ( version_compare( $installed_version, $version, '<' ) ) {
include $path . $file;
$path = WPUF_ROOT . '/includes/' . $file;
if ( file_exists( $path ) ) {
include_once $path;
}
update_option( 'wpuf_version', $version );
}
}

update_option( 'wpuf_version', WPUF_VERSION );
}

Expand All @@ -99,23 +106,26 @@ public function show_upgrade_notice() {
if ( ! current_user_can( 'update_plugins' ) || ! $this->needs_update() ) {
return;
}

if ( $this->needs_update() ) {
$url = ! empty( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
$url = ! empty( $_SERVER['REQUEST_URI'] ) ? sanitize_text_field( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
$link = add_query_arg(
[
'wpuf_do_update' => true,
'nonce' => wp_create_nonce( 'wpuf_do_update' ),
],
$url
);
?>
<div id="message" class="updated">
<p><?php printf( '<strong>%s</strong>',
esc_attr__( 'WPUF Data Update Required', 'wp-user-frontend' ) ); ?></p>
<p class="submit"><a
href="<?php echo esc_url( add_query_arg( [ 'wpuf_do_update' => true ], $url ) ); ?>"
class="wpuf-update-btn button-primary"><?php esc_attr_e( 'Run the updater',
'wp-user-frontend' ); ?></a></p>
<p><?php printf( '<strong>%s</strong>', esc_attr__( 'WPUF Data Update Required', 'wp-user-frontend' ) ); ?></p>
<p class="submit"><a href="<?php echo esc_url( $link ); ?>" class="wpuf-update-btn button-primary"><?php esc_attr_e( 'Run the updater', 'wp-user-frontend' ); ?></a></p>
</div>

<script type="text/javascript">
jQuery( '.wpuf-update-btn' ).click( 'click', function () {
return confirm( '<?php esc_attr_e( 'It is strongly recommended that you backup your database before proceeding. Are you sure you wish to run the updater now?',
'wp-user-frontend' ); ?>' );
} );
jQuery('.wpuf-update-btn').click('click', function() {
return confirm( '<?php esc_attr_e( 'It is strongly recommended that you backup your database before proceeding. Are you sure you wish to run the updater now?', 'wp-user-frontend' ); ?>' );
});
</script>
<?php
}
Expand Down
70 changes: 48 additions & 22 deletions includes/Fields/Form_Field_Column.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,15 @@ public function render( $field_settings, $form_id, $type = 'post', $post_id = nu
$columns_size = $field_settings['inner_columns_size'];
$column_space = $field_settings['column_space'];
$inner_fields = $field_settings['inner_fields'];
$atts = []; ?>
<li class="wpuf-el">
$id = ! empty( $field_settings['id'] ) ? $field_settings['id'] : 0;
$atts = [];
$input_type = 'column_field';
$class_names = ! empty( $field_settings['css'] ) ? ' ' . $field_settings['css'] : '';
$class_names .= ' wpuf_' . $input_type . '_' . $id . '_' . esc_attr( $form_id );
printf(
'<li class="wpuf-el %s%s" data-label="%s">', esc_attr( $input_type ), esc_attr( $class_names ), 'wpuf-column-field'
);
?>
<div class="wpuf-field-columns <?php echo 'has-columns-' . esc_attr( $columns ); ?>">
<div class="wpuf-column-field-inner-columns">
<div class="wpuf-column">
Expand Down Expand Up @@ -93,7 +100,26 @@ public function get_options_settings() {
],
];

return apply_filters( 'wpuf_text_field_option_settings', $options );
if ( is_wpuf_post_form_builder() ) {
$options[] =
[
'name' => 'wpuf_visibility',
'title' => __( 'Visibility', 'wp-user-frontend' ),
'type' => 'visibility',
'section' => 'advanced',
'options' => [
'everyone' => __( 'Everyone', 'wp-user-frontend' ),
'hidden' => __( 'Hidden', 'wp-user-frontend' ),
'logged_in' => __( 'Logged in users only', 'wp-user-frontend' ),
'subscribed_users' => __( 'Subscription users only', 'wp-user-frontend' ),
],
'priority' => 30,
'inline' => true,
'help_text' => __( 'Select option', 'wp-user-frontend' ),
];
}

return apply_filters( 'wpuf_column_field_option_settings', $options );
}

/**
Expand All @@ -102,28 +128,28 @@ public function get_options_settings() {
* @return array
*/
public function get_field_props() {
$props = [
'input_type' => 'column_field',
'template' => $this->get_type(),
'id' => 0,
'is_new' => true,
'is_meta' => 'no',
'columns' => 3,
'min_column' => 1,
'max_column' => 3,
'column_space' => '5',
'inner_fields' => [
'column-1' => [],
'column-2' => [],
'column-3' => [],
return [
'input_type' => 'column_field',
'template' => $this->get_type(),
'id' => 0,
'is_new' => true,
'is_meta' => 'no',
'columns' => 3,
'min_column' => 1,
'max_column' => 3,
'column_space' => '5',
'inner_fields' => [
'column-1' => [],
'column-2' => [],
'column-3' => [],
],
'inner_columns_size' => [
'column-1' => '33.33%',
'column-2' => '33.33%',
'column-3' => '33.33%',
'column-1' => '33.33%',
'column-2' => '33.33%',
'column-3' => '33.33%',
],
'wpuf_cond' => $this->default_conditional_prop(),
'wpuf_visibility' => $this->get_default_visibility_prop(),
];

return $props;
}
}
Loading

0 comments on commit 180e0e9

Please sign in to comment.