mirror of
https://github.com/WordPress/WordPress.git
synced 2025-03-09 07:00:01 +00:00
Default to leading and trailing wildcards for site user searches. Require explicit trailing wildcard asterisk request for network user searches. Disallow leading wildcards for network user searches. Move wildcard policy up the stake, allowing more flexibility in WP_User_Query. Props SergeyBiryukov. fixes #16014
git-svn-id: http://svn.automattic.com/wordpress/trunk@17189 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
parent
138c0ff862
commit
b6346ae5cd
@ -31,6 +31,8 @@ class WP_MS_Users_List_Table extends WP_List_Table {
|
||||
'fields' => 'all_with_meta'
|
||||
);
|
||||
|
||||
$args['search'] = ltrim($args['search'], '*');
|
||||
|
||||
if ( $role == 'super' ) {
|
||||
$logins = implode( "', '", get_super_admins() );
|
||||
$args['include'] = $wpdb->get_col( "SELECT ID FROM $wpdb->users WHERE user_login IN ('$logins')" );
|
||||
|
@ -51,6 +51,8 @@ class WP_Users_List_Table extends WP_List_Table {
|
||||
'fields' => 'all_with_meta'
|
||||
);
|
||||
|
||||
$args['search'] = '*' . $args['search'] . '*';
|
||||
|
||||
if ( $this->is_site_users )
|
||||
$args['blog_id'] = $this->site_id;
|
||||
|
||||
|
@ -465,11 +465,19 @@ class WP_User_Query {
|
||||
|
||||
$search = trim( $qv['search'] );
|
||||
if ( $search ) {
|
||||
$wild = false;
|
||||
if ( false !== strpos($search, '*') ) {
|
||||
$wild = true;
|
||||
$leading_wild = ( ltrim($search, '*') != $search );
|
||||
$trailing_wild = ( rtrim($search, '*') != $search );
|
||||
if ( $leading_wild && $trailing_wild )
|
||||
$wild = 'both';
|
||||
elseif ( $leading_wild )
|
||||
$wild = 'leading';
|
||||
elseif ( $trailing_wild )
|
||||
$wild = 'trailing';
|
||||
else
|
||||
$wild = false;
|
||||
if ( $wild )
|
||||
$search = trim($search, '*');
|
||||
}
|
||||
|
||||
if ( false !== strpos( $search, '@') )
|
||||
$search_columns = array('user_email');
|
||||
elseif ( is_numeric($search) )
|
||||
@ -564,19 +572,21 @@ class WP_User_Query {
|
||||
*
|
||||
* @param string $string
|
||||
* @param array $cols
|
||||
* @param bool $wild Whether to allow trailing wildcard searches. Default is false.
|
||||
* @param bool $wild Whether to allow wildcard searches. Default is false for Network Admin, true for
|
||||
* single site. Single site allows leading and trailing wildcards, Network Admin only trailing.
|
||||
* @return string
|
||||
*/
|
||||
function get_search_sql( $string, $cols, $wild = false ) {
|
||||
$string = esc_sql( $string );
|
||||
|
||||
$searches = array();
|
||||
$wild_char = ( $wild ) ? '%' : '';
|
||||
$leading_wild = ( 'leading' == $wild || 'both' == $wild ) ? '%' : '';
|
||||
$trailing_wild = ( 'trailing' == $wild || 'both' == $wild ) ? '%' : '';
|
||||
foreach ( $cols as $col ) {
|
||||
if ( 'ID' == $col )
|
||||
$searches[] = "$col = '$string'";
|
||||
else
|
||||
$searches[] = "$col LIKE '" . like_escape($string) . "$wild_char'";
|
||||
$searches[] = "$col LIKE '$leading_wild" . like_escape($string) . "$trailing_wild'";
|
||||
}
|
||||
|
||||
return ' AND (' . implode(' OR ', $searches) . ')';
|
||||
|
Loading…
x
Reference in New Issue
Block a user