mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-11 18:56:10 +09:00
Merge pull request #1302 from ultimatemember/fix/ID_reserved_key
Fields key blacklist
This commit is contained in:
@@ -49,6 +49,12 @@ if ( ! class_exists( 'um\admin\core\Admin_Builder' ) ) {
|
||||
return $errors;
|
||||
}
|
||||
|
||||
$blacklist_error = UM()->builtin()->blacklist_field_err( $submission_data['post']['_metakey'] );
|
||||
if ( ! empty( $blacklist_error ) ) {
|
||||
$errors['_metakey'] = $blacklist_error;
|
||||
return $errors;
|
||||
}
|
||||
|
||||
$field_attr = UM()->builtin()->get_core_field_attrs( $submission_data['field_type'] );
|
||||
if ( ! array_key_exists( 'validate', $field_attr ) ) {
|
||||
return $errors;
|
||||
|
||||
@@ -33,6 +33,11 @@ if ( ! class_exists( 'um\core\Builtin' ) ) {
|
||||
*/
|
||||
public $saved_fields = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
public $blacklist_fields = array();
|
||||
|
||||
/**
|
||||
* @var array
|
||||
*/
|
||||
@@ -50,6 +55,7 @@ if ( ! class_exists( 'um\core\Builtin' ) ) {
|
||||
add_action( 'init', array( &$this, 'set_core_fields' ), 1 );
|
||||
add_action( 'init', array( &$this, 'set_predefined_fields' ), 1 );
|
||||
add_action( 'init', array( &$this, 'set_custom_fields' ), 1 );
|
||||
add_action( 'init', array( &$this, 'set_blacklist_fields' ), 1 );
|
||||
$this->saved_fields = get_option( 'um_fields', array() );
|
||||
}
|
||||
|
||||
@@ -149,7 +155,7 @@ if ( ! class_exists( 'um\core\Builtin' ) ) {
|
||||
*
|
||||
* @return int|string
|
||||
*/
|
||||
function unique_field_err( $key ) {
|
||||
public function unique_field_err( $key ) {
|
||||
if ( empty( $key ) ) {
|
||||
return __( 'Please provide a meta key', 'ultimate-member' );
|
||||
}
|
||||
@@ -170,6 +176,22 @@ if ( ! class_exists( 'um\core\Builtin' ) ) {
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Checks for a blacklist field error
|
||||
*
|
||||
* @param $key
|
||||
*
|
||||
* @return int|string
|
||||
*/
|
||||
public function blacklist_field_err( $key ) {
|
||||
if ( in_array( strtolower( $key ), UM()->builtin()->blacklist_fields, true ) ) {
|
||||
return __( 'Your meta key can not be used', 'ultimate-member' );
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check date range errors (start date)
|
||||
*
|
||||
@@ -1355,6 +1377,32 @@ if ( ! class_exists( 'um\core\Builtin' ) ) {
|
||||
}
|
||||
|
||||
|
||||
public function set_blacklist_fields() {
|
||||
$this->blacklist_fields = array(
|
||||
'id',
|
||||
);
|
||||
|
||||
/**
|
||||
* Filters change metakeys in the blacklist.
|
||||
*
|
||||
* @since 2.6.12
|
||||
* @hook um_blacklist_fields_hook
|
||||
*
|
||||
* @param {array} $blacklist_fields array of metakeys in the blacklist.
|
||||
*
|
||||
* @return {array} Array of metakeys in the blacklis.
|
||||
*
|
||||
* @example <caption>Change array of metakeys in the blacklist.</caption>
|
||||
* function my_um_blacklist_fields_hook( $blacklist_fields ) {
|
||||
* // your code here
|
||||
* return $blacklist_fields;
|
||||
* }
|
||||
* add_filter( 'um_blacklist_fields_hook', 'my_um_blacklist_fields_hook' );
|
||||
*/
|
||||
$this->blacklist_fields = apply_filters( 'um_blacklist_fields_hook', $this->blacklist_fields );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Custom Fields
|
||||
*/
|
||||
|
||||
Reference in New Issue
Block a user