Making WordPress.org

Changeset 1592


Ignore:
Timestamp:
05/18/2015 05:48:17 PM (10 years ago)
Author:
obenland
Message:

WP.org Themes: Extend repopackage searches in wp-admin to include theme slugs.

File:
1 edited

Legend:

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

    r1473 r1592  
    4848}
    4949add_action( 'init', 'wporg_themes_post_status' );
     50
     51/**
     52 * Extends repopackage searches in wp-admin to include theme slugs.
     53 *
     54 * @param string   $search   Search SQL for WHERE clause.
     55 * @param WP_Query $wp_query The current WP_Query object.
     56 * @return string
     57 */
     58function wporg_themes_search_slug( $search, $wp_query ) {
     59    if ( ! is_admin() || 'repopackage' !== $wp_query->query_vars['post_type'] ) {
     60        return $search;
     61    }
     62
     63    global $wpdb;
     64    $n = empty( $wp_query->query_vars['exact'] ) ? '%' : '';
     65    $search = $searchand = '';
     66
     67    foreach ( $wp_query->query_vars['search_terms'] as $term ) {
     68        $like    = $n . $wpdb->esc_like( $term ) . $n;
     69        $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 );
     70        $searchand = ' AND ';
     71    }
     72
     73    if ( ! empty( $search ) ) {
     74        $search = " AND ({$search}) ";
     75        if ( ! is_user_logged_in() ) {
     76            $search .= " AND ($wpdb->posts.post_password = '') ";
     77        }
     78    }
     79
     80    return $search;
     81}
     82add_filter( 'posts_search', 'wporg_themes_search_slug', 10, 2 );
    5083
    5184/**
Note: See TracChangeset for help on using the changeset viewer.