WordPress.org

Making WordPress.org

Changeset 1884


Ignore:
Timestamp:
09/17/2015 06:46:55 AM (4 years ago)
Author:
dd32
Message:

Themes Directory: Allow searches to match on theme slug in addition to tags, content, and title.
Fixes #1021

Location:
sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/admin-edit.php

    r1767 r1884  
    4646}
    4747add_action( 'init', 'wporg_themes_post_status' );
    48 
    49 /**
    50  * Extends repopackage searches in wp-admin to include theme slugs.
    51  *
    52  * @param string   $search   Search SQL for WHERE clause.
    53  * @param WP_Query $wp_query The current WP_Query object.
    54  * @return string
    55  */
    56 function wporg_themes_search_slug( $search, $wp_query ) {
    57     if ( empty( $search ) || ! is_admin() || 'repopackage' !== $wp_query->query_vars['post_type'] || ! $wp_query->is_search() ) {
    58         return $search;
    59     }
    60 
    61     global $wpdb;
    62     $n = empty( $wp_query->query_vars['exact'] ) ? '%' : '';
    63     $search = $searchand = '';
    64 
    65     foreach ( $wp_query->query_vars['search_terms'] as $term ) {
    66         $like    = $n . $wpdb->esc_like( $term ) . $n;
    67         $search .= $wpdb->prepare( "{$searchand}(($wpdb->posts.post_title LIKE %s) OR ($wpdb->posts.post_name LIKE %s) OR ($wpdb->posts.post_content LIKE %s))", $like, $like, $like );
    68         $searchand = ' AND ';
    69     }
    70 
    71     if ( ! empty( $search ) ) {
    72         $search = " AND ({$search}) ";
    73         if ( ! is_user_logged_in() ) {
    74             $search .= " AND ($wpdb->posts.post_password = '') ";
    75         }
    76     }
    77 
    78     return $search;
    79 }
    80 add_filter( 'posts_search', 'wporg_themes_search_slug', 10, 2 );
    8148
    8249/**
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/theme-directory/theme-directory.php

    r1845 r1884  
    687687}
    688688
     689/**
     690 * Extends repopackage searches to include theme slugs.
     691 *
     692 * @param string   $search   Search SQL for WHERE clause.
     693 * @param WP_Query $wp_query The current WP_Query object.
     694 * @return string
     695 */
     696function wporg_themes_search_slug( $search, $wp_query ) {
     697    if ( empty( $search ) || 'repopackage' !== $wp_query->query_vars['post_type'] || ! $wp_query->is_search() ) {
     698        return $search;
     699    }
     700
     701    global $wpdb;
     702    $n = empty( $wp_query->query_vars['exact'] ) ? '%' : '';
     703    $search = $searchand = '';
     704
     705    foreach ( $wp_query->query_vars['search_terms'] as $term ) {
     706        $like    = $n . $wpdb->esc_like( $term ) . $n;
     707        $search .= $wpdb->prepare( "{$searchand}(($wpdb->posts.post_title LIKE %s) OR ($wpdb->posts.post_name LIKE %s) OR ($wpdb->posts.post_content LIKE %s))", $like, $like, $like );
     708        $searchand = ' AND ';
     709    }
     710
     711    if ( ! empty( $search ) ) {
     712        $search = " AND ({$search}) ";
     713        if ( ! is_user_logged_in() ) {
     714            $search .= " AND ($wpdb->posts.post_password = '') ";
     715        }
     716    }
     717
     718    return $search;
     719}
     720add_filter( 'posts_search', 'wporg_themes_search_slug', 10, 2 );
    689721
    690722/**
Note: See TracChangeset for help on using the changeset viewer.