Changeset 11025
- Timestamp:
- 06/11/2021 05:39:41 AM (3 years ago)
- 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 32 32 33 33 // 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' ) ); 35 38 36 39 // Redirect (.+)/page/[01]/ and (.+)?paged=[01] to $1 … … 77 80 78 81 /** 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() ) { 86 86 return; 87 87 } … … 91 91 } 92 92 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; 118 166 } 119 167 -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/bbpress/loop-search.php
r7818 r11025 9 9 <?php if ( 'topic' === get_post_type() ) : ?> 10 10 11 <?php bbp_get_template_part( ' content', 'single-topic-lead' ); ?>11 <?php bbp_get_template_part( 'loop', 'single-topic' ); ?> 12 12 13 13 <?php else : ?> -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/search.php
r11022 r11025 14 14 <main id="main" class="site-main" role="main"> 15 15 16 <h1><?php single_cat_title(); ?></h1>16 <h1><?php printf( __( 'Search Results for %s' ), esc_html( get_query_var( 's' ) ) ); ?></h1> 17 17 18 <div class=" three-up helphub-front-page">18 <div class="search"> 19 19 <?php 20 20 while ( have_posts() ) : … … 22 22 ?> 23 23 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> 27 26 28 <?php the_excerpt(); ?> 29 </article> 30 </a> 31 27 <?php the_excerpt(); ?> 28 </article> 32 29 33 30 <?php endwhile; ?> -
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-support/searchform.php
r9664 r11025 21 21 $placeholder = _x( 'Search this forum', 'placeholder', 'wporg-forums' ); 22 22 $project = wporg_support_get_compat_object(); 23 $tab = $project->type; 24 $project = $project->post_name; 23 25 } elseif ( is_front_page() ) { 24 26 $placeholder = _x( 'Search documentation', 'placeholder', 'wporg-forums' ); 25 27 $project = null; 26 28 $tab = 'docs'; 29 } elseif ( is_search() || bbp_is_search() ) { 30 if ( isset( $_GET['tab'] ) ) { 31 $tab = $_GET['tab']; 32 $project = $_GET[ $_GET['tab'] ]; 33 } 27 34 } else { 28 35 $placeholder = _x( 'Search forums', 'placeholder', 'wporg-forums' ); 29 36 $project = null; 37 $tab = 'support'; 30 38 } 31 39 ?> 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" /> 33 41 <?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 ); ?>" /> 35 43 <?php endif; ?> 36 44 <?php if ( $tab ) : ?>
Note: See TracChangeset
for help on using the changeset viewer.