mirror of
git://develop.git.wordpress.org/
synced 2025-02-27 10:02:43 +01:00
Move _wp_search_sql() into WP_Object_Query. Introduce WP_Comment_Search. See #15032
git-svn-id: https://develop.svn.wordpress.org/trunk@15723 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
4360f8c1a4
commit
12fdf54fdd
@ -546,7 +546,7 @@ class WP_Object_Query {
|
||||
/*
|
||||
* Populates the $meta_query property
|
||||
*
|
||||
* @access private
|
||||
* @access protected
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @param array $qv The query variables
|
||||
@ -570,7 +570,7 @@ class WP_Object_Query {
|
||||
/*
|
||||
* Used internally to generate an SQL string for searching across multiple meta key = value pairs
|
||||
*
|
||||
* @access private
|
||||
* @access protected
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @param string $primary_table
|
||||
@ -621,6 +621,26 @@ class WP_Object_Query {
|
||||
|
||||
return array( $join, $where );
|
||||
}
|
||||
|
||||
/*
|
||||
* 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) . ')';
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -188,6 +188,13 @@ function &get_comment(&$comment, $output = OBJECT) {
|
||||
* @return array List of comments.
|
||||
*/
|
||||
function get_comments( $args = '' ) {
|
||||
$query = new WP_Comment_Query;
|
||||
return $query->query( $args );
|
||||
}
|
||||
|
||||
class WP_Comment_Query extends WP_Object_Query {
|
||||
|
||||
function query( $args ) {
|
||||
global $wpdb;
|
||||
|
||||
$defaults = array(
|
||||
@ -295,7 +302,7 @@ function get_comments( $args = '' ) {
|
||||
if ( '' !== $user_id )
|
||||
$post_where .= $wpdb->prepare( ' AND user_id = %d', $user_id );
|
||||
if ( '' !== $search )
|
||||
$post_where .= _wp_search_sql($search, array('comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content'));
|
||||
$post_where .= $this->get_search_sql( $search, array( 'comment_author', 'comment_author_email', 'comment_author_url', 'comment_author_IP', 'comment_content' ) );
|
||||
|
||||
if ( $count )
|
||||
return $wpdb->get_var( "SELECT COUNT(*) FROM $wpdb->comments $post_where ORDER BY $orderby $order $limit" );
|
||||
@ -305,6 +312,7 @@ function get_comments( $args = '' ) {
|
||||
wp_cache_add( $cache_key, $comments, 'comment' );
|
||||
|
||||
return $comments;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -4236,26 +4236,6 @@ function get_file_data( $file, $default_headers, $context = '' ) {
|
||||
return $file_data;
|
||||
}
|
||||
|
||||
/*
|
||||
* Used internally to generate an SQL string for searching across multiple columns
|
||||
*
|
||||
* @access private
|
||||
* @since 3.1.0
|
||||
*
|
||||
* @param string $string
|
||||
* @param array $cols
|
||||
* @return string
|
||||
*/
|
||||
function _wp_search_sql($string, $cols) {
|
||||
$string = esc_sql($string);
|
||||
|
||||
$searches = array();
|
||||
foreach ( $cols as $col )
|
||||
$searches[] = "$col LIKE '%$string%'";
|
||||
|
||||
return ' AND (' . implode(' OR ', $searches) . ')';
|
||||
}
|
||||
|
||||
/*
|
||||
* Used internally to tidy up the search terms
|
||||
*
|
||||
|
@ -441,7 +441,7 @@ class WP_User_Query extends WP_Object_Query {
|
||||
|
||||
$search = trim( $qv['search'] );
|
||||
if ( $search ) {
|
||||
$this->query_where .= _wp_search_sql( $search, array('user_login', 'user_nicename', 'user_email', 'user_url', 'display_name') );
|
||||
$this->query_where .= $this->get_search_sql( $search, array( 'user_login', 'user_nicename', 'user_email', 'user_url', 'display_name' ) );
|
||||
}
|
||||
|
||||
$this->parse_meta_query( $qv );
|
||||
|
Loading…
x
Reference in New Issue
Block a user