- fixed save empty value to the selectbox;

This commit is contained in:
nikitasinelnikov
2019-05-13 17:19:12 +03:00
parent efbfb97567
commit 0408067a6b
3 changed files with 22 additions and 18 deletions
+14 -12
View File
@@ -687,6 +687,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
* ?>
*/
$value = apply_filters( "um_edit_{$key}_field_value", $value, $key );
$value = maybe_unserialize( $value );
} elseif ( $default ) {
@@ -786,6 +787,8 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
*/
$value = apply_filters( "um_edit_{$key}_field_value", $default, $key );
} elseif ( isset( $value ) && is_array( $value ) && ! count( $value ) ) {
$value = '';
} elseif ( ! isset( $value ) ) {
$value = '';
}
@@ -2446,18 +2449,18 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
$output .= '<div class="um-field' . $classes . '"' . $conditional . ' data-key="' . $key . '">';
if (isset( $data['allowclear'] ) && $data['allowclear'] == 0) {
if ( isset( $data['allowclear'] ) && $data['allowclear'] == 0 ) {
$class = 'um-s2';
} else {
$class = 'um-s1';
}
if (isset( $data['label'] )) {
if ( isset( $data['label'] ) ) {
$output .= $this->field_label( $label, $key, $data );
}
$output .= '<div class="um-field-area ' . ( isset( $this->field_icons ) && $this->field_icons == 'field' ? 'um-field-area-has-icon' : '' ) . ' ">';
if (isset( $icon ) && $icon && isset( $this->field_icons ) && $this->field_icons == 'field') {
if ( isset( $icon ) && $icon && isset( $this->field_icons ) && $this->field_icons == 'field' ) {
$output .= '<div class="um-field-icon"><i class="' . $icon . '"></i></div>';
}
@@ -2466,7 +2469,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
$atts_ajax = '';
$select_original_option_value = '';
if (isset( $data['parent_dropdown_relationship'] ) && !empty( $data['parent_dropdown_relationship'] ) && !UM()->user()->preview) {
if ( ! empty( $data['parent_dropdown_relationship'] ) && ! UM()->user()->preview ) {
$disabled_by_parent_option = 'disabled = disabled';
@@ -2496,20 +2499,19 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
$parent_dropdown_relationship = apply_filters( "um_custom_dropdown_options_parent__{$form_key}", $data['parent_dropdown_relationship'], $data );
$atts_ajax .= " data-um-parent='{$parent_dropdown_relationship}' ";
if (isset( $data['custom_dropdown_options_source'] ) && !empty( $data['custom_dropdown_options_source'] ) &&
$has_parent_option && function_exists( $data['custom_dropdown_options_source'] ) &&
if ( ! empty( $data['custom_dropdown_options_source'] ) && $has_parent_option && function_exists( $data['custom_dropdown_options_source'] ) &&
um_user( $data['parent_dropdown_relationship'] )
) {
$options = call_user_func( $data['custom_dropdown_options_source'], $data['parent_dropdown_relationship'] );
$disabled_by_parent_option = '';
if (um_user( $form_key )) {
if ( um_user( $form_key ) ) {
$select_original_option_value = " data-um-original-value='" . um_user( $form_key ) . "' ";
}
}
}
if (!empty( $data['custom_dropdown_options_source'] )) {
if ( ! empty( $data['custom_dropdown_options_source'] ) ) {
/**
* UM hook
@@ -2589,12 +2591,12 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
*/
$enable_options_pair = apply_filters( "um_fields_options_enable_pairs__{$key}", false );
if( ! $has_parent_option ) {
if ( isset($options) && $options == 'builtin'){
if ( ! $has_parent_option ) {
if ( isset( $options ) && $options == 'builtin' ) {
$options = UM()->builtin()->get ( $filter );
}
if ( ! isset( $options )) {
if ( ! isset( $options ) ) {
$options = UM()->builtin()->get( 'countries' );
}
@@ -2684,7 +2686,7 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
$um_field_checkbox_item_title = $v;
}
if (isset( $options_pair )) {
if ( isset( $options_pair ) ) {
$option_value = $k;
$um_field_checkbox_item_title = $v;
}
+4 -3
View File
@@ -73,16 +73,17 @@ if ( ! class_exists( 'um\core\Validation' ) ) {
}
//validation of correct values from options in wp-admin
$stripslashes = stripslashes( $value );
if ( in_array( $fields[ $key ]['type'], array( 'select' ) ) &&
isset( $value ) && ! empty( $fields[ $key ]['options'] ) &&
! in_array( stripslashes( $value ), array_map( 'trim', $fields[ $key ]['options'] ) ) ) {
! empty( $stripslashes ) && ! empty( $fields[ $key ]['options'] ) &&
! in_array( $stripslashes, array_map( 'trim', $fields[ $key ]['options'] ) ) ) {
unset( $changes[ $key ] );
}
//validation of correct values from options in wp-admin
//the user cannot set invalid value in the hidden input at the page
if ( in_array( $fields[ $key ]['type'], array( 'multiselect', 'checkbox', 'radio' ) ) &&
isset( $value ) && ! empty( $fields[ $key ]['options'] ) ) {
! empty( $value ) && ! empty( $fields[ $key ]['options'] ) ) {
$value = array_map( 'stripslashes', array_map( 'trim', $value ) );
$changes[ $key ] = array_intersect( $value, array_map( 'trim', $fields[ $key ]['options'] ) );
}
+4 -3
View File
@@ -247,16 +247,17 @@ function um_user_edit_profile( $args ) {
}
//validation of correct values from options in wp-admin
$stripslashes = stripslashes( $args['submitted'][ $key ] );
if ( in_array( $array['type'], array( 'select' ) ) &&
isset( $args['submitted'][ $key ] ) && ! empty( $array['options'] ) &&
! in_array( stripslashes( $args['submitted'][ $key ] ), array_map( 'trim', $array['options'] ) ) ) {
! empty( $array['options'] ) && ! empty( $stripslashes ) &&
! in_array( $stripslashes, array_map( 'trim', $array['options'] ) ) ) {
continue;
}
//validation of correct values from options in wp-admin
//the user cannot set invalid value in the hidden input at the page
if ( in_array( $array['type'], array( 'multiselect', 'checkbox', 'radio' ) ) &&
isset( $args['submitted'][ $key ] ) && ! empty( $array['options'] ) ) {
! empty( $args['submitted'][ $key ] ) && ! empty( $array['options'] ) ) {
$args['submitted'][ $key ] = array_map( 'stripslashes', array_map( 'trim', $args['submitted'][ $key ] ) );
$args['submitted'][ $key ] = array_intersect( $args['submitted'][ $key ], array_map( 'trim', $array['options'] ) );
}