Making WordPress.org


Ignore:
Timestamp:
07/01/2021 12:19:51 AM (4 years ago)
Author:
dd32
Message:

Support Forums: Revert to using the global WordPress.org/search system rather than using bbPress/WordPress search.

Reverts [11025], [11026], [11027].
See #5771.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-performance-optimizations.php

    r11027 r11083  
    3232
    3333        // Redirect search results.
    34         add_action( 'bbp_template_redirect', array( $this, 'redirect_search_results' ) );
    35         add_filter( 'pre_get_posts', array( $this, 'search_alterations' ) );
    36         add_filter( 'pre_get_posts', array( $this, 'search_forum_alterations' ) );
    37         add_filter( 'bbp_after_has_search_results_parse_args', array( $this, 'search_forum_alteration_args' ) );
     34        add_action( 'bbp_template_redirect', array( $this, 'redirect_search_results_to_google_search' ) );
    3835
    3936        // Redirect (.+)/page/[01]/ and (.+)?paged=[01] to $1
     
    8077
    8178    /**
    82      * Redirects search results to appropriate place.
    83      */
    84     public function redirect_search_results() {
    85         if ( ! is_search() ) {
     79     * Redirects search results to Google Custom Search.
     80     */
     81    public function redirect_search_results_to_google_search() {
     82        $is_wp_search  = is_search();
     83        $is_bbp_search = bbp_is_search_results();
     84
     85        if ( ! $is_wp_search && ! $is_bbp_search ) {
    8686            return;
    8787        }
     
    9191        }
    9292
    93         $search_terms = get_search_query( false );
    94 
    95         $tab = $_GET['tab'] ?? 'support';
    96         if ( ! in_array( $tab, [ 'support', 'docs', 'plugin', 'theme', 'searchforum' ] ) ) {
    97             $tab = 'support';
    98         }
    99 
    100         switch ( $tab ) {
    101             case 'theme':
    102             case 'plugin':
    103             case 'searchforum':
    104                 wp_safe_redirect( add_query_arg( $tab, $_GET[ $tab ], home_url( "/search/{$search_terms}/" ) ) );
    105                 exit;
    106             case 'support':
    107                 wp_safe_redirect( home_url( "/search/{$search_terms}/" ) );
    108                 exit;
    109             case 'docs':
    110                 // Do nothing.
    111         }
    112     }
    113 
    114     /**
    115      * Search alterations for forums.
    116      */
    117     public function search_alterations( $query ) {
    118         if ( ! is_search() || ! $query->is_search() ) {
    119             return;
    120         }
    121 
    122         $query->set( 'post_type', [ 'page', 'helphub_article' ] );
    123 
    124     }
    125 
    126     public function search_forum_alterations( $query ) {
    127         if ( empty( $query->query['_bbp_search_query'] ) ) {
    128             return;
    129         }
    130 
    131         // Limit searches to published topics.
    132         $query->set( 'post_type', 'topic' );
    133         $query->set( 'post_status', 'publish' );
    134 
    135         // Limit to either the plugin/theme in question, or to general support threads.
    136         if ( !empty( $_GET['plugin'] ) ) {
    137             $query->set( 'tax_query', [
    138                 [
    139                     'taxonomy' => 'topic-plugin',
    140                     'field' => 'slug',
    141                     'terms' => [ $_GET['plugin'] ]
    142                 ]
    143             ] );
    144 
    145             add_filter( 'posts_where', array( $this, 'posts_in_last_year' ) );
    146         } elseif ( ! empty( $_GET['theme'] ) ) {
    147             $query->set( 'tax_query', [
    148                 [
    149                     'taxonomy' => 'topic-theme',
    150                     'field' => 'slug',
    151                     'terms' => [ $_GET['theme'] ]
    152                 ]
    153             ] );
    154 
    155             add_filter( 'posts_where', array( $this, 'posts_in_last_year' ) );
    156         } elseif ( ! empty( $_GET['searchforum'] ) ) {
    157             $query->set( 'post_parent', (int) $_GET['searchforum'] );
    158 
    159             add_filter( 'posts_where', array( $this, 'posts_in_last_year' ) );
    160         } else {
    161             $query->set( 'post_parent__not_in', [21261, 21262, 21272] ); // Magic numbers: Plugins, Themes, Reviews
    162 
    163             add_filter( 'posts_where', array( $this, 'posts_in_last_six_months' ) );
    164         }
    165     }
    166 
    167     public function search_forum_alteration_args( $args ) {
    168         $args['_bbp_search_query'] = true;
    169 
    170         return $args;
     93        $search_terms = $search_url = '';
     94
     95        if ( $is_bbp_search ) {
     96            $search_terms = bbp_get_search_terms();
     97        } elseif ( $is_wp_search ) {
     98            $search_terms = get_search_query( false );
     99        }
     100
     101        if ( isset( $_GET['intext'] ) ) {
     102            $search_terms .= ' intext:"' . esc_attr( $_GET['intext'] ) . '"';
     103        }
     104
     105        if ( $search_terms ) {
     106            $tab = ! empty( $_GET['tab'] ) && 'docs' === $_GET['tab'] ? 'docs' : 'forums';
     107            $search_url = sprintf( "https://wordpress.org/search/%s/?{$tab}=1", urlencode( $search_terms ) );
     108            $search_url = esc_url_raw( $search_url );
     109        }
     110
     111        if ( ! $search_url ) {
     112            wp_safe_redirect( home_url( '/' ) );
     113            exit;
     114        }
     115
     116        wp_safe_redirect( $search_url );
     117        exit;
    171118    }
    172119
Note: See TracChangeset for help on using the changeset viewer.