Changeset 11159 for sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-patterns/functions.php
- Timestamp:
- 07/29/2021 07:02:19 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-patterns/functions.php
r11146 r11159 16 16 17 17 add_filter( 'archive_template', __NAMESPACE__ . '\use_index_php_as_template' ); 18 add_action( 'template_redirect', __NAMESPACE__ . '\rewrite_ search_url' );18 add_action( 'template_redirect', __NAMESPACE__ . '\rewrite_urls' ); 19 19 20 20 /** … … 99 99 'site' => esc_url( home_url() ), 100 100 'login' => esc_url( wp_login_url() ), 101 'register' => esc_url( wp_registration_url() ), 101 102 ) ) ), 102 103 ), … … 178 179 if ( $pagename ) { 179 180 list( $_pagename ) = explode( '/', $pagename ); 180 if ( in_array( $_pagename, array( 'my-patterns', ' my-favorites' ) ) ) {181 if ( in_array( $_pagename, array( 'my-patterns', 'favorites' ) ) ) { 181 182 // Need to get the page ID because this is set before `pre_get_posts` fires. 182 183 $page = get_page_by_path( $_pagename ); … … 206 207 function add_rewrite() { 207 208 add_rewrite_rule( '^my-patterns/[^/]+/?$', 'index.php?pagename=my-patterns', 'top' ); 208 add_rewrite_rule( '^ my-favorites/.+/?$', 'index.php?pagename=my-favorites', 'top' );209 add_rewrite_rule( '^favorites/.+/?$', 'index.php?pagename=favorites', 'top' ); 209 210 } 210 211 … … 256 257 257 258 /** 258 * Rewrites the search url from s={keyword} to /search/{keyword}.259 * Set up redirects for the site. 259 260 * 260 261 * @return void 261 262 */ 262 function rewrite_search_url() { 263 function rewrite_urls() { 264 // Redirect searches to `/search/term`. 263 265 if ( is_search() && ! empty( $_GET['s'] ) ) { 264 266 wp_redirect( home_url( '/search/' ) . urlencode( trim( get_query_var( 's' ) ) ) . '/' ); 267 exit(); 268 } 269 // Redirect old slug `my-favorites` to `favorites`, see WordPress/pattern-directory#332. 270 $path = str_replace( 'patterns/', '', trim( $_SERVER['REQUEST_URI'], '/' ) ); 271 if ( preg_match( '/^my-favorites(.*)/', $path, $matches ) ) { 272 wp_redirect( home_url( '/favorites/' . $matches[1] . '/' ) ); 265 273 exit(); 266 274 }
Note: See TracChangeset
for help on using the changeset viewer.