Split get_search_sql(). See #15170. See #15032

git-svn-id: http://svn.automattic.com/wordpress/trunk@16351 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
scribu 2010-11-13 18:18:45 +00:00
parent 2c9faf261b
commit 6267650ddd
3 changed files with 46 additions and 26 deletions

View File

@ -70,32 +70,6 @@ class WP_Object_Query {
$qv['meta_query'] = $meta_query; $qv['meta_query'] = $meta_query;
} }
/*
* Used internally to generate an SQL string for searching across multiple columns
*
* @access protected
* @since 3.1.0
*
* @param string $string
* @param array $cols
* @param bool $wild Whether to allow trailing wildcard searches. Default is false.
* @return string
*/
function get_search_sql( $string, $cols, $wild = false ) {
$string = esc_sql( $string );
$searches = array();
$wild_char = ( $wild ) ? '%' : '';
foreach ( $cols as $col ) {
if ( 'ID' == $col )
$searches[] = "$col = '$string'";
else
$searches[] = "$col LIKE '$string$wild_char'";
}
return ' AND (' . implode(' OR ', $searches) . ')';
}
} }
?> ?>

View File

@ -341,6 +341,26 @@ class WP_Comment_Query extends WP_Object_Query {
return $comments; return $comments;
} }
/*
* Used internally to generate an SQL string for searching across multiple columns
*
* @access protected
* @since 3.1.0
*
* @param string $string
* @param array $cols
* @return string
*/
function get_search_sql( $string, $cols ) {
$string = esc_sql( $string );
$searches = array();
foreach ( $cols as $col )
$searches[] = "$col LIKE '%$string%'";
return ' AND (' . implode(' OR ', $searches) . ')';
}
} }
/** /**

View File

@ -526,6 +526,32 @@ class WP_User_Query extends WP_Object_Query {
} }
} }
/*
* Used internally to generate an SQL string for searching across multiple columns
*
* @access protected
* @since 3.1.0
*
* @param string $string
* @param array $cols
* @param bool $wild Whether to allow trailing wildcard searches. Default is false.
* @return string
*/
function get_search_sql( $string, $cols, $wild = false ) {
$string = esc_sql( $string );
$searches = array();
$wild_char = ( $wild ) ? '%' : '';
foreach ( $cols as $col ) {
if ( 'ID' == $col )
$searches[] = "$col = '$string'";
else
$searches[] = "$col LIKE '$string$wild_char'";
}
return ' AND (' . implode(' OR ', $searches) . ')';
}
/** /**
* Return the list of users * Return the list of users
* *