diff --git a/includes/core/class-fields.php b/includes/core/class-fields.php index a9487089..2360a29b 100644 --- a/includes/core/class-fields.php +++ b/includes/core/class-fields.php @@ -275,11 +275,13 @@ if ( ! class_exists( 'Fields' ) ) { } /** - * Print field error - * @param string $text - * @param boolean $force_show + * Print field error + * + * @param string $text + * @param bool $force_show + * @return string */ - function field_error($text, $force_show = false ) { + function field_error( $text, $force_show = false ) { if ( $force_show ) { $output = '
'.$text.'
'; return $output; diff --git a/includes/core/class-form.php b/includes/core/class-form.php index a7882eef..d75a8052 100644 --- a/includes/core/class-form.php +++ b/includes/core/class-form.php @@ -121,7 +121,7 @@ if ( ! class_exists( 'Form' ) ) { * @return boolean */ function has_error( $key ) { - if ( isset($this->errors[$key]) ) + if ( isset( $this->errors[$key] ) ) return true; return false; } diff --git a/includes/core/um-actions-form.php b/includes/core/um-actions-form.php index 20f72a13..0e885167 100644 --- a/includes/core/um-actions-form.php +++ b/includes/core/um-actions-form.php @@ -139,35 +139,81 @@ foreach ( $fields as $key => $array ) { if ( isset( $array['public'] ) && -2 == $array['public'] && ! empty( $array['roles'] ) && is_user_logged_in() ) { - - if( ! in_array( um_user( 'role' ) , $array['roles'] ) ){ + if ( ! in_array( um_user( 'role' ), $array['roles'] ) ) { continue; } } - $array = apply_filters('um_get_custom_field_array', $array, $fields ); - - if( isset( $array ['conditions'] ) && ! empty( $array ['conditions'] ) ){ - - foreach( $array ['conditions'] as $condition ){ - - $visibility = $condition[0]; - $parent_key = $condition[1]; - $op = $condition[2]; - $parent_value = $condition[3]; - - if( $visibility == 'hide' ){ - if( $op == 'equals to' ){ + $array = apply_filters( 'um_get_custom_field_array', $array, $fields ); - if( $args[ $parent_key ] == $parent_value ){ - continue 2; - } - - } + if ( ! empty( $array['conditions'] ) ) { + foreach ( $array['conditions'] as $condition ) { + list( $visibility, $parent_key, $op, $parent_value ) = $condition; + + $cond_value = ( $fields[ $parent_key ]['type'] == 'radio' ) ? $args[ $parent_key ][0] : $args[ $parent_key ]; + + if ( $visibility == 'hide' ) { + if ( $op == 'empty' ) { + if ( empty( $cond_value ) ) { + continue 2; + } + } elseif ( $op == 'not empty' ) { + if ( ! empty( $cond_value ) ) { + continue 2; + } + } elseif ( $op == 'equals to' ) { + if ( $cond_value == $parent_value ) { + continue 2; + } + } elseif ( $op == 'not equals' ) { + if ( $cond_value != $parent_value ) { + continue 2; + } + } elseif ( $op == 'greater than' ) { + if ( $cond_value > $op ) { + continue 2; + } + } elseif ( $op == 'less than' ) { + if ( $cond_value < $op ) { + continue 2; + } + } elseif ( $op == 'contains' ) { + if ( strstr( $cond_value, $parent_value ) ) { + continue 2; + } + } + } elseif ( $visibility == 'show' ) { + if ( $op == 'empty' ) { + if ( ! empty( $cond_value ) ) { + continue 2; + } + } elseif ( $op == 'not empty' ) { + if ( empty( $cond_value ) ) { + continue 2; + } + } elseif ( $op == 'equals to' ) { + if ( $cond_value != $parent_value ) { + continue 2; + } + } elseif ( $op == 'not equals' ) { + if ( $cond_value == $parent_value ) { + continue 2; + } + } elseif ( $op == 'greater than' ) { + if ( $cond_value <= $op ) { + continue 2; + } + } elseif ( $op == 'less than' ) { + if ( $cond_value >= $op ) { + continue 2; + } + } elseif ( $op == 'contains' ) { + if ( ! strstr( $cond_value, $parent_value ) ) { + continue 2; + } + } } - } - } if ( isset( $array['type'] ) && $array['type'] == 'checkbox' && isset( $array['required'] ) && $array['required'] == 1 && !isset( $args[$key] ) ) { @@ -195,7 +241,7 @@ if ( isset( $args[$key] ) ) { if ( isset( $array['required'] ) && $array['required'] == 1 ) { - if ( !isset($args[$key]) || $args[$key] == '' ) { + if ( ! isset( $args[$key] ) || $args[$key] == '' ) { UM()->form()->add_error($key, sprintf( __('%s is required','ultimate-member'), $array['label'] ) ); } } diff --git a/includes/core/um-actions-password.php b/includes/core/um-actions-password.php index 06fc9563..d5c3cef8 100644 --- a/includes/core/um-actions-password.php +++ b/includes/core/um-actions-password.php @@ -60,7 +60,7 @@ * Overrides password changed notification * */ - add_action('send_password_change_email','um_send_password_change_email'); + add_action( 'send_password_change_email','um_send_password_change_email', 10, 1 ); function um_send_password_change_email( $args ) { extract( $args ); diff --git a/includes/core/um-actions-profile.php b/includes/core/um-actions-profile.php index cf4e37d3..ca0b15f6 100644 --- a/includes/core/um-actions-profile.php +++ b/includes/core/um-actions-profile.php @@ -558,7 +558,6 @@ ***/ add_action( 'um_submit_form_profile', 'um_submit_form_profile', 10 ); function um_submit_form_profile( $args ) { - if ( isset( UM()->form()->errors ) ) return false; diff --git a/includes/core/um-filters-fields.php b/includes/core/um-filters-fields.php index 8faccf9c..27283763 100644 --- a/includes/core/um-filters-fields.php +++ b/includes/core/um-filters-fields.php @@ -277,45 +277,39 @@ } - /*** - *** @validate conditional logic - ***/ - add_filter('um_get_custom_field_array', 'um_get_custom_field_array',99,2); - function um_get_custom_field_array( $array, $fields ){ + /** + * Validate conditional logic + * + * @param $array + * @param $fields + * @return mixed + */ + function um_get_custom_field_array( $array, $fields ) { - if( isset( $array['conditions'] ) ){ - $found = 0; - for( $a = 0; $a < count( $array['conditions'] ); $a++ ){ - if( isset( $array['conditional_value'] ) || isset( $array['conditional_value'.$a] ) ){ + if ( isset( $array['conditions'] ) ) { + for ( $a = 0; $a < count( $array['conditions'] ); $a++ ) { + if ( isset( $array['conditional_value'] ) || isset( $array['conditional_value' . $a] ) ) { + foreach ( $array['conditions'] as $key => $value ) { + $condition_metakey = $fields[ $value[1] ]['metakey']; - if( isset( $array['conditions'] ) && ! empty( $array['conditions'] ) ){ + if ( isset( $_POST[ $condition_metakey ] ) ) { + $cond_value = ( $fields[ $value[1] ]['type'] == 'radio' ) ? $_POST[ $condition_metakey ][0] : $_POST[ $condition_metakey ]; - $arr_conditions = array(); - - foreach ($array['conditions'] as $key => $value) { - $metakey = $fields[ $value[1] ]['metakey'] ; - $arr_conditions[ $metakey ] = isset( $_POST[ $metakey ] )? $_POST[ $metakey ]: ''; - } - - foreach ($array['conditions'] as $key => $value) { - $metakey = $fields[ $value[1] ]['metakey'] ; - $arr_conditions[ $metakey ] = isset( $_POST[ $metakey ] )? $_POST[ $metakey ]: ''; - if( isset( $_POST[ $metakey ] ) && isset( $array['conditional_value'] ) && $_POST[ $metakey ] !== $array['conditional_value'] ){ - $array['required'] = 0; - } - if( isset( $_POST[ $metakey ] ) && isset( $array['conditional_value'.$a] ) && $_POST[ $metakey ] !== $array['conditional_value'.$a] ){ - $array['required'] = 0; - } - } - - } - } - } + if ( isset( $array['conditional_value'] ) && $cond_value !== $array['conditional_value'] ) { + $array['required'] = 0; + } elseif ( isset( $array['conditional_value'.$a] ) && $cond_value !== $array['conditional_value'.$a] ) { + $array['required'] = 0; + } + } + } + } + } } - return $array; + return $array; } + add_filter( 'um_get_custom_field_array', 'um_get_custom_field_array', 99, 2 ); /**