Changeset 10577 for sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-hooks.php
- Timestamp:
- 01/14/2021 04:49:17 AM (4 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-hooks.php
r10428 r10577 19 19 add_filter( 'old_slug_redirect_post_id', array( $this, 'disable_wp_old_slug_redirect' ) ); 20 20 add_action( 'template_redirect', array( $this, 'redirect_update_php_page' ) ); 21 add_action( 'template_redirect', array( $this, 'redirect_legacy_u ser_structure' ) );21 add_action( 'template_redirect', array( $this, 'redirect_legacy_urls' ) ); 22 22 add_action( 'template_redirect', array( $this, 'redirect_ask_question_plugin_forum' ) ); 23 23 add_filter( 'wp_insert_post_data', array( $this, 'set_post_date_gmt_for_pending_posts' ) ); … … 303 303 304 304 /** 305 * Redirect /users/$id to their new /users/$slug permastructure. 306 */ 307 public function redirect_legacy_user_structure() { 308 if ( is_404() && get_query_var( 'bbp_user' ) && is_numeric( get_query_var( 'bbp_user' ) ) ) { 305 * Redirect legacy urls to their new permastructure. 306 * - /users/$id & /profile/$slug to /users/$slug 307 * 308 */ 309 public function redirect_legacy_urls() { 310 global $wp_query; 311 312 if ( ! is_404() ) { 313 return; 314 } 315 316 // Legacy /profile/$user route 317 if ( 318 ! empty( $wp_query->query['pagename'] ) && 319 preg_match( '!^profile/(?P<user>.+)(/|$)!', $wp_query->query['pagename'], $m ) 320 ) { 321 wp_safe_redirect( home_url( '/users/' . urlencode( $m['user'] ) . '/' ), 301 ); 322 exit; 323 } 324 325 // Legacy /users/$user_id route 326 if ( 327 get_query_var( 'bbp_user' ) && 328 is_numeric( get_query_var( 'bbp_user' ) ) 329 ) { 309 330 $user = get_user_by( 'id', (int) get_query_var( 'bbp_user' ) ); 310 331 if ( $user ) { 311 wp_ redirect( home_url( '/users/' . $user->user_nicename . '/' ), 301 );332 wp_safe_redirect( home_url( '/users/' . $user->user_nicename . '/' ), 301 ); 312 333 exit; 313 334 }
Note: See TracChangeset
for help on using the changeset viewer.