mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-11 18:56:10 +09:00
- fixed conditional logic for profile form fields on submit;
- small notices fixes;
This commit is contained in:
@@ -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 = '<div class="um-field-error"><span class="um-field-arrow"><i class="um-faicon-caret-up"></i></span>'.$text.'</div>';
|
||||
return $output;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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'] ) );
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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 );
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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 );
|
||||
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user