WordPress.org

Making WordPress.org


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

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

File:
1 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/**
Note: See TracChangeset for help on using the changeset viewer.