mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-07-18 22:23:37 +09:00
fix callback func in members directory search
This commit is contained in:
@@ -87,6 +87,7 @@ if ( ! class_exists( 'um\core\Form' ) ) {
|
||||
*/
|
||||
function ajax_select_options() {
|
||||
|
||||
|
||||
$arr_options = array();
|
||||
$arr_options['status'] = 'success';
|
||||
$arr_options['post'] = $_POST;
|
||||
@@ -96,57 +97,66 @@ if ( ! class_exists( 'um\core\Form' ) ) {
|
||||
$form_fields = UM()->fields()->get_fields();
|
||||
$arr_options['fields'] = $form_fields;
|
||||
|
||||
/**
|
||||
* UM hook
|
||||
*
|
||||
* @type filter
|
||||
* @title um_ajax_select_options__debug_mode
|
||||
* @description Activate debug mode for AJAX select options
|
||||
* @input_vars
|
||||
* [{"var":"$debug_mode","type":"bool","desc":"Enable Debug mode"}]
|
||||
* @change_log
|
||||
* ["Since: 2.0"]
|
||||
* @usage
|
||||
* <?php add_filter( 'um_ajax_select_options__debug_mode', 'function_name', 10, 1 ); ?>
|
||||
* @example
|
||||
* <?php
|
||||
* add_filter( 'um_ajax_select_options__debug_mode', 'my_ajax_select_options__debug_mode', 10, 1 );
|
||||
* function my_ajax_select_options__debug_mode( $debug_mode ) {
|
||||
* // your code here
|
||||
* return $debug_mode;
|
||||
* }
|
||||
* ?>
|
||||
*/
|
||||
$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'] ] ) ){
|
||||
|
||||
if ( $arr_options['post']['members_directory'] == 'yes' ) {
|
||||
$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, $arr_options['field']['parent_dropdown_relationship'] );
|
||||
}
|
||||
|
||||
}else{
|
||||
$arr_options['status'] = 'error';
|
||||
$arr_options['message'] = __( 'This is not possible for security reasons.','ultimate-member');
|
||||
if( function_exists( $ajax_source_func ) ){
|
||||
$arr_options['items'] = call_user_func( $ajax_source_func, $arr_options['field']['parent_dropdown_relationship'] );
|
||||
wp_send_json( $arr_options );
|
||||
}
|
||||
} else {
|
||||
/**
|
||||
* UM hook
|
||||
*
|
||||
* @type filter
|
||||
* @title um_ajax_select_options__debug_mode
|
||||
* @description Activate debug mode for AJAX select options
|
||||
* @input_vars
|
||||
* [{"var":"$debug_mode","type":"bool","desc":"Enable Debug mode"}]
|
||||
* @change_log
|
||||
* ["Since: 2.0"]
|
||||
* @usage
|
||||
* <?php add_filter( 'um_ajax_select_options__debug_mode', 'function_name', 10, 1 ); ?>
|
||||
* @example
|
||||
* <?php
|
||||
* add_filter( 'um_ajax_select_options__debug_mode', 'my_ajax_select_options__debug_mode', 10, 1 );
|
||||
* function my_ajax_select_options__debug_mode( $debug_mode ) {
|
||||
* // your code here
|
||||
* return $debug_mode;
|
||||
* }
|
||||
* ?>
|
||||
*/
|
||||
$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'] ] ) ){
|
||||
|
||||
wp_send_json( $arr_options );
|
||||
$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, $arr_options['field']['parent_dropdown_relationship'] );
|
||||
}
|
||||
|
||||
} else {
|
||||
$arr_options['status'] = 'error';
|
||||
$arr_options['message'] = __( 'This is not possible for security reasons.','ultimate-member');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
wp_send_json( $arr_options );
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -312,7 +322,7 @@ if ( ! class_exists( 'um\core\Form' ) ) {
|
||||
$exclude_roles = array_diff( array_keys( $wp_roles->roles ), array_merge( $role_keys, array( 'subscriber' ) ) );
|
||||
|
||||
if ( ! empty( $role ) &&
|
||||
( ! in_array( $role , $custom_field_roles ) || in_array( $role , $exclude_roles ) ) ) {
|
||||
( ! in_array( $role , $custom_field_roles ) || in_array( $role , $exclude_roles ) ) ) {
|
||||
wp_die( __( 'This is not possible for security reasons.','ultimate-member') );
|
||||
}
|
||||
|
||||
|
||||
@@ -88,14 +88,14 @@ if ( ! class_exists( 'um\core\Members' ) ) {
|
||||
return $string;
|
||||
}
|
||||
|
||||
/**
|
||||
/**
|
||||
* Prepare filter data
|
||||
*
|
||||
* @param $filter
|
||||
* @return array
|
||||
* @return array
|
||||
*/
|
||||
function prepare_filter( $filter ) {
|
||||
$fields = UM()->builtin()->all_user_fields;
|
||||
$fields = UM()->builtin()->all_user_fields;
|
||||
|
||||
if ( isset( $fields[ $filter ] ) ) {
|
||||
$attrs = $fields[ $filter ];
|
||||
@@ -223,7 +223,7 @@ if ( ! class_exists( 'um\core\Members' ) ) {
|
||||
}
|
||||
|
||||
return compact( 'type', 'attrs' );
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Show filter
|
||||
@@ -231,11 +231,11 @@ if ( ! class_exists( 'um\core\Members' ) ) {
|
||||
* @param $filter
|
||||
*/
|
||||
function show_filter( $filter ) {
|
||||
/**
|
||||
* @var $type
|
||||
* @var $attrs
|
||||
*/
|
||||
extract( $this->prepare_filter( $filter ) );
|
||||
/**
|
||||
* @var $type
|
||||
* @var $attrs
|
||||
*/
|
||||
extract( $this->prepare_filter( $filter ) );
|
||||
|
||||
switch ( $type ) {
|
||||
|
||||
@@ -243,9 +243,9 @@ if ( ! class_exists( 'um\core\Members' ) ) {
|
||||
|
||||
?>
|
||||
|
||||
<select name="<?php echo $filter; ?>" id="<?php echo $filter; ?>" class="um-s1" style="width: 100%" data-placeholder="<?php echo __( stripslashes( $attrs['label'] ), 'ultimate-member' ); ?>" <?php if ( ! empty( $attrs['custom_dropdown_options_source'] ) ) { ?> data-um-ajax-source="<?php echo $attrs['custom_dropdown_options_source'] ?>"<?php } ?>>
|
||||
<select name="<?php echo $filter; ?>" id="<?php echo $filter; ?>" class="um-s1" style="width: 100%" data-placeholder="<?php echo __( stripslashes( $attrs['label'] ), 'ultimate-member' ); ?>" <?php if ( ! empty( $attrs['custom_dropdown_options_source'] ) ) { ?> data-um-parent="<?php echo $attrs['parent_dropdown_relationship']; ?>" data-mebers-directory="yes" data-um-ajax-source="<?php echo $attrs['custom_dropdown_options_source'] ?>"<?php } ?>>
|
||||
|
||||
<option></option>
|
||||
<option></option>
|
||||
|
||||
<?php foreach ( $attrs['options'] as $k => $v ) {
|
||||
|
||||
@@ -259,13 +259,14 @@ if ( ! class_exists( 'um\core\Members' ) ) {
|
||||
if ( isset( $attrs['custom'] ) )
|
||||
$opt = $k;
|
||||
|
||||
|
||||
?>
|
||||
|
||||
<option value="<?php echo $opt; ?>" <?php um_select_if_in_query_params( $filter, $opt ); ?>><?php echo __( $v, 'ultimate-member'); ?></option>
|
||||
<option value="<?php echo $opt; ?>" <?php um_select_if_in_query_params( $filter, $opt ); ?> <?php selected( $_GET[$filter], $v ) ?>><?php echo __( $v, 'ultimate-member'); ?></option>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
</select>
|
||||
</select>
|
||||
|
||||
<?php
|
||||
|
||||
@@ -275,7 +276,7 @@ if ( ! class_exists( 'um\core\Members' ) ) {
|
||||
|
||||
?>
|
||||
|
||||
<input type="text" autocomplete="off" name="<?php echo $filter; ?>" id="<?php echo $filter; ?>" placeholder="<?php echo isset( $attrs['label'] ) ? __( $attrs['label'], 'ultimate-member') : ''; ?>" value='<?php echo esc_attr( um_queried_search_value( $filter, false ) ); ?>' />
|
||||
<input type="text" autocomplete="off" name="<?php echo $filter; ?>" id="<?php echo $filter; ?>" placeholder="<?php echo isset( $attrs['label'] ) ? __( $attrs['label'], 'ultimate-member') : ''; ?>" value='<?php echo esc_attr( um_queried_search_value( $filter, false ) ); ?>' />
|
||||
|
||||
<?php
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@
|
||||
*/
|
||||
function um_members_directory_search( $args ) {
|
||||
$search_filters = array();
|
||||
|
||||
|
||||
if ( isset($args['search_fields']) ) {
|
||||
foreach( $args['search_fields'] as $k => $testfilter ){
|
||||
if ($testfilter && !in_array( $testfilter, (array)$search_filters ) ) {
|
||||
@@ -49,48 +49,47 @@ function um_members_directory_search( $args ) {
|
||||
|
||||
$count = count( $search_filters ); ?>
|
||||
|
||||
<div class="um-search um-search-<?php echo $count; ?>">
|
||||
|
||||
<form method="get" action="" />
|
||||
|
||||
<div class="um-search um-search-<?php echo $count; ?>">
|
||||
|
||||
<form method="get" action="" />
|
||||
|
||||
<?php if ( isset( $_REQUEST['page_id'] ) && get_option('permalink_structure') == 0 ) { ?>
|
||||
|
||||
<input type="hidden" name="page_id" id="page_id" value="<?php echo esc_attr( $_REQUEST['page_id']); ?>" />
|
||||
|
||||
|
||||
<input type="hidden" name="page_id" id="page_id" value="<?php echo esc_attr( $_REQUEST['page_id']); ?>" />
|
||||
|
||||
<?php }
|
||||
|
||||
$i = 0;
|
||||
foreach( $search_filters as $filter ) {
|
||||
$i++;
|
||||
|
||||
|
||||
if ( $i % 2 == 0 ) {
|
||||
$add_class = 'um-search-filter-2';
|
||||
} else {
|
||||
$add_class = '';
|
||||
}
|
||||
|
||||
echo '<div class="um-search-filter '. $add_class .'">'; UM()->members()->show_filter( $filter ); echo '</div>';
|
||||
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div class="um-clear"></div>
|
||||
|
||||
<div class="um-search-submit">
|
||||
|
||||
<input type="hidden" name="um_search" id="um_search" value="1" />
|
||||
|
||||
<a href="#" class="um-button um-do-search"><?php _e('Search','ultimate-member'); ?></a><a href="<?php echo UM()->permalinks()->get_current_url( true ); ?>" class="um-button um-alt"><?php _e('Reset','ultimate-member'); ?></a>
|
||||
|
||||
</div><div class="um-clear"></div>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
echo '<div class="um-search-filter '. $add_class .'">'; UM()->members()->show_filter( $filter ); echo '</div>';
|
||||
}
|
||||
|
||||
?>
|
||||
|
||||
<div class="um-clear"></div>
|
||||
|
||||
<div class="um-search-submit">
|
||||
|
||||
<input type="hidden" name="um_search" id="um_search" value="1" />
|
||||
|
||||
<a href="#" class="um-button um-do-search"><?php _e('Search','ultimate-member'); ?></a><a href="<?php echo UM()->permalinks()->get_current_url( true ); ?>" class="um-button um-alt"><?php _e('Reset','ultimate-member'); ?></a>
|
||||
|
||||
</div><div class="um-clear"></div>
|
||||
|
||||
</form>
|
||||
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
add_action( 'um_members_directory_search', 'um_members_directory_search' );
|
||||
@@ -115,7 +114,7 @@ add_action( 'um_pre_directory_shortcode', 'um_pre_directory_shortcode' );
|
||||
*/
|
||||
function um_members_directory_head( $args ) {
|
||||
extract( $args );
|
||||
|
||||
|
||||
if ( isset($_REQUEST['um_search']) ) {
|
||||
$is_filtering = 1;
|
||||
} else if ( UM()->is_filtering == 1 ) {
|
||||
@@ -123,15 +122,15 @@ function um_members_directory_head( $args ) {
|
||||
} else {
|
||||
$is_filtering = 0;
|
||||
}
|
||||
|
||||
|
||||
if ( um_members('header') && $is_filtering && um_members('users_per_page') ) { ?>
|
||||
|
||||
<div class="um-members-intro">
|
||||
|
||||
<div class="um-members-total"><?php echo ( um_members('total_users') > 1 ) ? um_members('header') : um_members('header_single'); ?></div>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
<div class="um-members-intro">
|
||||
|
||||
<div class="um-members-total"><?php echo ( um_members('total_users') > 1 ) ? um_members('header') : um_members('header_single'); ?></div>
|
||||
|
||||
</div>
|
||||
|
||||
<?php }
|
||||
}
|
||||
add_action( 'um_members_directory_head', 'um_members_directory_head' );
|
||||
@@ -148,71 +147,71 @@ function um_members_directory_pagination( $args ) {
|
||||
|
||||
if ( isset( $args['search'] ) && $args['search'] == 1 && isset( $args['must_search'] ) && $args['must_search'] == 1 && !isset( $_REQUEST['um_search'] ) )
|
||||
return;
|
||||
|
||||
|
||||
if ( um_members('total_pages') > 1 ) { // needs pagination
|
||||
|
||||
|
||||
?>
|
||||
|
||||
<div class="um-members-pagidrop uimob340-show uimob500-show">
|
||||
|
||||
|
||||
<div class="um-members-pagidrop uimob340-show uimob500-show">
|
||||
|
||||
<?php _e('Jump to page:','ultimate-member'); ?>
|
||||
|
||||
|
||||
<?php if ( um_members('pages_to_show') && is_array( um_members('pages_to_show') ) ) { ?>
|
||||
<select onChange="window.location.href=this.value" class="um-s2" style="width: 100px">
|
||||
<select onChange="window.location.href=this.value" class="um-s2" style="width: 100px">
|
||||
<?php foreach( um_members('pages_to_show') as $i ) { ?>
|
||||
<option value="<?php echo UM()->permalinks()->add_query( 'members_page', $i ); ?>" <?php selected($i, um_members('page')); ?>><?php printf(__('%s of %d','ultimate-member'), $i, um_members('total_pages') ); ?></option>
|
||||
<option value="<?php echo UM()->permalinks()->add_query( 'members_page', $i ); ?>" <?php selected($i, um_members('page')); ?>><?php printf(__('%s of %d','ultimate-member'), $i, um_members('total_pages') ); ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</select>
|
||||
<?php } ?>
|
||||
|
||||
</div>
|
||||
|
||||
<div class="um-members-pagi uimob340-hide uimob500-hide">
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<div class="um-members-pagi uimob340-hide uimob500-hide">
|
||||
|
||||
<?php if ( um_members('page') != 1 ) { ?>
|
||||
<a href="<?php echo UM()->permalinks()->add_query( 'members_page', 1 ); ?>" class="pagi pagi-arrow um-tip-n" title="<?php _e('First Page','ultimate-member'); ?>"><i class="um-faicon-angle-double-left"></i></a>
|
||||
<a href="<?php echo UM()->permalinks()->add_query( 'members_page', 1 ); ?>" class="pagi pagi-arrow um-tip-n" title="<?php _e('First Page','ultimate-member'); ?>"><i class="um-faicon-angle-double-left"></i></a>
|
||||
<?php } else { ?>
|
||||
<span class="pagi pagi-arrow disabled"><i class="um-faicon-angle-double-left"></i></span>
|
||||
<span class="pagi pagi-arrow disabled"><i class="um-faicon-angle-double-left"></i></span>
|
||||
<?php } ?>
|
||||
|
||||
|
||||
<?php if ( um_members('page') > 1 ) { ?>
|
||||
<a href="<?php echo UM()->permalinks()->add_query( 'members_page', um_members('page') - 1 ); ?>" class="pagi pagi-arrow um-tip-n" title="<?php _e('Previous','ultimate-member'); ?>"><i class="um-faicon-angle-left"></i></a>
|
||||
<a href="<?php echo UM()->permalinks()->add_query( 'members_page', um_members('page') - 1 ); ?>" class="pagi pagi-arrow um-tip-n" title="<?php _e('Previous','ultimate-member'); ?>"><i class="um-faicon-angle-left"></i></a>
|
||||
<?php } else { ?>
|
||||
<span class="pagi pagi-arrow disabled"><i class="um-faicon-angle-left"></i></span>
|
||||
<span class="pagi pagi-arrow disabled"><i class="um-faicon-angle-left"></i></span>
|
||||
<?php } ?>
|
||||
|
||||
|
||||
<?php if ( um_members('pages_to_show') && is_array( um_members('pages_to_show') ) ) { ?>
|
||||
<?php foreach( um_members('pages_to_show') as $i ) { ?>
|
||||
|
||||
|
||||
<?php if ( um_members('page') == $i ) { ?>
|
||||
<span class="pagi current"><?php echo $i; ?></span>
|
||||
<span class="pagi current"><?php echo $i; ?></span>
|
||||
<?php } else { ?>
|
||||
|
||||
<a href="<?php echo UM()->permalinks()->add_query( 'members_page', $i ); ?>" class="pagi"><?php echo $i; ?></a>
|
||||
|
||||
|
||||
<a href="<?php echo UM()->permalinks()->add_query( 'members_page', $i ); ?>" class="pagi"><?php echo $i; ?></a>
|
||||
|
||||
<?php } ?>
|
||||
|
||||
|
||||
<?php } ?>
|
||||
<?php } ?>
|
||||
|
||||
|
||||
<?php if ( um_members('page') != um_members('total_pages') ) { ?>
|
||||
<a href="<?php echo UM()->permalinks()->add_query( 'members_page', um_members('page') + 1 ); ?>" class="pagi pagi-arrow um-tip-n" title="<?php _e('Next','ultimate-member'); ?>"><i class="um-faicon-angle-right"></i></a>
|
||||
<a href="<?php echo UM()->permalinks()->add_query( 'members_page', um_members('page') + 1 ); ?>" class="pagi pagi-arrow um-tip-n" title="<?php _e('Next','ultimate-member'); ?>"><i class="um-faicon-angle-right"></i></a>
|
||||
<?php } else { ?>
|
||||
<span class="pagi pagi-arrow disabled"><i class="um-faicon-angle-right"></i></span>
|
||||
<span class="pagi pagi-arrow disabled"><i class="um-faicon-angle-right"></i></span>
|
||||
<?php } ?>
|
||||
|
||||
|
||||
<?php if ( um_members('page') != um_members('total_pages') ) { ?>
|
||||
<a href="<?php echo UM()->permalinks()->add_query( 'members_page', um_members('total_pages') ); ?>" class="pagi pagi-arrow um-tip-n" title="<?php _e('Last Page','ultimate-member'); ?>"><i class="um-faicon-angle-double-right"></i></a>
|
||||
<a href="<?php echo UM()->permalinks()->add_query( 'members_page', um_members('total_pages') ); ?>" class="pagi pagi-arrow um-tip-n" title="<?php _e('Last Page','ultimate-member'); ?>"><i class="um-faicon-angle-double-right"></i></a>
|
||||
<?php } else { ?>
|
||||
<span class="pagi pagi-arrow disabled"><i class="um-faicon-angle-double-right"></i></span>
|
||||
<span class="pagi pagi-arrow disabled"><i class="um-faicon-angle-double-right"></i></span>
|
||||
<?php } ?>
|
||||
|
||||
</div>
|
||||
|
||||
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
add_action( 'um_members_directory_footer', 'um_members_directory_pagination' );
|
||||
|
||||
@@ -224,30 +223,30 @@ add_action( 'um_members_directory_footer', 'um_members_directory_pagination' );
|
||||
*/
|
||||
function um_members_directory_display( $args ) {
|
||||
extract( $args );
|
||||
|
||||
|
||||
if ( isset( $args['search'] ) && $args['search'] == 1 && isset( $args['must_search'] ) && $args['must_search'] == 1 && !isset( $_REQUEST['um_search'] ) )
|
||||
return;
|
||||
|
||||
if ( um_members('no_users') ) {
|
||||
|
||||
|
||||
if ( um_members('no_users') ) {
|
||||
|
||||
?>
|
||||
|
||||
<div class="um-members-none">
|
||||
<p><?php echo $args['no_users']; ?></p>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="um-members-none">
|
||||
<p><?php echo $args['no_users']; ?></p>
|
||||
</div>
|
||||
|
||||
<?php
|
||||
|
||||
}
|
||||
|
||||
$file = um_path . 'templates/members-grid.php';
|
||||
$theme_file = get_stylesheet_directory() . '/ultimate-member/templates/members-grid.php';
|
||||
|
||||
if ( file_exists( $theme_file ) ){
|
||||
$file = $theme_file;
|
||||
}
|
||||
|
||||
include $file;
|
||||
|
||||
}
|
||||
|
||||
$file = um_path . 'templates/members-grid.php';
|
||||
$theme_file = get_stylesheet_directory() . '/ultimate-member/templates/members-grid.php';
|
||||
|
||||
if ( file_exists( $theme_file ) ){
|
||||
$file = $theme_file;
|
||||
}
|
||||
|
||||
include $file;
|
||||
|
||||
}
|
||||
add_action( 'um_members_directory_display', 'um_members_directory_display' );
|
||||
Reference in New Issue
Block a user