mirror of
https://github.com/10h30/ultimatemember.git
synced 2026-06-05 15:09:37 +09:00
Fix searching with space
This commit is contained in:
+51
-51
@@ -1,5 +1,5 @@
|
||||
<?php
|
||||
|
||||
|
||||
/***
|
||||
*** @Members Filter Hooks
|
||||
***/
|
||||
@@ -7,41 +7,41 @@
|
||||
add_filter('um_prepare_user_query_args', 'um_add_search_to_query', 50, 2);
|
||||
add_filter('um_prepare_user_query_args', 'um_search_usernames_emails', 51, 2);
|
||||
add_filter('um_prepare_user_query_args', 'um_remove_special_users_from_list', 99, 2);
|
||||
|
||||
|
||||
/***
|
||||
*** @WP API user search
|
||||
***/
|
||||
function um_search_usernames_emails( $query_args, $args ) {
|
||||
global $ultimatemember;
|
||||
extract( $args );
|
||||
|
||||
|
||||
$query = $ultimatemember->permalinks->get_query_array();
|
||||
|
||||
|
||||
foreach( $ultimatemember->members->core_search_fields as $key ) {
|
||||
if ( isset( $query[$key] ) ) {
|
||||
$query_args['search'] = '*' . $query[$key] . '*';
|
||||
$query_args['search'] = '*' . trim($query[$key]) . '*';
|
||||
}
|
||||
}
|
||||
return $query_args;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
*** @Remove users we do not need to show in directory
|
||||
***/
|
||||
function um_remove_special_users_from_list( $query_args, $args ) {
|
||||
global $ultimatemember;
|
||||
extract( $args );
|
||||
|
||||
|
||||
if ( !um_user_can('can_edit_everyone') ) {
|
||||
|
||||
|
||||
$query_args['meta_query'][] = array(
|
||||
'key' => 'account_status',
|
||||
'value' => 'approved',
|
||||
'compare' => '='
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
$query_args['meta_query'][] = array(
|
||||
'key' => 'hide_in_members',
|
||||
'value' => '',
|
||||
@@ -50,23 +50,23 @@
|
||||
|
||||
return $query_args;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
*** @adds search parameters
|
||||
***/
|
||||
function um_add_search_to_query( $query_args, $args ){
|
||||
global $ultimatemember;
|
||||
extract( $args );
|
||||
|
||||
|
||||
if ( isset( $_REQUEST['um_search'] ) ) {
|
||||
|
||||
|
||||
$query = $ultimatemember->permalinks->get_query_array();
|
||||
|
||||
if ( $query && is_array( $query ) ) {
|
||||
foreach( $query as $field => $value ) {
|
||||
|
||||
if(in_array($field, array('members_page'))) continue;
|
||||
|
||||
|
||||
if ( in_array( $field, array('gender') ) ) {
|
||||
$operator = '=';
|
||||
} else {
|
||||
@@ -78,53 +78,53 @@
|
||||
}
|
||||
|
||||
if ( $value && $field != 'um_search' && $field != 'page_id' ) {
|
||||
|
||||
|
||||
if ( !in_array( $field, $ultimatemember->members->core_search_fields ) ) {
|
||||
|
||||
|
||||
if ( strstr($field, 'role_' ) ) {
|
||||
$field = 'role';
|
||||
$operator = '=';
|
||||
}
|
||||
|
||||
|
||||
$query_args['meta_query'][] = array(
|
||||
'key' => $field,
|
||||
'value' => $value,
|
||||
'value' => trim($value),
|
||||
'compare' => $operator,
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
// allow filtering
|
||||
$query_args = apply_filters('um_query_args_filter', $query_args );
|
||||
|
||||
|
||||
if ( count ($query_args['meta_query']) == 1 ) {
|
||||
unset( $query_args['meta_query'] );
|
||||
}
|
||||
|
||||
return $query_args;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
*** @adds main parameters
|
||||
***/
|
||||
function um_prepare_user_query_args($query_args, $args){
|
||||
global $ultimatemember;
|
||||
extract( $args );
|
||||
|
||||
|
||||
$query_args['fields'] = 'ID';
|
||||
|
||||
|
||||
$query_args['number'] = 0;
|
||||
|
||||
|
||||
$query_args['meta_query']['relation'] = 'AND';
|
||||
|
||||
|
||||
// must have a profile photo
|
||||
if ( $has_profile_photo == 1 ) {
|
||||
$query_args['meta_query'][] = array(
|
||||
@@ -133,7 +133,7 @@
|
||||
'compare' => '!='
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// must have a cover photo
|
||||
if ( $has_cover_photo == 1 ) {
|
||||
$query_args['meta_query'][] = array(
|
||||
@@ -142,7 +142,7 @@
|
||||
'compare' => '!='
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
// show specific usernames
|
||||
if ( isset( $show_these_users ) && $show_these_users && is_array( $show_these_users ) ) {
|
||||
foreach( $show_these_users as $username ) {
|
||||
@@ -150,52 +150,52 @@
|
||||
}
|
||||
$query_args['include'] = $users_array;
|
||||
}
|
||||
|
||||
// add roles to appear in directory
|
||||
|
||||
// add roles to appear in directory
|
||||
if ( !empty( $roles ) ) {
|
||||
|
||||
|
||||
$query_args['meta_query'][] = array(
|
||||
'key' => 'role',
|
||||
'value' => $roles,
|
||||
'compare' => 'IN'
|
||||
);
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
// sort members by
|
||||
$query_args['order'] = 'ASC';
|
||||
|
||||
|
||||
if ( isset( $sortby ) ) {
|
||||
|
||||
|
||||
if ( $sortby == 'other' && $sortby_custom ) {
|
||||
|
||||
|
||||
$query_args['meta_key'] = $sortby_custom;
|
||||
$query_args['orderby'] = 'meta_value, display_name';
|
||||
|
||||
|
||||
} else if ( in_array( $sortby, array( 'last_name', 'first_name' ) ) ) {
|
||||
|
||||
|
||||
$query_args['meta_key'] = $sortby;
|
||||
$query_args['orderby'] = 'meta_value';
|
||||
|
||||
|
||||
} else {
|
||||
|
||||
|
||||
if ( strstr( $sortby, '_desc' ) ) {$sortby = str_replace('_desc','',$sortby);$order = 'DESC';}
|
||||
if ( strstr( $sortby, '_asc' ) ) {$sortby = str_replace('_asc','',$sortby);$order = 'ASC';}
|
||||
$query_args['orderby'] = $sortby;
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
if ( isset( $order ) ) {
|
||||
$query_args['order'] = $order;
|
||||
}
|
||||
|
||||
|
||||
$query_args = apply_filters('um_modify_sortby_parameter', $query_args, $sortby);
|
||||
|
||||
}
|
||||
|
||||
|
||||
return $query_args;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
*** @sorting by last login date
|
||||
***/
|
||||
@@ -208,7 +208,7 @@
|
||||
}
|
||||
return $query_args;
|
||||
}
|
||||
|
||||
|
||||
/***
|
||||
*** @hook in the member results array
|
||||
***/
|
||||
@@ -220,6 +220,6 @@
|
||||
} else {
|
||||
$result['no_users'] = 0;
|
||||
}
|
||||
|
||||
|
||||
return $result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user