Making WordPress.org

Changeset 7827


Ignore:
Timestamp:
11/05/2018 11:06:19 PM (6 years ago)
Author:
coffee2code
Message:

Developer: Rerun empty searches where the search term contains characters that can be converted to HTML entities, but with such characters converted.

Fixes #3019.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-developer/inc/search.php

    r7319 r7827  
    2424        add_action( 'pre_get_posts', array( __CLASS__, 'pre_get_posts' ), 20 );
    2525        add_filter( 'posts_orderby', array( __CLASS__, 'search_posts_orderby' ), 10, 2 );
    26         add_filter( 'the_posts',     array( __CLASS__, 'rerun_empty_exact_search' ), 10, 2 );
     26        add_filter( 'the_posts',     array( __CLASS__, 'rerun_empty_search' ), 10, 2 );
    2727    }
    2828
     
    169169
    170170    /**
    171      * Rerun an exact search with the same criteria except exactness if no posts
    172      * were found.
     171     * Potentially rerun a search if no posts were found.
     172     *
     173     * Situations:
     174     * - For an exact search, try again with the same criteria but without exactness
     175     * - For a search containing characters that can be converted to HTML entities,
     176     * , try again after converting those characters
    173177     *
    174178     * @access public
     
    178182     * @return array
    179183     */
    180     public static function rerun_empty_exact_search( $posts, $query ) {
    181         if ( is_search() && true === $query->get( 'exact' ) && ! $query->found_posts ) {
    182             $query->set( 'exact', false );
    183             $posts = $query->get_posts();
     184    public static function rerun_empty_search( $posts, $query ) {
     185        if ( is_search() && ! $query->found_posts ) {
     186            $s = $query->get( 's' );
     187
     188            // Return exact search without exactness.
     189            if ( true === $query->get( 'exact' ) ) {
     190                $query->set( 'exact', false );
     191                $posts = $query->get_posts();
     192            }
     193           
     194            // Retry HTML entity convertible search term after such a conversion.
     195            elseif ( $s != ( $she = htmlentities( $s ) ) ) {
     196                $query->set( 's', $she );
     197                $posts = $query->get_posts();
     198            }
    184199        }
    185200
Note: See TracChangeset for help on using the changeset viewer.