Making WordPress.org

Changeset 11025


Ignore:
Timestamp:
06/11/2021 05:39:41 AM (3 years ago)
Author:
dd32
Message:

Support: Attempt to use bbPress/WordPress search for support forums.

This is kind of ugly and not perfect, this is just to get it out there.

Searches from Plugin/Theme subforums should be limited to that plugin/theme forum.
Searches for support threads (without plugin/themes) should be limited to not-plugin/theme/review forums.
Searches from homepage or where it says 'Documentation' should be limited to HelpHub articles/Pages.

This is temporary, and as a result, the urls are not super pretty, but should suffice for the immediate need.

SEe #5771.

Location:
sites/trunk/wordpress.org/public_html/wp-content
Files:
3 edited
1 copied

Legend:

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

    r10638 r11025  
    3232
    3333        // Redirect search results.
    34         add_action( 'bbp_template_redirect', array( $this, 'redirect_search_results_to_google_search' ) );
     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' ) );
    3538
    3639        // Redirect (.+)/page/[01]/ and (.+)?paged=[01] to $1
     
    7780
    7881    /**
    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 ) {
     82     * Redirects search results to appropriate place.
     83     */
     84    public function redirect_search_results() {
     85        if ( ! is_search() ) {
    8686            return;
    8787        }
     
    9191        }
    9292
    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;
     93        $search_terms = get_search_query( false );
     94
     95        $tab = $_GET['tab'] ?? 'support';
     96        if ( ! in_array( $tab, [ 'support', 'docs', 'plugin', 'theme' ] ) ) {
     97            $tab = 'support';
     98        }
     99
     100        switch ( $tab ) {
     101            case 'theme':
     102            case 'plugin':
     103                wp_safe_redirect( add_query_arg( $tab, $_GET[ $tab ], home_url( "/search/{$search_terms}/" ) ) );
     104                exit;
     105            case 'support':
     106                wp_safe_redirect( home_url( "/search/{$search_terms}/" ) );
     107                exit;
     108            case 'docs':
     109                // Do nothing.
     110        }
     111    }
     112
     113    /**
     114     * Search alterations for forums.
     115     */
     116    public function search_alterations( $query ) {
     117        if ( ! is_search() || ! $query->is_search() ) {
     118            return;
     119        }
     120
     121        $query->set( 'post_type', [ 'page', 'helphub_article' ] );
     122
     123    }
     124
     125    public function search_forum_alterations( $query ) {
     126        if ( empty( $query->query['_bbp_search_query'] ) ) {
     127            return;
     128        }
     129
     130        // Limit searches to published topics.
     131        $query->set( 'post_type', 'topic' );
     132        $query->set( 'post_status', 'publish' );
     133
     134        // Limit to either the plugin/theme in question, or to general support threads.
     135        if ( !empty( $_GET['plugin'] ) ) {
     136            $query->set( 'tax_query', [
     137                [
     138                    'taxonomy' => 'topic-plugin',
     139                    'field' => 'slug',
     140                    'terms' => [ $_GET['plugin'] ]
     141                ]
     142            ] );
     143
     144            add_filter( 'posts_where', array( $this, 'posts_in_last_year' ) );
     145        } elseif ( ! empty( $_GET['theme'] ) ) {
     146            $query->set( 'tax_query', [
     147                [
     148                    'taxonomy' => 'topic-theme',
     149                    'field' => 'slug',
     150                    'terms' => [ $_GET['theme'] ]
     151                ]
     152            ] );
     153
     154            add_filter( 'posts_where', array( $this, 'posts_in_last_year' ) );
     155        } else {
     156            $query->set( 'post_parent__not_in', [21261, 21262, 21272] ); // Magic numbers: Plugins, Themes, Reviews
     157
     158            add_filter( 'posts_where', array( $this, 'posts_in_last_six_months' ) );
     159        }
     160    }
     161
     162    public function search_forum_alteration_args( $args ) {
     163        $args['_bbp_search_query'] = true;
     164
     165        return $args;
    118166    }
    119167
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/bbpress/loop-search.php

    r7818 r11025  
    99            <?php if ( 'topic' === get_post_type() ) : ?>
    1010
    11                 <?php bbp_get_template_part( 'content', 'single-topic-lead' ); ?>
     11                <?php bbp_get_template_part( 'loop', 'single-topic' ); ?>
    1212
    1313            <?php else : ?>
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/search.php

    r11022 r11025  
    1414    <main id="main" class="site-main" role="main">
    1515
    16         <h1><?php single_cat_title(); ?></h1>
     16        <h1><?php printf( __( 'Search Results for %s' ), esc_html( get_query_var( 's' ) ) ); ?></h1>
    1717
    18         <div class="three-up helphub-front-page">
     18        <div class="search">
    1919            <?php
    2020            while ( have_posts() ) :
     
    2222            ?>
    2323
    24                 <a href="<?php echo esc_url( get_the_permalink() ); ?>" class="archive-block">
    25                     <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
    26                         <?php the_title( '<h2>', '</h2>' ); ?>
     24            <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
     25                <a href="<?php echo esc_url( get_the_permalink() ); ?>" class="archive-block"><?php the_title( '<h2>', '</h2>' ); ?></a>
    2726
    28                         <?php the_excerpt(); ?>
    29                     </article>
    30                 </a>
    31 
     27                <?php the_excerpt(); ?>
     28            </article>
    3229
    3330            <?php endwhile; ?>
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/searchform.php

    r9664 r11025  
    2121            $placeholder = _x( 'Search this forum', 'placeholder', 'wporg-forums' );
    2222            $project     = wporg_support_get_compat_object();
     23            $tab         = $project->type;
     24            $project     = $project->post_name;
    2325        } elseif ( is_front_page() ) {
    2426            $placeholder = _x( 'Search documentation', 'placeholder', 'wporg-forums' );
    2527            $project     = null;
    2628            $tab         = 'docs';
     29        } elseif ( is_search() || bbp_is_search() ) {
     30            if ( isset( $_GET['tab'] ) ) {
     31                $tab     = $_GET['tab'];
     32                $project = $_GET[ $_GET['tab'] ];
     33            }
    2734        } else {
    2835            $placeholder = _x( 'Search forums', 'placeholder', 'wporg-forums' );
    2936            $project     = null;
     37            $tab         = 'support';
    3038        }
    3139    ?>
    32     <input type="search" id="s" class="search-field" placeholder="<?php echo esc_attr( $placeholder ); ?>" value="<?php the_search_query(); ?>" name="s" />
     40    <input type="search" id="s" class="search-field" placeholder="<?php echo esc_attr( $placeholder ); ?>" value="<?php echo esc_attr( get_query_var( 's' ) ?: get_query_var( 'bbp_search' ) ) ?>" name="s" />
    3341    <?php if ( $project ) : ?>
    34     <input type="hidden" name="intext" value="<?php echo esc_attr( $project->prefixed_title ); ?>" />
     42    <input type="hidden" name="<?php echo esc_attr( $tab ); ?>" value="<?php echo esc_attr( $project ); ?>" />
    3543    <?php endif; ?>
    3644    <?php if ( $tab ) : ?>
Note: See TracChangeset for help on using the changeset viewer.