mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-16 21:23:39 +09:00
Adds parent select field option to dynamically populate child select fields
This commit is contained in:
@@ -1509,13 +1509,37 @@ class UM_Admin_Metabox {
|
||||
case '_custom_dropdown_options_source':
|
||||
?>
|
||||
|
||||
<p><label for="_placeholder">Options Callback<?php $this->tooltip('Add a callback source to retrieve options.'); ?></label>
|
||||
<p><label for="_custom_dropdown_options_source">Choices Callback<?php $this->tooltip('Add a callback source to retrieve choices.'); ?></label>
|
||||
<input type="text" name="_custom_dropdown_options_source" id="_custom_dropdown_options_source" value="<?php echo htmlspecialchars($this->edit_mode_value, ENT_QUOTES); ?>" />
|
||||
</p>
|
||||
|
||||
<?php
|
||||
break;
|
||||
|
||||
|
||||
case '_parent_dropdown_relationship':
|
||||
?>
|
||||
|
||||
<p><label for="_parent_dropdown_relationship">Parent Option<?php $this->tooltip('Dynamically populates the option based from selected parent option.'); ?></label>
|
||||
<select name="_parent_dropdown_relationship" id="_parent_dropdown_relationship" class="umaf-selectjs" style="width: 100%">
|
||||
<option value="">No Selected</option>
|
||||
<?php
|
||||
if ( $ultimatemember->builtin->custom_fields ) {
|
||||
foreach ($ultimatemember->builtin->custom_fields as $field_key => $array) {
|
||||
if( in_array( $array['type'], array( 'select' ) )
|
||||
&& $field_args['metakey'] != $array['metakey'] ){
|
||||
echo "<option value='".$array['metakey']."' ".selected( $array['metakey'], $this->edit_mode_value ).">".$array['title']."</option>";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
</select>
|
||||
</p>
|
||||
|
||||
<?php
|
||||
break;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
jQuery(document).ready(function() {
|
||||
|
||||
jQuery(document).on('click', '.um-popup-overlay', function(){
|
||||
|
||||
remove_Modal();
|
||||
});
|
||||
|
||||
jQuery(document).on('click', '.um-modal-overlay, a[data-action="um_remove_modal"]', function(){
|
||||
|
||||
um_remove_modal();
|
||||
});
|
||||
|
||||
@@ -81,7 +83,6 @@ jQuery(document).ready(function() {
|
||||
jQuery('.um-single-file-preview[data-key='+key+']').parents('.um-field').find('.um-btn-auto-width').html( jQuery(this).attr('data-change') );
|
||||
|
||||
jQuery('.um-single-file-preview[data-key='+key+']').parents('.um-field').find('input[type=hidden]').val( jQuery('.um-single-file-preview[data-key='+key+']').parents('.um-field').find('.um-single-fileinfo a').attr('href') );
|
||||
|
||||
});
|
||||
|
||||
jQuery(document).on('click', '.um-finish-upload.image', function(){
|
||||
@@ -147,7 +148,6 @@ jQuery(document).ready(function() {
|
||||
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
jQuery(document).on('click', 'a[data-modal^="um_"], span[data-modal^="um_"]', function(e){
|
||||
@@ -182,7 +182,6 @@ jQuery(document).ready(function() {
|
||||
um_new_modal( modal_id, size );
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
});
|
||||
+121
-4
@@ -1,10 +1,12 @@
|
||||
jQuery(document).ready(function() {
|
||||
|
||||
jQuery(document).on('click', '.um-dropdown a', function(e){
|
||||
|
||||
return false;
|
||||
});
|
||||
|
||||
jQuery(document).on('click', '.um-dropdown a.real_url', function(e){
|
||||
|
||||
window.location = jQuery(this).attr('href');
|
||||
});
|
||||
|
||||
@@ -16,7 +18,8 @@ jQuery(document).ready(function() {
|
||||
});
|
||||
|
||||
jQuery(document).on('click', '.um-dropdown-hide', function(e){
|
||||
UM_hide_menus();
|
||||
|
||||
UM_hide_menus();
|
||||
});
|
||||
|
||||
jQuery(document).on('click', 'a.um-manual-trigger', function(){
|
||||
@@ -50,7 +53,6 @@ jQuery(document).ready(function() {
|
||||
this_field.addClass('active');
|
||||
this_field.find('i').removeClass().addClass('um-icon-android-checkbox-outline');
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
jQuery('.um-datepicker').each(function(){
|
||||
@@ -179,6 +181,7 @@ jQuery(document).ready(function() {
|
||||
jQuery('.um-s1,.um-s2').css({'display':'block'});
|
||||
|
||||
jQuery(".um-s1").select2({
|
||||
|
||||
allowClear: true,
|
||||
});
|
||||
|
||||
@@ -213,7 +216,6 @@ jQuery(document).ready(function() {
|
||||
jQuery(this).addClass('disabled');
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
jQuery(document).on('click', '.um-field-group-cancel', function(e){
|
||||
@@ -288,7 +290,122 @@ jQuery(document).ready(function() {
|
||||
});
|
||||
|
||||
jQuery(document).on('click', '#um-search-button', function() {
|
||||
jQuery(this).parents('form').submit();
|
||||
|
||||
jQuery(this).parents('form').submit();
|
||||
});
|
||||
|
||||
|
||||
var um_select_options_cache = {};
|
||||
|
||||
/**
|
||||
* Find all select fields with parent select fields
|
||||
*/
|
||||
jQuery('select[data-um-parent]').each(function(){
|
||||
|
||||
var me = jQuery(this);
|
||||
var parent_option = me.data('um-parent');
|
||||
var um_ajax_url = me.data('um-ajax-url');
|
||||
var um_ajax_source = me.data('um-ajax-source');
|
||||
var original_value = me.val();
|
||||
|
||||
me.attr('data-um-init-field', true );
|
||||
|
||||
jQuery(document).on('change','select[name="'+parent_option+'"]',function(){
|
||||
var parent = jQuery(this);
|
||||
var form_id = parent.closest('form').find('input[type=hidden][name=form_id]').val();
|
||||
var arr_key = me.attr('name');
|
||||
|
||||
if( parent.val() != '' && typeof um_select_options_cache[ arr_key ] != 'object' ){
|
||||
|
||||
jQuery.ajax({
|
||||
url: um_ajax_url,
|
||||
type: 'post',
|
||||
data: {
|
||||
action: 'ultimatemember_ajax_select_options',
|
||||
parent_option: parent.val(),
|
||||
child_callback: um_ajax_source,
|
||||
child_name: me.attr('name'),
|
||||
form_id: form_id,
|
||||
},
|
||||
success: function( data ){
|
||||
|
||||
if( data.status == 'success' && parent.val() != '' ){
|
||||
um_field_populate_child_options( me, data, arr_key);
|
||||
}
|
||||
|
||||
if( typeof data.debug !== 'undefined' ){
|
||||
console.log( data );
|
||||
}
|
||||
},
|
||||
error: function( e ){
|
||||
console.log( e );
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
}
|
||||
|
||||
if( parent.val() != '' && typeof um_select_options_cache[ arr_key ] == 'object' ){
|
||||
var data = um_select_options_cache[ arr_key ];
|
||||
um_field_populate_child_options( me, data, arr_key );
|
||||
}
|
||||
|
||||
if( parent.val() == '' ){
|
||||
me.find('option[value!=""]').remove();
|
||||
me.val('').trigger('change');
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
jQuery('select[name="'+parent_option+'"]').trigger('change');
|
||||
|
||||
});
|
||||
|
||||
/**
|
||||
* Populates child options and cache ajax response
|
||||
* @param DOM me child option elem
|
||||
* @param array data
|
||||
* @param string key
|
||||
*/
|
||||
function um_field_populate_child_options( me, data, arr_key, arr_items ){
|
||||
|
||||
|
||||
var parent_option = me.data('um-parent');
|
||||
var child_name = me.attr('name');
|
||||
var parent_dom = jQuery('select[name="'+parent_option+'"]');
|
||||
me.find('option[value!=""]').remove();
|
||||
|
||||
if( ! me.hasClass('um-child-option-disabled') ){
|
||||
me.removeAttr('disabled');
|
||||
}
|
||||
|
||||
var arr_items = [];
|
||||
|
||||
jQuery.each( data.items, function(k,v){
|
||||
arr_items.push({id: k, text: v});
|
||||
});
|
||||
|
||||
me.select2('destroy');
|
||||
me.select2({
|
||||
data: arr_items,
|
||||
allowClear: true,
|
||||
minimumResultsForSearch: 10,
|
||||
});
|
||||
|
||||
if( typeof data.field.default !== 'undefined' && ! me.data('um-original-value') ){
|
||||
me.val( data.field.default ).trigger('change');
|
||||
}else if( me.data('um-original-value') != '' ){
|
||||
me.val( me.data('um-original-value') ).trigger('change');
|
||||
}
|
||||
|
||||
if( data.field.editable == 0 ){
|
||||
me.addClass('um-child-option-disabled');
|
||||
me.attr('disabled','disabled');
|
||||
}
|
||||
|
||||
um_select_options_cache[ arr_key ] = data;
|
||||
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
@@ -23,6 +23,7 @@
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
*** @remove any file silently
|
||||
***/
|
||||
@@ -158,3 +159,53 @@
|
||||
|
||||
die();
|
||||
}
|
||||
|
||||
/***
|
||||
*** @run an ajax to retrieve select options from a callback function
|
||||
***/
|
||||
add_action('wp_ajax_nopriv_ultimatemember_ajax_select_options', 'ultimatemember_ajax_select_options');
|
||||
add_action('wp_ajax_ultimatemember_ajax_select_options', 'ultimatemember_ajax_select_options');
|
||||
function ultimatemember_ajax_select_options() {
|
||||
|
||||
global $ultimatemember;
|
||||
|
||||
$arr_options = array();
|
||||
$arr_options['status'] = 'success';
|
||||
$arr_options['post'] = $_POST;
|
||||
|
||||
$ultimatemember->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 );
|
||||
}
|
||||
|
||||
+1
-1
@@ -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(
|
||||
|
||||
+69
-13
@@ -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 .= '<div class="um-field' . $classes . '"' . $conditional . ' data-key="'.$key.'">';
|
||||
|
||||
|
||||
if ( isset( $data['allowclear'] ) && $data['allowclear'] == 0 ) {
|
||||
$class = 'um-s2';
|
||||
} else {
|
||||
@@ -1675,20 +1689,59 @@ class UM_Fields {
|
||||
}
|
||||
|
||||
$output .= '<div class="um-field-area">';
|
||||
|
||||
$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 .= '<select '.$disabled.' name="'.$form_key.'" id="'.$form_key.'" data-validate="'.$validate.'" data-key="'.$key.'" class="'.$this->get_class($key, $data, $class).'" style="width: 100%" data-placeholder="'.$placeholder.'">';
|
||||
if( isset( $data['custom_dropdown_options_source'] ) && ! empty( $data['custom_dropdown_options_source'] ) &&
|
||||
$has_parent_option && function_exists( $data['custom_dropdown_options_source'] ) &&
|
||||
um_user( $data['parent_dropdown_relationship'] ) ){
|
||||
$options = call_user_func( $data['custom_dropdown_options_source'] );
|
||||
$disabled_by_parent_option = '';
|
||||
if( um_user( $form_key ) ){
|
||||
$select_original_option_value = " data-um-original-value='".um_user( $form_key )."' ";
|
||||
}
|
||||
}
|
||||
|
||||
if ( isset($options) && $options == 'builtin'){
|
||||
$options = $ultimatemember->builtin->get ( $filter );
|
||||
}
|
||||
|
||||
if (!isset($options)){
|
||||
$options = $ultimatemember->builtin->get ( 'countries' );
|
||||
if( isset( $data['custom_dropdown_options_source'] ) && ! empty( $data['custom_dropdown_options_source'] ) ){
|
||||
|
||||
$ajax_source = apply_filters("um_custom_dropdown_options_source__{$form_key}", $data['custom_dropdown_options_source'], $data );
|
||||
$atts_ajax .= " data-um-ajax-source='{$ajax_source}' ";
|
||||
|
||||
$ajax_source_url = apply_filters("um_custom_dropdown_options_source_url__{$form_key}", admin_url('admin-ajax.php'), $data );
|
||||
$atts_ajax .= " data-um-ajax-url='{$ajax_source_url}' ";
|
||||
|
||||
|
||||
}
|
||||
|
||||
if ( isset( $options ) ) {
|
||||
$options = apply_filters('um_select_dropdown_dynamic_options', $options, $data );
|
||||
$options = apply_filters("um_select_dropdown_dynamic_options_{$key}", $options );
|
||||
$output .= '<select '.$disabled.' '.$select_original_option_value.' '.$disabled_by_parent_option.' name="'.$form_key.'" id="'.$form_key.'" data-validate="'.$validate.'" data-key="'.$key.'" class="'.$this->get_class($key, $data, $class).'" style="width: 100%" data-placeholder="'.$placeholder.'" '.$atts_ajax.'>';
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
+12
-10
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
+12
-5
@@ -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 ) ) ? '<i class="'.$icon.'"></i>' : '';
|
||||
|
||||
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[] = '<span>' . $icon . $value . '</span>';
|
||||
$items[] = '<span class="b">•</span>';
|
||||
|
||||
+139
-134
@@ -1,6 +1,7 @@
|
||||
<?php
|
||||
|
||||
function um_mail_content_type( $content_type ) {
|
||||
|
||||
return 'text/html';
|
||||
}
|
||||
|
||||
@@ -47,6 +48,7 @@
|
||||
*** @Convert urls to clickable links
|
||||
***/
|
||||
function um_clickable_links($s) {
|
||||
|
||||
return preg_replace('@(https?://([-\w\.]+[-\w])+(:\d+)?(/([\w/_\.#-]*(\?\S+)?[^\.\s])?)?)@', '<a href="$1" class="um-link" target="_blank">$1</a>', $s);
|
||||
}
|
||||
|
||||
@@ -225,41 +227,41 @@
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* @function um_user_ip()
|
||||
*
|
||||
* @description This function returns the IP address of user.
|
||||
*
|
||||
* @usage <?php $user_ip = um_user_ip(); ?>
|
||||
*
|
||||
* @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 <?php $user_ip = um_user_ip(); ?>
|
||||
*
|
||||
* @returns Returns the user's IP address.
|
||||
*
|
||||
* @example The example below can retrieve the user's IP address
|
||||
|
||||
<?php
|
||||
<?php
|
||||
|
||||
$user_ip = um_user_ip();
|
||||
echo 'User IP address is: ' . $user_ip; // prints the user IP address e.g. 127.0.0.1
|
||||
$user_ip = um_user_ip();
|
||||
echo 'User IP address is: ' . $user_ip; // prints the user IP address e.g. 127.0.0.1
|
||||
|
||||
?>
|
||||
?>
|
||||
|
||||
*
|
||||
*
|
||||
*/
|
||||
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 <?php um_reset_user_clean(); ?>
|
||||
*
|
||||
* @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 <?php um_reset_user_clean(); ?>
|
||||
*
|
||||
* @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
|
||||
|
||||
<?php um_reset_user_clean(); ?>
|
||||
<?php um_reset_user_clean(); ?>
|
||||
|
||||
*
|
||||
*
|
||||
*/
|
||||
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 <?php um_reset_user(); ?>
|
||||
*
|
||||
* @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 <?php um_reset_user(); ?>
|
||||
*
|
||||
* @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
|
||||
|
||||
<?php um_reset_user(); ?>
|
||||
<?php um_reset_user(); ?>
|
||||
|
||||
*
|
||||
*
|
||||
*/
|
||||
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 <?php $value = um_get_option( $setting ); ?>
|
||||
*
|
||||
* @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 <?php $value = um_get_option( $setting ); ?>
|
||||
*
|
||||
* @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
|
||||
|
||||
<?php $default_role = um_get_option('default_role'); ?>
|
||||
<?php $default_role = um_get_option('default_role'); ?>
|
||||
|
||||
*
|
||||
* @example Get blocked IP addresses set in backend
|
||||
*
|
||||
* @example Get blocked IP addresses set in backend
|
||||
|
||||
<?php $blocked_ips = um_get_option('blocked_ips'); ?>
|
||||
<?php $blocked_ips = um_get_option('blocked_ips'); ?>
|
||||
|
||||
*
|
||||
*/
|
||||
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 <?php um_fetch_user( $user_id ); ?>
|
||||
*
|
||||
* @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 <?php um_fetch_user( $user_id ); ?>
|
||||
*
|
||||
* @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.
|
||||
|
||||
<?php
|
||||
<?php
|
||||
|
||||
um_fetch_user(5);
|
||||
echo um_user('display_name'); // returns the display name of user ID 5
|
||||
um_fetch_user(5);
|
||||
echo um_user('display_name'); // returns the display name of user ID 5
|
||||
|
||||
?>
|
||||
?>
|
||||
|
||||
*
|
||||
* @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.
|
||||
|
||||
<?php
|
||||
<?php
|
||||
|
||||
um_fetch_user( get_current_user_id() );
|
||||
echo um_user('display_name'); // returns the display name of logged-in user
|
||||
um_fetch_user( get_current_user_id() );
|
||||
echo um_user('display_name'); // returns the display name of logged-in user
|
||||
|
||||
?>
|
||||
?>
|
||||
|
||||
*
|
||||
*/
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user