mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-11 18:56:10 +09:00
Merge remote-tracking branch 'remotes/origin/fix/custom_callback_function_for_multi-select_select_type_field'
This commit is contained in:
@@ -1070,45 +1070,53 @@ if ( ! class_exists( 'um\core\Fields' ) ) {
|
||||
*/
|
||||
function get_option_value_from_callback( $value, $data, $type ) {
|
||||
|
||||
|
||||
if ( in_array( $type, array( 'select', 'multiselect' ) ) && ! empty( $data['custom_dropdown_options_source'] ) ) {
|
||||
|
||||
if ( function_exists( $data['custom_dropdown_options_source'] ) ) {
|
||||
$has_custom_source = apply_filters("um_has_dropdown_options_source__{$data['metakey']}", false );
|
||||
|
||||
if( $has_custom_source ){
|
||||
|
||||
$opts = apply_filters("um_get_field__{$data['metakey']}", array() );
|
||||
$arr_options = $opts['options'];
|
||||
|
||||
}else if ( function_exists( $data['custom_dropdown_options_source'] ) ) {
|
||||
|
||||
$arr_options = call_user_func(
|
||||
$data['custom_dropdown_options_source'],
|
||||
( ! empty( $data['parent_dropdown_relationship'] ) ? $data['parent_dropdown_relationship'] : '' )
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
if( $has_custom_source || function_exists( $data['custom_dropdown_options_source'] ) ){
|
||||
if ( $type == 'select' ) {
|
||||
if ( ! empty( $arr_options[ $value ] ) ) {
|
||||
return $arr_options[ $value ];
|
||||
} elseif ( ! empty( $data['default'] ) && empty( $arr_options[ $value ] ) ) {
|
||||
return $arr_options[ $data['default'] ];
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
if ( $type == 'multiselect' ) {
|
||||
|
||||
if ( is_array( $value ) ) {
|
||||
$values = $value;
|
||||
} else {
|
||||
$values = explode( ', ', $value );
|
||||
}
|
||||
|
||||
$arr_paired_options = array();
|
||||
|
||||
foreach ( $values as $option ) {
|
||||
if ( isset( $arr_options[ $option ] ) ) {
|
||||
$arr_paired_options[] = $arr_options[ $option ];
|
||||
if ( ! empty( $arr_options[ $value ] ) ) {
|
||||
return $arr_options[ $value ];
|
||||
} elseif ( ! empty( $data['default'] ) && empty( $arr_options[ $value ] ) ) {
|
||||
return $arr_options[ $data['default'] ];
|
||||
} else {
|
||||
return '';
|
||||
}
|
||||
}
|
||||
|
||||
return implode( ', ', $arr_paired_options );
|
||||
}
|
||||
if ( $type == 'multiselect' ) {
|
||||
|
||||
if ( is_array( $value ) ) {
|
||||
$values = $value;
|
||||
} else {
|
||||
$values = explode( ', ', $value );
|
||||
}
|
||||
|
||||
$arr_paired_options = array();
|
||||
|
||||
foreach ( $values as $option ) {
|
||||
if ( isset( $arr_options[ $option ] ) ) {
|
||||
$arr_paired_options[] = $arr_options[ $option ];
|
||||
}
|
||||
}
|
||||
|
||||
return implode( ', ', $arr_paired_options );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -215,8 +215,8 @@ function um_user_edit_profile( $args ) {
|
||||
*/
|
||||
do_action( 'um_user_before_updating_profile', $userinfo );
|
||||
|
||||
if ( ! empty( $args['custom_fields'] ) ) {
|
||||
$fields = unserialize( $args['custom_fields'] );
|
||||
if ( !empty( $args[ 'custom_fields' ] ) ) {
|
||||
$fields = apply_filters( 'um_user_edit_profile_fields', unserialize( $args[ 'custom_fields' ] ), $args );
|
||||
}
|
||||
|
||||
// loop through fields
|
||||
@@ -246,6 +246,27 @@ function um_user_edit_profile( $args ) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns dropdown/multi-select options keys from a callback function
|
||||
* @since 2019-05-30
|
||||
*/
|
||||
$has_custom_source = apply_filters("um_has_dropdown_options_source__{$key}", false );
|
||||
|
||||
if ( isset( $array[ 'options' ] ) && in_array( $array[ 'type' ], array( 'select', 'multiselect' ) ) ) {
|
||||
|
||||
if ( !empty( $array[ 'custom_dropdown_options_source' ] ) && function_exists( $array[ 'custom_dropdown_options_source' ] ) && ! $has_custom_source ) {
|
||||
$options = call_user_func( $array[ 'custom_dropdown_options_source' ], $array[ 'options' ] );
|
||||
if( is_array( $options ) ){
|
||||
$array[ 'options' ] = apply_filters("um_custom_dropdown_options__{$key}", array_keys( $options ) );
|
||||
}
|
||||
}else{
|
||||
$array[ 'options' ] = apply_filters("um_custom_dropdown_options__{$key}", array() );
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
//validation of correct values from options in wp-admin
|
||||
$stripslashes = $args['submitted'][ $key ];
|
||||
if ( is_string( $stripslashes ) ) {
|
||||
@@ -253,7 +274,7 @@ function um_user_edit_profile( $args ) {
|
||||
}
|
||||
if ( in_array( $array['type'], array( 'select' ) ) &&
|
||||
! empty( $array['options'] ) && ! empty( $stripslashes ) &&
|
||||
! in_array( $stripslashes, array_map( 'trim', $array['options'] ) ) ) {
|
||||
! in_array( $stripslashes, array_map( 'trim', $array['options'] ) ) && ! $has_custom_source ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
@@ -299,6 +320,7 @@ function um_user_edit_profile( $args ) {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if ( isset( $args['submitted']['description'] ) ) {
|
||||
$to_update['description'] = $args['submitted']['description'];
|
||||
}
|
||||
|
||||
@@ -333,7 +333,7 @@ function um_profile_field_filter_hook__( $value, $data, $type = '' ) {
|
||||
if ( $data['validate'] == 'vk_url' ) $value = 'https://vk.com/' . $value;
|
||||
}
|
||||
|
||||
|
||||
|
||||
if ( isset( $data['validate'] ) && $data['validate'] == 'skype' ) {
|
||||
|
||||
$value = $value;
|
||||
@@ -351,15 +351,15 @@ function um_profile_field_filter_hook__( $value, $data, $type = '' ) {
|
||||
}
|
||||
|
||||
if ( isset( $data['validate'] ) && $data['validate'] == 'skype' ) {
|
||||
|
||||
|
||||
$value = str_replace('https://','',$value );
|
||||
$value = str_replace('http://','',$value );
|
||||
|
||||
|
||||
$data['url_target'] = ( isset( $data['url_target'] ) ) ? $data['url_target'] : '_blank';
|
||||
$value = '<a href="'. 'skype:'.$value.'?chat'.'" title="'.$value.'" target="'.$data['url_target'].'" ' . $url_rel . '>'.$value.'</a>';
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if ( !is_array( $value ) ) {
|
||||
if ( is_email( $value ) )
|
||||
$value = '<a href="mailto:'. $value.'" title="'.$value.'">'.$value.'</a>';
|
||||
@@ -679,13 +679,13 @@ function um_profile_field_filter_xss_validation( $value, $data, $type = '' ) {
|
||||
}
|
||||
}
|
||||
} elseif ( 'select' == $type || 'radio' == $type ) {
|
||||
if ( ! empty( $data['options'] ) && ! in_array( $value, $data['options'] ) ) {
|
||||
if ( ! empty( $data['options'] ) && ! in_array( $value, $data['options'] ) && empty( $data[ 'custom_dropdown_options_source' ] ) ) {
|
||||
$value = '';
|
||||
}
|
||||
}
|
||||
} elseif ( ! empty( $value ) ) {
|
||||
} elseif ( ! empty( $value ) && is_array( $value ) ) {
|
||||
if ( 'multiselect' == $type || 'checkbox' == $type ) {
|
||||
if ( ! empty( $data['options'] ) && is_array( $value ) ) {
|
||||
if ( ! empty( $data['options'] ) && empty( $data[ 'custom_dropdown_options_source' ] ) ) {
|
||||
$value = array_intersect( $value, $data['options'] );
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user