Making WordPress.org

Changeset 10577


Ignore:
Timestamp:
01/14/2021 04:49:17 AM (6 years ago)
Author:
dd32
Message:

Support: Add a forum handler for the obsolete /profile/$slug URI which should soon be hitting WordPress.

See #5384.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/plugins/support-forums/inc/class-hooks.php

    r10428 r10577  
    1919                add_filter( 'old_slug_redirect_post_id',       array( $this, 'disable_wp_old_slug_redirect' ) );
    2020                add_action( 'template_redirect',               array( $this, 'redirect_update_php_page' ) );
    21                 add_action( 'template_redirect',               array( $this, 'redirect_legacy_user_structure' ) );
     21                add_action( 'template_redirect',               array( $this, 'redirect_legacy_urls' ) );
    2222                add_action( 'template_redirect',               array( $this, 'redirect_ask_question_plugin_forum' ) );
    2323                add_filter( 'wp_insert_post_data',             array( $this, 'set_post_date_gmt_for_pending_posts' ) );
     
    303303
    304304        /**
    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                ) {
    309330                        $user = get_user_by( 'id', (int) get_query_var( 'bbp_user' ) );
    310331                        if ( $user ) {
    311                                 wp_redirect( home_url( '/users/' . $user->user_nicename . '/' ), 301 );
     332                                wp_safe_redirect( home_url( '/users/' . $user->user_nicename . '/' ), 301 );
    312333                                exit;
    313334                        }
Note: See TracChangeset for help on using the changeset viewer.