Merge pull request #1218 from ultimatemember/fix/remove_extract_admin

Remove extract() wp-admin
This commit is contained in:
Mykyta Synelnikov
2023-06-22 23:47:01 +03:00
committed by GitHub
8 changed files with 602 additions and 679 deletions
+36 -45
View File
@@ -35,22 +35,20 @@ jQuery(document).ready(function() {
/* Add a Field */
jQuery(document.body).on('submit', 'form.um_add_field', function(e){
e.preventDefault();
var conditions = jQuery('.um-admin-cur-condition');
//need fields refactor
jQuery(conditions).each( function ( i ) {
if ( jQuery( this ).find('[id^="_conditional_action"]').val() === '' ||
jQuery( this ).find('[id^="_conditional_field"]').val() === '' ||
jQuery( this ).find('[id^="_conditional_operator"]').val() ==='' )
{
jQuery(conditions[i]).find('.um-admin-remove-condition').trigger('click');
}
} );
conditions = jQuery('.um-admin-cur-condition');
jQuery(conditions).each( function ( i ) {
var id = i === 0 ? '' : i;
var conditions = jQuery('.um-admin-cur-condition');
//need fields refactor
jQuery(conditions).each( function ( i ) {
if ( jQuery( this ).find('[id^="_conditional_action"]').val() === '' ||
jQuery( this ).find('[id^="_conditional_field"]').val() === '' ||
jQuery( this ).find('[id^="_conditional_operator"]').val() ==='' )
{
jQuery(conditions[i]).find('.um-admin-remove-condition').trigger('click');
}
} );
conditions = jQuery('.um-admin-cur-condition');
jQuery(conditions).each( function ( i ) {
var id = i === 0 ? '' : i;
jQuery( this ).find('[id^="_conditional_action"]').attr('name', '_conditional_action' + id);
jQuery( this ).find('[id^="_conditional_action"]').attr('id', '_conditional_action' + id);
@@ -60,8 +58,7 @@ jQuery(document).ready(function() {
jQuery( this ).find('[id^="_conditional_operator"]').attr('id', '_conditional_operator' + id);
jQuery( this ).find('[id^="_conditional_value"]').attr('name', '_conditional_value' + id);
jQuery( this ).find('[id^="_conditional_value"]').attr('id', '_conditional_value' + id);
} );
} );
var form = jQuery(this);
jQuery.ajax({
@@ -78,40 +75,34 @@ jQuery(document).ready(function() {
complete: function(){
form.css({'opacity': 1});
},
success: function(data){
if (data.error){
c = 0;
jQuery.each(data.error, function(i, v){
c++;
if ( c == 1 ) {
form.find('#'+i).addClass('um-admin-error').trigger('focus');
form.find('.um-admin-error-block').show().html(v);
}
});
um_admin_modal_responsive();
success: function( response ){
if ( response.success ) {
let data = response.data;
if ( data.error ) {
let c = 0;
jQuery.each( data.error, function(i, v){
c++;
if ( 1 === c ) {
form.find('#' + i).addClass('um-admin-error').trigger('focus');
form.find('.um-admin-error-block').show().html(v);
}
});
um_admin_modal_responsive();
} else {
jQuery('.um-col-demon-settings').data('in_row', '').data('in_sub_row', '').data('in_column', '').data('in_group', '');
um_admin_remove_modal();
um_admin_update_builder();
}
} else {
jQuery('.um-col-demon-settings').data('in_row', '');
jQuery('.um-col-demon-settings').data('in_sub_row', '');
jQuery('.um-col-demon-settings').data('in_column', '');
jQuery('.um-col-demon-settings').data('in_group', '');
um_admin_remove_modal();
um_admin_update_builder();
console.log( response );
}
},
error: function(data){
console.log(data);
error: function( response ){
console.log( response );
}
});
return false;
});
});
});
File diff suppressed because it is too large Load Diff
+10 -11
View File
@@ -35,18 +35,19 @@ if ( ! class_exists( 'um\admin\core\Admin_DragDrop' ) ) {
*/
public function update_order() {
UM()->admin()->check_ajax_nonce();
// phpcs:disable WordPress.Security.NonceVerification -- already verified here
if ( ! is_user_logged_in() || ! current_user_can( 'manage_options' ) ) {
wp_send_json_error( __( 'Please login as administrator', 'ultimate-member' ) );
}
/**
* @var $form_id
*/
extract( $_POST );
if ( empty( $_POST['form_id'] ) ) {
wp_send_json_error( __( 'Invalid form ID.', 'ultimate-member' ) );
}
if ( isset( $form_id ) ) {
$form_id = absint( $form_id );
$form_id = absint( $_POST['form_id'] );
if ( empty( $form_id ) ) {
wp_send_json_error( __( 'Invalid form ID.', 'ultimate-member' ) );
}
$fields = UM()->query()->get_attr( 'custom_fields', $form_id );
@@ -71,12 +72,11 @@ if ( ! class_exists( 'um\admin\core\Admin_DragDrop' ) ) {
// adding rows
if ( 0 === strpos( $key, '_um_row_' ) ) {
$update_args = null;
$row_id = str_replace( '_um_row_', '', $key );
if ( strstr( $_POST[ '_um_rowcols_' . $row_id . '_cols' ], ':' ) ) {
if ( false !== strpos( $_POST[ '_um_rowcols_' . $row_id . '_cols' ], ':' ) ) {
$cols = sanitize_text_field( $_POST[ '_um_rowcols_' . $row_id . '_cols' ] );
} else {
$cols = absint( $_POST[ '_um_rowcols_' . $row_id . '_cols' ] );
@@ -105,7 +105,6 @@ if ( ! class_exists( 'um\admin\core\Admin_DragDrop' ) ) {
}
$fields[ $key ] = $row_args;
}
// change field position
@@ -160,16 +159,16 @@ if ( ! class_exists( 'um\admin\core\Admin_DragDrop' ) ) {
update_option( 'um_form_rowdata_' . $form_id, $this->row_data );
UM()->query()->update_attr( 'custom_fields', $form_id, $fields );
// phpcs:enable WordPress.Security.NonceVerification -- already verified here
}
/**
* Load form to maintain form order.
*/
public function load_field_order() {
$screen = get_current_screen();
if ( ! isset( $screen->id ) || 'um_form' !== $screen->id ) {
if ( ! isset( $screen, $screen->id ) || 'um_form' !== $screen->id ) {
return;
} ?>
+9 -7
View File
@@ -61,6 +61,8 @@ if ( ! class_exists( 'um\admin\core\Admin_Metabox' ) ) {
*/
public $is_loaded = false;
public $set_field_type;
/**
* Admin_Metabox constructor.
*/
@@ -1820,7 +1822,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Metabox' ) ) {
?>
<p><label for="_format_custom"><?php _e( 'Use custom Date format', 'ultimate-member' ); ?> <?php UM()->tooltip( __( 'This option overrides "Date User-Friendly Format" option. See https://www.php.net/manual/en/function.date.php', 'ultimate-member' ) ); ?></label>
<input type="text" name="_format_custom" id="_format_custom" value="<?php echo htmlspecialchars( $this->edit_mode_value, ENT_QUOTES ); ?>" placeholder="j M Y" />
<input type="text" name="_format_custom" id="_format_custom" value="<?php echo esc_attr( $this->edit_mode_value ); ?>" placeholder="j M Y" />
</p>
<?php
@@ -2191,7 +2193,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Metabox' ) ) {
?>
<p><label for="_title"><?php _e( 'Title', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This is the title of the field for your reference in the backend. The title will not appear on the front-end of your website.', 'ultimate-member' ) ); ?></label>
<input type="text" name="_title" id="_title" value="<?php echo htmlspecialchars( $this->edit_mode_value, ENT_QUOTES ); ?>" />
<input type="text" name="_title" id="_title" value="<?php echo esc_attr( $this->edit_mode_value ); ?>" />
</p>
<?php
@@ -2202,7 +2204,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Metabox' ) ) {
?>
<p style="display:none"><label for="_id"><?php _e( 'Unique ID', 'ultimate-member' ) ?></label>
<input type="text" name="_id" id="_id" value="<?php echo $this->edit_mode_value; ?>" />
<input type="text" name="_id" id="_id" value="<?php echo esc_attr( $this->edit_mode_value ); ?>" />
</p>
<?php
@@ -2271,7 +2273,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Metabox' ) ) {
<?php } else { ?>
<p><label for="_default"><?php _e( 'Default Value', 'ultimate-member' ); ?> <?php UM()->tooltip( __( 'This option allows you to pre-fill the field with a default value prior to the user entering a value in the field. Leave blank to have no default value', 'ultimate-member' ) ); ?></label>
<input type="text" name="_default" id="_default" value="<?php echo $this->edit_mode_value; ?>" />
<input type="text" name="_default" id="_default" value="<?php echo esc_attr( $this->edit_mode_value ); ?>" />
</p>
<?php } ?>
@@ -2283,7 +2285,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Metabox' ) ) {
?>
<p><label for="_label"><?php _e( 'Label', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'The field label is the text that appears above the field on your front-end form. Leave blank to not show a label above field.', 'ultimate-member' ) ); ?></label>
<input type="text" name="_label" id="_label" value="<?php echo htmlspecialchars( $this->edit_mode_value, ENT_QUOTES ); ?>" />
<input type="text" name="_label" id="_label" value="<?php echo esc_attr( $this->edit_mode_value ); ?>" />
</p>
<?php
@@ -2293,7 +2295,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Metabox' ) ) {
?>
<p><label for="_label_confirm_pass"><?php _e( 'Confirm password field label', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This label is the text that appears above the confirm password field. Leave blank to show default label.', 'ultimate-member' ) ); ?></label>
<input type="text" name="_label_confirm_pass" id="_label_confirm_pass" value="<?php echo htmlspecialchars( $this->edit_mode_value, ENT_QUOTES ); ?>" />
<input type="text" name="_label_confirm_pass" id="_label_confirm_pass" value="<?php echo esc_attr( $this->edit_mode_value ); ?>" />
</p>
<?php
@@ -2303,7 +2305,7 @@ if ( ! class_exists( 'um\admin\core\Admin_Metabox' ) ) {
?>
<p><label for="_placeholder"><?php _e( 'Placeholder', 'ultimate-member' ) ?> <?php UM()->tooltip( __( 'This is the text that appears within the field e.g please enter your email address. Leave blank to not show any placeholder text.', 'ultimate-member' ) ); ?></label>
<input type="text" name="_placeholder" id="_placeholder" value="<?php echo htmlspecialchars( $this->edit_mode_value, ENT_QUOTES ); ?>" />
<input type="text" name="_placeholder" id="_placeholder" value="<?php echo esc_attr( $this->edit_mode_value ); ?>" />
</p>
<?php
+1 -1
View File
@@ -47,7 +47,7 @@ if ( ! class_exists( 'UM' ) ) {
/**
* @var UM the single instance of the class
*/
protected static $instance = null;
protected static $instance;
/**
+38 -47
View File
@@ -210,26 +210,22 @@ if ( ! class_exists( 'um\core\Builtin' ) ) {
return 0;
}
/**
* Get a core field attrs
* Get a core field attrs.
*
* @param $type
* @param string $type Field type.
*
* @return array|mixed
* @return array Field data.
*/
function get_core_field_attrs( $type ) {
return ( isset( $this->core_fields[ $type ] ) ) ? $this->core_fields[ $type ] : array('');
public function get_core_field_attrs( $type ) {
return array_key_exists( $type, $this->core_fields ) ? $this->core_fields[ $type ] : array( '' );
}
/**
* Core Fields
*/
function set_core_fields() {
public function set_core_fields() {
$this->core_fields = array(
'row' => array(
'name' => 'Row',
'in_fields' => false,
@@ -651,21 +647,21 @@ if ( ! class_exists( 'um\core\Builtin' ) ) {
),
/*'group' => array(
'name' => 'Field Group',
'col1' => array('_title','_max_entries'),
'col2' => array('_label','_public','_roles'),
'form_only' => true,
'validate' => array(
'_title' => array(
'mode' => 'required',
'error' => 'You must provide a title'
),
'_label' => array(
'mode' => 'required',
'error' => 'You must provide a label'
),
)
),*/
'name' => 'Field Group',
'col1' => array('_title','_max_entries'),
'col2' => array('_label','_public','_roles'),
'form_only' => true,
'validate' => array(
'_title' => array(
'mode' => 'required',
'error' => 'You must provide a title'
),
'_label' => array(
'mode' => 'required',
'error' => 'You must provide a label'
),
)
),*/
);
@@ -1379,48 +1375,43 @@ if ( ! class_exists( 'um\core\Builtin' ) ) {
}
}
/**
* Get all fields without metakeys
* Get all fields without metakeys.
*
* @since 2.0.56
*
* @return array
*/
function get_fields_without_metakey() {
public function get_fields_without_metakey() {
$fields_without_metakey = array(
'block',
'shortcode',
'spacing',
'divider',
'group'
'group',
);
/**
* UM hook
* Filters the field types without meta key.
*
* @type filter
* @title um_fields_without_metakey
* @description Field Types without meta key
* @input_vars
* [{"var":"$types","type":"array","desc":"Field Types"}]
* @change_log
* ["Since: 2.0"]
* @usage add_filter( 'um_fields_without_metakey', 'function_name', 10, 1 );
* @example
* <?php
* add_filter( 'um_fields_without_metakey', 'my_fields_without_metakey', 10, 1 );
* function my_fields_without_metakey( $types ) {
* // your code here
* return $types;
* @param {array} $field_types Field types.
*
* @return {array} Field types.
*
* @since 1.3.x
* @hook um_fields_without_metakey
*
* @example <caption>It adds 'location' and 'distance' field-types to fields without metakeys array.</caption>
* function my_custom_um_fields_without_metakey( $field_types ) {
* $field_types[] = 'location';
* $field_types[] = 'distance';
* return $field_types;
* }
* ?>
* add_filter( 'um_fields_without_metakey', 'my_custom_um_fields_without_metakey' );
*/
return apply_filters( 'um_fields_without_metakey', $fields_without_metakey );
}
/**
* May be used to show a dropdown, or source for user meta
*
+11 -9
View File
@@ -1,34 +1,36 @@
<?php
namespace um\core;
// Exit if accessed directly
if ( ! defined( 'ABSPATH' ) ) exit;
if ( ! defined( 'ABSPATH' ) ) {
exit;
}
if ( ! class_exists( 'um\core\Password' ) ) {
/**
* Class Password
* @package um\core
*/
class Password {
/**
* @var bool
*/
private $change_password = false;
/**
* Password constructor.
*/
function __construct() {
public function __construct() {
add_shortcode( 'ultimatemember_password', array( &$this, 'ultimatemember_password' ) );
add_action( 'template_redirect', array( &$this, 'form_init' ), 10001 );
add_action( 'um_reset_password_errors_hook', array( &$this, 'um_reset_password_errors_hook' ) );
add_action( 'um_reset_password_process_hook', array( &$this,'um_reset_password_process_hook' ) );
add_action( 'um_reset_password_process_hook', array( &$this, 'um_reset_password_process_hook' ) );
add_action( 'um_change_password_errors_hook', array( &$this, 'um_change_password_errors_hook' ) );
add_action( 'um_change_password_process_hook', array( &$this,'um_change_password_process_hook' ) );
add_action( 'um_change_password_process_hook', array( &$this, 'um_change_password_process_hook' ) );
}
@@ -156,7 +158,7 @@ if ( ! class_exists( 'um\core\Password' ) ) {
*/
$args = apply_filters( 'um_reset_password_shortcode_args_filter', $args );
if ( isset( $this->change_password ) ) {
if ( false !== $this->change_password ) {
// then COOKIE are valid then get data from them and populate hidden fields for the password reset form
$args['template'] = 'password-change';
$args['rp_key'] = '';
+8 -11
View File
@@ -95,9 +95,9 @@ if ( ! class_exists( 'um\core\Query' ) ) {
}
$pages = $wpdb->get_results(
"SELECT *
FROM {$wpdb->posts}
WHERE post_type = 'page' AND
"SELECT *
FROM {$wpdb->posts}
WHERE post_type = 'page' AND
post_status = 'publish'",
OBJECT
);
@@ -363,21 +363,18 @@ if ( ! class_exists( 'um\core\Query' ) ) {
update_post_meta( $post_id, '_um_' . $key, $new_value );
}
/**
* Get data
* Get postmeta related to Ultimate Member.
*
* @param $key
* @param $post_id
* @param string $key
* @param int $post_id
*
* @return mixed
*/
function get_attr( $key, $post_id ) {
$meta = get_post_meta( $post_id, '_um_' . $key, true );
return $meta;
public function get_attr( $key, $post_id ) {
return get_post_meta( $post_id, '_um_' . $key, true );
}
/**
* Delete data
*