diff --git a/includes/core/class-fields.php b/includes/core/class-fields.php index 667f6be6..d1e8825e 100644 --- a/includes/core/class-fields.php +++ b/includes/core/class-fields.php @@ -1381,8 +1381,9 @@ if ( ! class_exists( 'um\core\Fields' ) ) { if ( $has_custom_source ) { - $opts = apply_filters( "um_get_field__{$data['metakey']}", array() ); - $arr_options = $opts['options']; + /** This filter is documented in includes/core/class-fields.php */ + $opts = apply_filters( "um_get_field__{$data['metakey']}", array() ); + $arr_options = array_key_exists( 'options', $opts ) ? $opts['options'] : array(); } elseif ( function_exists( $data['custom_dropdown_options_source'] ) ) { if ( isset( $data['parent_dropdown_relationship'] ) ) { @@ -1627,7 +1628,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) { $fields_without_metakey = UM()->builtin()->get_fields_without_metakey(); - if ( ! in_array( $array['type'], $fields_without_metakey ) ) { + if ( ! in_array( $array['type'], $fields_without_metakey, true ) ) { $array['classes'] .= ' um-field-' . esc_attr( $key ); } $array['classes'] .= ' um-field-' . esc_attr( $array['type'] ); @@ -1647,9 +1648,8 @@ if ( ! class_exists( 'um\core\Fields' ) ) { case 'text': $array['disabled'] = ''; - - if ( $key == 'user_login' && isset( $this->set_mode ) && $this->set_mode == 'account' ) { - $array['disabled'] = 'disabled="disabled"'; + if ( 'user_login' === $key && 'account' === $this->set_mode ) { + $array['disabled'] = ' disabled="disabled" '; } $array['input'] = 'text'; @@ -1759,37 +1759,10 @@ if ( ! class_exists( 'um\core\Fields' ) ) { $array['date_min'] = $past; $array['date_max'] = $future; - } - } - - /** - * UM hook - * - * @type filter - * @title um_get_field_date - * @description Extend field date - * @input_vars - * [{"var":"$data","type":"array","desc":"Field Date Data"}] - * @change_log - * ["Since: 2.5.4"] - * @usage add_filter( 'um_get_field_date', 'function_name', 10, 1 ); - * @example - * - */ - $array = apply_filters( 'um_get_field_date', $array ); - break; - case 'time': - $array['input'] = 'text'; if ( ! isset( $array['format'] ) ) { @@ -2019,31 +1992,45 @@ if ( ! class_exists( 'um\core\Fields' ) ) { } /** - * UM hook + * Filters the field data by the field type. Where $type is the field's type. * - * @type filter - * @title um_get_field__{$key} - * @description Extend field data by field $key - * @input_vars - * [{"var":"$data","type":"array","desc":"Field Data"}] - * @change_log - * ["Since: 2.0"] - * @usage add_filter( 'um_get_field__{$key}', 'function_name', 10, 1 ); - * @example - * Disable all date-type fields. + * function my_custom_get_field_date( $field_data ) { + * $field_data['disabled'] = ' disabled="disabled" '; + * return $field_data; * } - * ?> + * add_filter( 'um_get_field_date', 'my_custom_get_field_date' ); */ - $array = apply_filters( "um_get_field__{$key}", $array ); - - return $array; + $array = apply_filters( "um_get_field_{$array['type']}", $array ); + /** + * Filters the field data by the metakey. Where $key is the field's metakey. + * + * @param {array} $field_data Field data. + * + * @return {array} Field data. + * + * @since 1.3.x + * @hook um_get_field__{$key} + * + * @example Disable 'first_name' field. + * function my_custom_disable_first_name( $field_data ) { + * $field_data['disabled'] = ' disabled="disabled" '; + * return $field_data; + * } + * add_filter( 'um_get_field__first_name', 'my_custom_disable_first_name' ); + */ + return apply_filters( "um_get_field__{$key}", $array ); } - /** * @param $option_value * @@ -2109,8 +2096,8 @@ if ( ! class_exists( 'um\core\Fields' ) ) { $form_suffix = UM()->form()->form_suffix; } - $output = ''; - $disabled = ''; + $output = ''; + if ( empty( $_um_profile_id ) ) { $_um_profile_id = um_user( 'ID' ); } @@ -2133,6 +2120,11 @@ if ( ! class_exists( 'um\core\Fields' ) ) { } $type = $data['type']; + $disabled = ''; + if ( isset( $data['disabled'] ) ) { + $disabled = $data['disabled']; + } + if ( isset( $data['in_group'] ) && '' !== $data['in_group'] && 'group' !== $rule ) { return ''; } diff --git a/includes/core/class-validation.php b/includes/core/class-validation.php index b835b009..dbdbd564 100644 --- a/includes/core/class-validation.php +++ b/includes/core/class-validation.php @@ -90,13 +90,16 @@ if ( ! class_exists( 'um\core\Validation' ) ) { // Dynamic dropdown options population $has_custom_source = apply_filters("um_has_dropdown_options_source__{$key}", false ); - if ( in_array( $fields[ $key ]['type'], array( 'select','multiselect' ) ) && $has_custom_source ){ - $arr_options = apply_filters("um_get_field__{$key}", $fields[ $key ]['options'] ); - $fields[ $key ]['options'] = array_keys( $arr_options['options'] ); + if ( in_array( $fields[ $key ]['type'], array( 'select','multiselect' ), true ) && $has_custom_source ) { + /** This filter is documented in includes/core/class-fields.php */ + $fields[ $key ] = apply_filters( "um_get_field__{$key}", $fields[ $key ] ); + if ( is_array( $fields[ $key ] ) && array_key_exists( 'options', $fields[ $key ] ) ) { + $fields[ $key ]['options'] = array_keys( $fields[ $key ]['options'] ); + } } // Dropdown options source from callback function - if ( in_array( $fields[ $key ]['type'], array( 'select','multiselect' ) ) && + if ( in_array( $fields[ $key ]['type'], array( 'select','multiselect' ), true ) && isset( $fields[ $key ]['custom_dropdown_options_source'] ) && ! empty( $fields[ $key ]['custom_dropdown_options_source'] ) && function_exists( $fields[ $key ]['custom_dropdown_options_source'] ) ) { diff --git a/includes/core/um-filters-account.php b/includes/core/um-filters-account.php index d7c6613b..ebd103f5 100644 --- a/includes/core/um-filters-account.php +++ b/includes/core/um-filters-account.php @@ -1,29 +1,30 @@ -options()->get( 'account_name_disable' ) ) { return $fields; } if ( um_is_core_page( 'account' ) ) { - $fields['disabled'] = 'disabled="disabled"'; + $fields['disabled'] = ' disabled="disabled" '; } return $fields; } -add_filter( 'um_get_field__first_name', 'um_account_disable_name_fields', 10 ,1 ); -add_filter( 'um_get_field__last_name', 'um_account_disable_name_fields', 10 ,1 ); - +add_filter( 'um_get_field__first_name', 'um_account_disable_name_fields' ); +add_filter( 'um_get_field__last_name', 'um_account_disable_name_fields' ); /** - * Sanitize inputs on Account update + * Sanitize inputs on Account update. * * @param $data * @@ -32,12 +33,15 @@ add_filter( 'um_get_field__last_name', 'um_account_disable_name_fields', 10 ,1 ) function um_account_sanitize_data( $data ) { foreach ( $data as $key => $value ) { if ( is_array( $value ) ) { - $data[ $key ] = array_filter( $value, function( $var ) { - $var = trim( esc_html( strip_tags( $var ) ) ); - return $var; - }); + $data[ $key ] = array_filter( + $value, + function( $var ) { + $var = trim( esc_html( wp_strip_all_tags( $var ) ) ); + return $var; + } + ); } else { - $data[ $key ] = trim( esc_html( strip_tags( $value ) ) ); + $data[ $key ] = trim( esc_html( wp_strip_all_tags( $value ) ) ); } } @@ -45,11 +49,11 @@ function um_account_sanitize_data( $data ) { } add_filter( 'um_account_pre_updating_profile_array', 'um_account_sanitize_data', 10, 1 ); - /** - * Fix for the account field "Avoid indexing my profile by search engines" + * Fix for the account field "Avoid indexing my profile by search engines". + * * @since 2.1.16 - * @param bool $value + * @param mixed|int $value * @return int */ function um_account_profile_noindex_value( $value ) { @@ -58,4 +62,4 @@ function um_account_profile_noindex_value( $value ) { } return $value; } -add_filter( 'um_profile_profile_noindex_empty__filter', 'um_account_profile_noindex_value' ); \ No newline at end of file +add_filter( 'um_profile_profile_noindex_empty__filter', 'um_account_profile_noindex_value' );