Changeset 8050
- Timestamp:
- 01/09/2019 12:40:52 AM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-performance-optimizations.php
r7806 r8050 33 33 // Redirect search results. 34 34 add_action( 'bbp_template_redirect', array( $this, 'redirect_search_results_to_google_search' ) ); 35 36 // Redirect (.+)/page/[01]/ and (.+)?paged=[01] to $1 37 add_action( 'bbp_template_redirect', array( $this, 'redirect_page_zero_one' ) ); 35 38 36 39 // REST API. … … 122 125 wp_safe_redirect( $search_url ); 123 126 exit; 127 } 128 129 /** 130 * Redirects /page/[01]/, and /?paged=[01] requests to the archive root. 131 */ 132 public function redirect_page_zero_one() { 133 global $wp_query; 134 135 if ( 136 isset( $wp_query->query['paged'] ) && 137 in_array( $wp_query->query['paged'], [ 0, 1 ] ) && 138 'POST' !== $_SERVER['REQUEST_METHOD'] 139 ) { 140 // Generate the current URL. 141 $current_url = $_SERVER['REQUEST_URI']; 142 // Remove the path components. 143 $current_url = preg_replace( '!^' . preg_quote( parse_url( home_url('/'), PHP_URL_PATH ), '!' ) . '!i', '', $current_url ); 144 $current_url = home_url( $current_url ); 145 146 // Remove any paged items 147 $pageless_url = $current_url; 148 $pageless_url = remove_query_arg( 'paged', $pageless_url ); 149 $pageless_url = preg_replace( '!/page/[01]/?!i', '/', $pageless_url ); 150 151 if ( $pageless_url !== $current_url ) { 152 wp_safe_redirect( $pageless_url ); 153 exit; 154 } 155 } 124 156 } 125 157
Note: See TracChangeset
for help on using the changeset viewer.