Make WordPress Core


Ignore:
Timestamp:
06/16/2016 11:08:30 PM (7 years ago)
Author:
jeremyfelt
Message:

Multisite: Add search column support to WP_Site_Query.

domain and/or path can be used to specify which column(s) should be searched.

See #35791.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/class-wp-site-query.php

    r37477 r37735  
    142142     *     @type int          $deleted           Limit results to deleted sites. Accepts '1' or '0'. Default empty.
    143143     *     @type string       $search            Search term(s) to retrieve matching sites for. Default empty.
     144     *     @type array        $search_columns    Array of column names to be searched. Accepts 'domain' and 'path'.
     145     *                                           Default empty array.
    144146     *     @type bool         $update_site_cache Whether to prime the cache for found sites. Default false.
    145147     * }
     
    171173            'deleted'           => null,
    172174            'search'            => '',
     175            'search_columns'    => array(),
    173176            'count'             => false,
    174177            'date_query'        => null, // See WP_Date_Query
     
    482485        // Falsey search strings are ignored.
    483486        if ( strlen( $this->query_vars['search'] ) ) {
    484             $this->sql_clauses['where']['search'] = $this->get_search_sql(
    485                 $this->query_vars['search'],
    486                 array( 'domain', 'path' )
    487             );
     487            $search_columns = array();
     488
     489            if ( $this->query_vars['search_columns'] ) {
     490                $search_columns = array_intersect( $this->query_vars['search_columns'], array( 'domain', 'path' ) );
     491            }
     492
     493            if ( ! $search_columns ) {
     494                $search_columns = array( 'domain', 'path' );
     495            }
     496
     497            /**
     498             * Filters the columns to search in a WP_Site_Query search.
     499             *
     500             * The default columns include 'domain' and 'path.
     501             *
     502             * @since 4.6.0
     503             *
     504             * @param array         $search_columns Array of column names to be searched.
     505             * @param string        $search         Text being searched.
     506             * @param WP_Site_Query $this           The current WP_Site_Query instance.
     507             */
     508            $search_columns = apply_filters( 'site_search_columns', $search_columns, $this->query_vars['search'], $this );
     509
     510            $this->sql_clauses['where']['search'] = $this->get_search_sql( $this->query_vars['search'], $search_columns );
    488511        }
    489512
     
    564587        global $wpdb;
    565588
    566         $like = '%' . $wpdb->esc_like( $string ) . '%';
     589        if ( false !== strpos( $string, '*' ) ) {
     590            $like = '%' . implode( '%', array_map( array( $wpdb, 'esc_like' ), explode( '*', $string ) ) ) . '%';
     591        } else {
     592            $like = '%' . $wpdb->esc_like( $string ) . '%';
     593        }
    567594
    568595        $searches = array();
Note: See TracChangeset for help on using the changeset viewer.