From 4d53a629a03cf9ee188a5108a0233e9e5b6c9f35 Mon Sep 17 00:00:00 2001 From: Champ Camba Date: Mon, 3 Jun 2019 01:20:31 +0800 Subject: [PATCH] Add filter hooks to populate dropdown options alternative to callback function --- includes/core/um-actions-profile.php | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/includes/core/um-actions-profile.php b/includes/core/um-actions-profile.php index 46d71322..f99504e9 100644 --- a/includes/core/um-actions-profile.php +++ b/includes/core/um-actions-profile.php @@ -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']; }