Add filter hooks to populate dropdown options alternative to callback function

This commit is contained in:
Champ Camba
2019-06-03 01:20:31 +08:00
parent d948f1d7f5
commit 4d53a629a0
+11 -4
View File
@@ -251,13 +251,19 @@ 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' ] ) ) {
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' ] = array_keys( $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() );
}
}
@@ -265,7 +271,7 @@ function um_user_edit_profile( $args ) {
$stripslashes = stripslashes( $args['submitted'][ $key ] );
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;
}
@@ -311,6 +317,7 @@ function um_user_edit_profile( $args ) {
}
}
if ( isset( $args['submitted']['description'] ) ) {
$to_update['description'] = $args['submitted']['description'];
}