diff --git a/admin/core/um-admin-metabox.php b/admin/core/um-admin-metabox.php index 2e0cc98d..bac4ed15 100644 --- a/admin/core/um-admin-metabox.php +++ b/admin/core/um-admin-metabox.php @@ -1509,13 +1509,37 @@ class UM_Admin_Metabox { case '_custom_dropdown_options_source': ?> -

+

+ +

+ +

+ + fields->set_id = intval( $_POST['form_id'] ); + $ultimatemember->fields->set_mode = 'profile'; + $form_fields = $ultimatemember->fields->get_fields(); + $arr_options['fields'] = $form_fields; + + $debug = apply_filters('um_ajax_select_options__debug_mode', false ); + if( $debug ){ + $arr_options['debug'] = array( + $_POST, + $form_fields, + ); + } + + if( isset( $_POST['child_callback'] ) && ! empty( $_POST['child_callback'] ) && isset( $form_fields[ $_POST['child_name'] ] ) ){ + + $ajax_source_func = $_POST['child_callback']; + + // If the requested callback function is added in the form or added in the field option, execute it with call_user_func. + if( isset( $form_fields[ $_POST['child_name'] ]['custom_dropdown_options_source'] ) && + ! empty( $form_fields[ $_POST['child_name'] ]['custom_dropdown_options_source'] ) && + $form_fields[ $_POST['child_name'] ]['custom_dropdown_options_source'] == $ajax_source_func ){ + + $arr_options['field'] = $form_fields[ $_POST['child_name'] ]; + if( function_exists( $ajax_source_func ) ){ + $arr_options['items'] = call_user_func( $ajax_source_func ); + } + + }else{ + $arr_options['status'] = 'error'; + $arr_options['message'] = __( 'This is not possible for security reasons.','ultimatemember'); + } + + } + + wp_send_json( $arr_options ); + } diff --git a/core/um-builtin.php b/core/um-builtin.php index 232e476d..49848a98 100644 --- a/core/um-builtin.php +++ b/core/um-builtin.php @@ -202,7 +202,7 @@ class UM_Builtin { 'multiselect' => array( 'name' => 'Multi-Select', 'col1' => array('_title','_metakey','_help','_default','_options','_visibility'), - 'col2' => array('_label','_placeholder','_public','_roles','_min_selections','_max_selections','_custom_dropdown_options_source','_parent_dropdown_relationship'), + 'col2' => array('_label','_placeholder','_public','_roles','_min_selections','_max_selections','_custom_dropdown_options_source'), 'col3' => array('_required','_editable','_icon'), 'validate' => array( '_title' => array( diff --git a/core/um-fields.php b/core/um-fields.php index d15fd3a3..09dd725e 100644 --- a/core/um-fields.php +++ b/core/um-fields.php @@ -403,6 +403,10 @@ class UM_Fields { } else if ( $default ) { + $default = apply_filters( "um_field_default_value", $default, $data, $type ); + $default = apply_filters( "um_field_{$key}_default_value", $default, $data ); + $default = apply_filters( "um_field_{$type}_default_value", $default, $data ); + return $default; } else if ( $this->editing == true ) { @@ -560,16 +564,23 @@ class UM_Fields { * Get selected option from a callback function */ function get_option_value_from_callback( $value, $data, $type ){ - + + global $ultimatemember; if( in_array( $type , array('select','multiselect') ) && isset( $data['custom_dropdown_options_source'] ) && ! empty( $data['custom_dropdown_options_source'] ) ){ if( function_exists( $data['custom_dropdown_options_source'] ) ){ $arr_options = call_user_func( $data['custom_dropdown_options_source'] ); - + if( $type == 'select' ){ - return isset( $arr_options[ $value ] ) ? $arr_options[ $value ]: '' ; + if( isset( $arr_options[ $value ] ) && ! empty( $arr_options[ $value ] ) ) { + return $arr_options[ $value ]; + }else if( isset( $data['default'] ) && ! empty( $data['default'] ) && empty( $arr_options[ $value ] ) ) { + return $arr_options[ $data['default'] ]; + }else{ + return ''; + } } if( $type == 'multiselect' ){ @@ -579,11 +590,13 @@ class UM_Fields { }else{ $values = explode(', ', $value ); } - + $arr_paired_options = array(); foreach ( $values as $option ) { - $arr_paired_options[] = $arr_options[ $option ]; + if( isset( $arr_options[ $option ] ) ){ + $arr_paired_options[] = $arr_options[ $option ]; + } } return implode( ', ' , $arr_paired_options ); @@ -1664,6 +1677,7 @@ class UM_Fields { $output .= '
'; + if ( isset( $data['allowclear'] ) && $data['allowclear'] == 0 ) { $class = 'um-s2'; } else { @@ -1675,20 +1689,59 @@ class UM_Fields { } $output .= '
'; + + $has_parent_option = false; + $disabled_by_parent_option = ''; + $atts_ajax = ''; + $select_original_option_value = ''; + + if( isset( $data['parent_dropdown_relationship'] ) && ! empty( $data['parent_dropdown_relationship'] ) && ! $ultimatemember->user->preview ){ + + $disabled_by_parent_option = 'disabled = disabled'; + + $has_parent_option = true; + + $parent_dropdown_relationship = apply_filters("um_custom_dropdown_options_parent__{$form_key}", $data['parent_dropdown_relationship'], $data ); + $atts_ajax .= " data-um-parent='{$parent_dropdown_relationship}' "; - $output .= ''; + + if( ! $has_parent_option ){ + if ( isset($options) && $options == 'builtin'){ + $options = $ultimatemember->builtin->get ( $filter ); + } + + if (!isset($options)){ + $options = $ultimatemember->builtin->get ( 'countries' ); + } + + if ( isset( $options ) ) { + $options = apply_filters('um_select_dropdown_dynamic_options', $options, $data ); + $options = apply_filters("um_select_dropdown_dynamic_options_{$key}", $options ); + } } // role field @@ -2350,6 +2403,7 @@ class UM_Fields { $res = stripslashes( $res ); } + $data['is_view_field'] = true; $res = apply_filters("um_view_field", $res, $data, $type ); $res = apply_filters("um_view_field_value_{$type}", $res, $data ); @@ -2686,4 +2740,6 @@ class UM_Fields { return $output; } + + } diff --git a/core/um-filters-fields.php b/core/um-filters-fields.php index 9ed8051c..cf52de0e 100644 --- a/core/um-filters-fields.php +++ b/core/um-filters-fields.php @@ -414,19 +414,21 @@ * @param $type string * @param $data array * @return $value string - * @uses hook filter: um_view_field + * @uses hook filter: um_profile_field_filter_hook__ */ - add_filter('um_profile_field_filter_hook__','um_select_dropdown_callback_view_field', 10, 3); - function um_select_dropdown_callback_view_field( $value, $data, $type ){ + add_filter('um_profile_field_filter_hook__select','um_option_match_callback_view_field', 10, 2); + add_filter('um_profile_field_filter_hook__multiselect','um_option_match_callback_view_field', 10, 2); + add_filter('um_field_select_default_value','um_option_match_callback_view_field', 10, 2); + add_filter('um_field_multiselect_default_value','um_option_match_callback_view_field', 10, 2); + function um_option_match_callback_view_field( $value, $data ){ global $ultimatemember; - - if( in_array( $type , array('select','multiselect') ) && isset( $data['custom_dropdown_options_source'] ) && ! empty( $data['custom_dropdown_options_source'] ) ){ - - return $ultimatemember->fields->get_option_value_from_callback( $value, $data, $type ); - - - } + + if( ! empty( $data['custom_dropdown_options_source'] ) ){ + return $ultimatemember->fields->get_option_value_from_callback( $value, $data, $data['type'] ); + } return $value; } + + diff --git a/core/um-profile.php b/core/um-profile.php index 6c9b4a9f..b2bc6b72 100644 --- a/core/um-profile.php +++ b/core/um-profile.php @@ -168,18 +168,25 @@ class UM_Profile { $data = ''; if ( $key && um_filtered_value( $key ) ) { - if ( isset( $ultimatemember->builtin->all_user_fields[$key]['icon'] ) ) { - $icon = $ultimatemember->builtin->all_user_fields[$key]['icon']; + if ( isset( $ultimatemember->builtin->all_user_fields[ $key ] ) ){ + $data = $ultimatemember->builtin->all_user_fields[ $key ]; + } + + if ( isset( $data['icon'] ) ) { + $icon = $data['icon']; } else { $icon = ''; } + $data['in_profile_meta'] = true; + $icon = ( isset( $icon ) && !empty( $icon ) ) ? '' : ''; - if ( !um_get_option('profile_show_metaicon') ) + if ( !um_get_option('profile_show_metaicon') ){ $icon = ''; - - $value = um_filtered_value( $key ); + } + + $value = um_filtered_value( $key, $data ); $items[] = '' . $icon . $value . ''; $items[] = ''; diff --git a/core/um-short-functions.php b/core/um-short-functions.php index 87d36e68..cbbeb639 100644 --- a/core/um-short-functions.php +++ b/core/um-short-functions.php @@ -1,6 +1,7 @@ $1', $s); } @@ -225,41 +227,41 @@ } -/** - * @function um_user_ip() - * - * @description This function returns the IP address of user. - * - * @usage - * - * @returns Returns the user's IP address. - * - * @example The example below can retrieve the user's IP address + /** + * @function um_user_ip() + * + * @description This function returns the IP address of user. + * + * @usage + * + * @returns Returns the user's IP address. + * + * @example The example below can retrieve the user's IP address - + ?> - * - * - */ -function um_user_ip() { - $ip = '127.0.0.1'; + * + * + */ + function um_user_ip() { + $ip = '127.0.0.1'; - if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) { - //check ip from share internet - $ip = $_SERVER['HTTP_CLIENT_IP']; - } elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { - //to check ip is pass from proxy - $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; - } elseif( ! empty( $_SERVER['REMOTE_ADDR'] ) ) { - $ip = $_SERVER['REMOTE_ADDR']; + if ( ! empty( $_SERVER['HTTP_CLIENT_IP'] ) ) { + //check ip from share internet + $ip = $_SERVER['HTTP_CLIENT_IP']; + } elseif ( ! empty( $_SERVER['HTTP_X_FORWARDED_FOR'] ) ) { + //to check ip is pass from proxy + $ip = $_SERVER['HTTP_X_FORWARDED_FOR']; + } elseif( ! empty( $_SERVER['REMOTE_ADDR'] ) ) { + $ip = $_SERVER['REMOTE_ADDR']; + } + return apply_filters( 'um_user_ip', $ip ); } - return apply_filters( 'um_user_ip', $ip ); -} /*** *** @If conditions are met return true; @@ -364,6 +366,7 @@ function um_user_ip() { *** @Exit and redirect to home ***/ function um_redirect_home() { + exit( wp_redirect( home_url() ) ); } @@ -532,8 +535,7 @@ function um_user_ip() { /*** *** @Get a translated core page URL ***/ - function um_get_url_for_language( $post_id, $language ) - { + function um_get_url_for_language( $post_id, $language ){ $lang_post_id = icl_object_id( $post_id , 'page', true, $language ); $url = ""; @@ -785,54 +787,55 @@ function um_user_ip() { return $ultimatemember->members->results[ $argument ]; } -/** - * @function um_reset_user_clean() - * - * @description This function is similar to um_reset_user() with a difference that it will not use the logged-in user - data after resetting. It is a hard-reset function for all user data. - * - * @usage - * - * @returns Clears the user data. You need to fetch a user manually after using this function. - * - * @example You can reset user data by using the following line in your code + /** + * @function um_reset_user_clean() + * + * @description This function is similar to um_reset_user() with a difference that it will not use the logged-in user + data after resetting. It is a hard-reset function for all user data. + * + * @usage + * + * @returns Clears the user data. You need to fetch a user manually after using this function. + * + * @example You can reset user data by using the following line in your code - + - * - * - */ -function um_reset_user_clean() { - global $ultimatemember; - $ultimatemember->user->reset( true ); -} + * + * + */ + function um_reset_user_clean() { + global $ultimatemember; + $ultimatemember->user->reset( true ); + } -/** - * @function um_reset_user() - * - * @description This function resets the current user. You can use it to reset user data after - retrieving the details of a specific user. - * - * @usage - * - * @returns Clears the user data. If a user is logged in, the user data will be reset to that user's data - * - * @example You can reset user data by using the following line in your code + /** + * @function um_reset_user() + * + * @description This function resets the current user. You can use it to reset user data after + retrieving the details of a specific user. + * + * @usage + * + * @returns Clears the user data. If a user is logged in, the user data will be reset to that user's data + * + * @example You can reset user data by using the following line in your code - + - * - * - */ -function um_reset_user() { - global $ultimatemember; - $ultimatemember->user->reset(); -} + * + * + */ + function um_reset_user() { + global $ultimatemember; + $ultimatemember->user->reset(); + } /*** *** @gets the queried user ***/ function um_queried_user() { + return get_query_var('um_user'); } @@ -1075,51 +1078,51 @@ function um_reset_user() { return um_get_option('admin_email'); } -/** - * @function um_get_option() - * - * @description This function returns the value of an option or setting. - * - * @usage - * - * @param $option_id (string) (required) The option or setting that you want to retrieve - * - * @returns Returns the value of the setting you requested, or a blank value if the setting - does not exist. - * - * @example Get default user role set in global options + /** + * @function um_get_option() + * + * @description This function returns the value of an option or setting. + * + * @usage + * + * @param $option_id (string) (required) The option or setting that you want to retrieve + * + * @returns Returns the value of the setting you requested, or a blank value if the setting + does not exist. + * + * @example Get default user role set in global options - + - * - * @example Get blocked IP addresses set in backend + * + * @example Get blocked IP addresses set in backend - + - * - */ -function um_get_option($option_id) { - global $ultimatemember; - if ( !isset( $ultimatemember->options ) ) return ''; - $um_options = $ultimatemember->options; - if ( isset( $um_options[ $option_id ] ) && !empty( $um_options[ $option_id ] ) ) { - return apply_filters("um_get_option_filter__{$option_id}", $um_options[ $option_id ] ); - } + * + */ + function um_get_option($option_id) { + global $ultimatemember; + if ( !isset( $ultimatemember->options ) ) return ''; + $um_options = $ultimatemember->options; + if ( isset( $um_options[ $option_id ] ) && !empty( $um_options[ $option_id ] ) ) { + return apply_filters("um_get_option_filter__{$option_id}", $um_options[ $option_id ] ); + } - switch($option_id){ + switch($option_id){ - case 'site_name': - return get_bloginfo('name'); - break; + case 'site_name': + return get_bloginfo('name'); + break; - case 'admin_email': - return get_bloginfo('admin_email'); - break; + case 'admin_email': + return get_bloginfo('admin_email'); + break; + + } } -} - /*** *** @Display a link to profile page ***/ @@ -1136,42 +1139,42 @@ function um_get_option($option_id) { return $ultimatemember->query->get_roles(); } -/** - * @function um_fetch_user() - * - * @description This function sets a user and allow you to retrieve any information for the retrieved user - * - * @usage - * - * @param $user_id (numeric) (required) A user ID is required. This is the user's ID that you wish to set/retrieve - * - * @returns Sets a specific user and prepares profile data and user permissions and makes them accessible. - * - * @example The example below will set user ID 5 prior to retrieving his profile information. + /** + * @function um_fetch_user() + * + * @description This function sets a user and allow you to retrieve any information for the retrieved user + * + * @usage + * + * @param $user_id (numeric) (required) A user ID is required. This is the user's ID that you wish to set/retrieve + * + * @returns Sets a specific user and prepares profile data and user permissions and makes them accessible. + * + * @example The example below will set user ID 5 prior to retrieving his profile information. - + ?> - * - * @example In the following example you can fetch the profile of a logged-in user dynamically. + * + * @example In the following example you can fetch the profile of a logged-in user dynamically. - + ?> - * - */ -function um_fetch_user( $user_id ) { - global $ultimatemember; - $ultimatemember->user->set( $user_id ); -} + * + */ + function um_fetch_user( $user_id ) { + global $ultimatemember; + $ultimatemember->user->set( $user_id ); + } /*** *** @Load profile key @@ -1704,7 +1707,6 @@ function um_fetch_user( $user_id ) { } return $value; - } /** @@ -1738,6 +1740,7 @@ function um_fetch_user( $user_id ) { * @return string */ function um_get_search_form() { + return do_shortcode( '[ultimatemember_searchform]' ); } @@ -1747,6 +1750,7 @@ function um_fetch_user( $user_id ) { * @return string */ function um_search_form() { + echo um_get_search_form(); } @@ -1886,4 +1890,5 @@ function um_fetch_user( $user_id ) { } return $ret; - } \ No newline at end of file + } +