<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN"
"http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head><meta http-equiv="content-type" content="text/html; charset=utf-8" />
<title>[11025] sites/trunk/wordpress.org/public_html/wp-content: Support: Attempt to use bbPress/WordPress search for support forums.</title>
</head>
<body>

<style type="text/css"><!--
#msg dl.meta { border: 1px #006 solid; background: #369; padding: 6px; color: #fff; }
#msg dl.meta dt { float: left; width: 6em; font-weight: bold; }
#msg dt:after { content:':';}
#msg dl, #msg dt, #msg ul, #msg li, #header, #footer, #logmsg { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt;  }
#msg dl a { font-weight: bold}
#msg dl a:link    { color:#fc3; }
#msg dl a:active  { color:#ff0; }
#msg dl a:visited { color:#cc6; }
h3 { font-family: verdana,arial,helvetica,sans-serif; font-size: 10pt; font-weight: bold; }
#msg pre { white-space: pre-line; overflow: auto; background: #ffc; border: 1px #fa0 solid; padding: 6px; }
#logmsg { background: #ffc; border: 1px #fa0 solid; padding: 1em 1em 0 1em; }
#logmsg p, #logmsg pre, #logmsg blockquote { margin: 0 0 1em 0; }
#logmsg p, #logmsg li, #logmsg dt, #logmsg dd { line-height: 14pt; }
#logmsg h1, #logmsg h2, #logmsg h3, #logmsg h4, #logmsg h5, #logmsg h6 { margin: .5em 0; }
#logmsg h1:first-child, #logmsg h2:first-child, #logmsg h3:first-child, #logmsg h4:first-child, #logmsg h5:first-child, #logmsg h6:first-child { margin-top: 0; }
#logmsg ul, #logmsg ol { padding: 0; list-style-position: inside; margin: 0 0 0 1em; }
#logmsg ul { text-indent: -1em; padding-left: 1em; }#logmsg ol { text-indent: -1.5em; padding-left: 1.5em; }
#logmsg > ul, #logmsg > ol { margin: 0 0 1em 0; }
#logmsg pre { background: #eee; padding: 1em; }
#logmsg blockquote { border: 1px solid #fa0; border-left-width: 10px; padding: 1em 1em 0 1em; background: white;}
#logmsg dl { margin: 0; }
#logmsg dt { font-weight: bold; }
#logmsg dd { margin: 0; padding: 0 0 0.5em 0; }
#logmsg dd:before { content:'\00bb';}
#logmsg table { border-spacing: 0px; border-collapse: collapse; border-top: 4px solid #fa0; border-bottom: 1px solid #fa0; background: #fff; }
#logmsg table th { text-align: left; font-weight: normal; padding: 0.2em 0.5em; border-top: 1px dotted #fa0; }
#logmsg table td { text-align: right; border-top: 1px dotted #fa0; padding: 0.2em 0.5em; }
#logmsg table thead th { text-align: center; border-bottom: 1px solid #fa0; }
#logmsg table th.Corner { text-align: left; }
#logmsg hr { border: none 0; border-top: 2px dashed #fa0; height: 1px; }
#header, #footer { color: #fff; background: #636; border: 1px #300 solid; padding: 6px; }
#patch { width: 100%; }
#patch h4 {font-family: verdana,arial,helvetica,sans-serif;font-size:10pt;padding:8px;background:#369;color:#fff;margin:0;}
#patch .propset h4, #patch .binary h4 {margin:0;}
#patch pre {padding:0;line-height:1.2em;margin:0;}
#patch .diff {width:100%;background:#eee;padding: 0 0 10px 0;overflow:auto;}
#patch .propset .diff, #patch .binary .diff  {padding:10px 0;}
#patch span {display:block;padding:0 10px;}
#patch .modfile, #patch .addfile, #patch .delfile, #patch .propset, #patch .binary, #patch .copfile {border:1px solid #ccc;margin:10px 0;}
#patch ins {background:#dfd;text-decoration:none;display:block;padding:0 10px;}
#patch del {background:#fdd;text-decoration:none;display:block;padding:0 10px;}
#patch .lines, .info {color:#888;background:#fff;}
--></style>
<div id="msg">
<dl class="meta" style="font-size: 105%">
<dt style="float: left; width: 6em; font-weight: bold">Revision</dt> <dd><a style="font-weight: bold" href="http://meta.trac.wordpress.org/changeset/11025">11025</a><script type="application/ld+json">{"@context":"http://schema.org","@type":"EmailMessage","description":"Review this Commit","action":{"@type":"ViewAction","url":"http://meta.trac.wordpress.org/changeset/11025","name":"Review Commit"}}</script></dd>
<dt style="float: left; width: 6em; font-weight: bold">Author</dt> <dd>dd32</dd>
<dt style="float: left; width: 6em; font-weight: bold">Date</dt> <dd>2021-06-11 05:39:41 +0000 (Fri, 11 Jun 2021)</dd>
</dl>

<pre style='padding-left: 1em; margin: 2em 0; border-left: 2px solid #ccc; line-height: 1.25; font-size: 105%; font-family: sans-serif'>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 <a href="http://meta.trac.wordpress.org/ticket/5771">#5771</a>.</pre>

<h3>Modified Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentpluginssupportforumsincclassperformanceoptimizationsphp">sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-performance-optimizations.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgsupportbbpressloopsearchphp">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/bbpress/loop-search.php</a></li>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgsupportsearchformphp">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/searchform.php</a></li>
</ul>

<h3>Added Paths</h3>
<ul>
<li><a href="#sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgsupportsearchphp">sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/search.php</a></li>
</ul>

</div>
<div id="patch">
<h3>Diff</h3>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentpluginssupportforumsincclassperformanceoptimizationsphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-performance-optimizations.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-performance-optimizations.php   2021-06-10 19:48:58 UTC (rev 11024)
+++ sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-performance-optimizations.php     2021-06-11 05:39:41 UTC (rev 11025)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -31,7 +31,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">                add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_styles' ) );
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Redirect search results.
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                add_action( 'bbp_template_redirect', array( $this, 'redirect_search_results_to_google_search' ) );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         add_action( 'bbp_template_redirect', array( $this, 'redirect_search_results' ) );
+               add_filter( 'pre_get_posts', array( $this, 'search_alterations' ) );
+               add_filter( 'pre_get_posts', array( $this, 'search_forum_alterations' ) );
+               add_filter( 'bbp_after_has_search_results_parse_args', array( $this, 'search_forum_alteration_args' ) );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                // Redirect (.+)/page/[01]/ and (.+)?paged=[01] to $1
</span><span class="cx" style="display: block; padding: 0 10px">                add_action( 'bbp_template_redirect', array( $this, 'redirect_page_zero_one' ) );
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -76,13 +79,10 @@
</span><span class="cx" style="display: block; padding: 0 10px">        }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">        /**
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-         * Redirects search results to Google Custom Search.
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+  * Redirects search results to appropriate place.
</ins><span class="cx" style="display: block; padding: 0 10px">          */
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        public function redirect_search_results_to_google_search() {
-               $is_wp_search  = is_search();
-               $is_bbp_search = bbp_is_search_results();
-
-               if ( ! $is_wp_search && ! $is_bbp_search ) {
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ public function redirect_search_results() {
+               if ( ! is_search() ) {
</ins><span class="cx" style="display: block; padding: 0 10px">                         return;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -90,33 +90,81 @@
</span><span class="cx" style="display: block; padding: 0 10px">                        return;
</span><span class="cx" style="display: block; padding: 0 10px">                }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                $search_terms = $search_url = '';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $search_terms = get_search_query( false );
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( $is_bbp_search ) {
-                       $search_terms = bbp_get_search_terms();
-               } elseif ( $is_wp_search ) {
-                       $search_terms = get_search_query( false );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $tab = $_GET['tab'] ?? 'support';
+               if ( ! in_array( $tab, [ 'support', 'docs', 'plugin', 'theme' ] ) ) {
+                       $tab = 'support';
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( isset( $_GET['intext'] ) ) {
-                       $search_terms .= ' intext:"' . esc_attr( $_GET['intext'] ) . '"';
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         switch ( $tab ) {
+                       case 'theme':
+                       case 'plugin':
+                               wp_safe_redirect( add_query_arg( $tab, $_GET[ $tab ], home_url( "/search/{$search_terms}/" ) ) );
+                               exit;
+                       case 'support':
+                               wp_safe_redirect( home_url( "/search/{$search_terms}/" ) );
+                               exit;
+                       case 'docs':
+                               // Do nothing.
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        }
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( $search_terms ) {
-                       $tab = ! empty( $_GET['tab'] ) && 'docs' === $_GET['tab'] ? 'docs' : 'forums';
-                       $search_url = sprintf( "https://wordpress.org/search/%s/?{$tab}=1", urlencode( $search_terms ) );
-                       $search_url = esc_url_raw( $search_url );
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ /**
+        * Search alterations for forums.
+        */
+       public function search_alterations( $query ) {
+               if ( ! is_search() || ! $query->is_search() ) {
+                       return;
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                if ( ! $search_url ) {
-                       wp_safe_redirect( home_url( '/' ) );
-                       exit;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         $query->set( 'post_type', [ 'page', 'helphub_article' ] );
+
+       }
+
+       public function search_forum_alterations( $query ) {
+               if ( empty( $query->query['_bbp_search_query'] ) ) {
+                       return;
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                wp_safe_redirect( $search_url );
-               exit;
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+         // Limit searches to published topics.
+               $query->set( 'post_type', 'topic' );
+               $query->set( 'post_status', 'publish' );
+
+               // Limit to either the plugin/theme in question, or to general support threads.
+               if ( !empty( $_GET['plugin'] ) ) {
+                       $query->set( 'tax_query', [
+                               [
+                                       'taxonomy' => 'topic-plugin',
+                                       'field' => 'slug',
+                                       'terms' => [ $_GET['plugin'] ]
+                               ]
+                       ] );
+
+                       add_filter( 'posts_where', array( $this, 'posts_in_last_year' ) );
+               } elseif ( ! empty( $_GET['theme'] ) ) {
+                       $query->set( 'tax_query', [
+                               [
+                                       'taxonomy' => 'topic-theme',
+                                       'field' => 'slug',
+                                       'terms' => [ $_GET['theme'] ]
+                               ]
+                       ] );
+
+                       add_filter( 'posts_where', array( $this, 'posts_in_last_year' ) );
+               } else {
+                       $query->set( 'post_parent__not_in', [21261, 21262, 21272] ); // Magic numbers: Plugins, Themes, Reviews
+
+                       add_filter( 'posts_where', array( $this, 'posts_in_last_six_months' ) );
+               }
</ins><span class="cx" style="display: block; padding: 0 10px">         }
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+        public function search_forum_alteration_args( $args ) {
+               $args['_bbp_search_query'] = true;
+
+               return $args;
+       }
+
</ins><span class="cx" style="display: block; padding: 0 10px">         /**
</span><span class="cx" style="display: block; padding: 0 10px">         * Redirects /page/[01]/, and /?paged=[01] requests to the archive root.
</span><span class="cx" style="display: block; padding: 0 10px">         */
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgsupportbbpressloopsearchphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/bbpress/loop-search.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/bbpress/loop-search.php 2021-06-10 19:48:58 UTC (rev 11024)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/bbpress/loop-search.php   2021-06-11 05:39:41 UTC (rev 11025)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -8,7 +8,7 @@
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        <?php if ( 'topic' === get_post_type() ) : ?>
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-                                <?php bbp_get_template_part( 'content', 'single-topic-lead' ); ?>
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                         <?php bbp_get_template_part( 'loop', 'single-topic' ); ?>
</ins><span class="cx" style="display: block; padding: 0 10px"> 
</span><span class="cx" style="display: block; padding: 0 10px">                        <?php else : ?>
</span><span class="cx" style="display: block; padding: 0 10px"> 
</span></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgsupportsearchphpfromrev11022sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgsupportarchivephp"></a>
<div class="copfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Copied: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/search.php (from rev 11022, sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/archive.php)</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/search.php                              (rev 0)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/search.php        2021-06-11 05:39:41 UTC (rev 11025)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -0,0 +1,41 @@
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+<?php
+/**
+ * The catchall archive template.
+ *
+ * If no specific archive layout is defined, we'll go with
+ * a generic simplistic one, like this, just to actually
+ * be able to show some content.
+ *
+ * @package WPBBP
+ */
+
+get_header(); ?>
+
+       <main id="main" class="site-main" role="main">
+
+               <h1><?php printf( __( 'Search Results for %s' ), esc_html( get_query_var( 's' ) ) ); ?></h1>
+
+               <div class="search">
+                       <?php
+                       while ( have_posts() ) :
+                               the_post();
+                       ?>
+
+                       <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
+                               <a href="<?php echo esc_url( get_the_permalink() ); ?>" class="archive-block"><?php the_title( '<h2>', '</h2>' ); ?></a>
+
+                               <?php the_excerpt(); ?>
+                       </article>
+
+                       <?php endwhile; ?>
+
+               </div>
+
+               <div class="archive-pagination">
+                       <?php posts_nav_link(); ?>
+               </div>
+       </main>
+
+<?php
+get_footer();
+
</ins></span></pre></div>
<a id="sitestrunkwordpressorgpublic_htmlwpcontentthemespubwporgsupportsearchformphp"></a>
<div class="modfile"><h4 style="background-color: #eee; color: inherit; margin: 1em 0; padding: 1.3em; font-size: 115%">Modified: sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/searchform.php</h4>
<pre class="diff"><span>
<span class="info" style="display: block; padding: 0 10px; color: #888">--- sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/searchform.php  2021-06-10 19:48:58 UTC (rev 11024)
+++ sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/searchform.php    2021-06-11 05:39:41 UTC (rev 11025)
</span><span class="lines" style="display: block; padding: 0 10px; color: #888">@@ -20,18 +20,26 @@
</span><span class="cx" style="display: block; padding: 0 10px">                if ( in_array( current_action(), [ 'bbp_template_before_pagination_loop', 'wporg_compat_before_single_view' ] ) ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $placeholder = _x( 'Search this forum', 'placeholder', 'wporg-forums' );
</span><span class="cx" style="display: block; padding: 0 10px">                        $project     = wporg_support_get_compat_object();
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        $tab         = $project->type;
+                       $project     = $project->post_name;
</ins><span class="cx" style="display: block; padding: 0 10px">                 } elseif ( is_front_page() ) {
</span><span class="cx" style="display: block; padding: 0 10px">                        $placeholder = _x( 'Search documentation', 'placeholder', 'wporg-forums' );
</span><span class="cx" style="display: block; padding: 0 10px">                        $project     = null;
</span><span class="cx" style="display: block; padding: 0 10px">                        $tab         = 'docs';
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                } elseif ( is_search() || bbp_is_search() ) {
+                       if ( isset( $_GET['tab'] ) ) {
+                               $tab     = $_GET['tab'];
+                               $project = $_GET[ $_GET['tab'] ];
+                       }
</ins><span class="cx" style="display: block; padding: 0 10px">                 } else {
</span><span class="cx" style="display: block; padding: 0 10px">                        $placeholder = _x( 'Search forums', 'placeholder', 'wporg-forums' );
</span><span class="cx" style="display: block; padding: 0 10px">                        $project     = null;
</span><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+                        $tab         = 'support';
</ins><span class="cx" style="display: block; padding: 0 10px">                 }
</span><span class="cx" style="display: block; padding: 0 10px">        ?>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        <input type="search" id="s" class="search-field" placeholder="<?php echo esc_attr( $placeholder ); ?>" value="<?php the_search_query(); ?>" name="s" />
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <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" />
</ins><span class="cx" style="display: block; padding: 0 10px">         <?php if ( $project ) : ?>
</span><del style="background-color: #fdd; text-decoration:none; display:block; padding: 0 10px">-        <input type="hidden" name="intext" value="<?php echo esc_attr( $project->prefixed_title ); ?>" />
</del><ins style="background-color: #dfd; text-decoration:none; display:block; padding: 0 10px">+ <input type="hidden" name="<?php echo esc_attr( $tab ); ?>" value="<?php echo esc_attr( $project ); ?>" />
</ins><span class="cx" style="display: block; padding: 0 10px">         <?php endif; ?>
</span><span class="cx" style="display: block; padding: 0 10px">        <?php if ( $tab ) : ?>
</span><span class="cx" style="display: block; padding: 0 10px">        <input type="hidden" name="tab" value="<?php echo esc_attr( $tab ); ?>" />
</span></span></pre>
</div>
</div>

</body>
</html>