Making WordPress.org

Changeset 11335


Ignore:
Timestamp:
11/18/2021 01:47:58 AM (2 years ago)
Author:
dd32
Message:

Support: Make the https://wordpress.org/support/users/profile/edit/ url work when logged out.

Previously broken in [11333].
See #5830.

File:
1 edited

Legend:

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

    r11333 r11335  
    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_urls' ) );
     21        add_action( 'template_redirect',               array( $this, 'redirect_legacy_urls' ), 5 );
    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' ) );
     
    319319    public function redirect_legacy_urls() {
    320320        global $wp_query, $wp;
     321
     322        // A user called 'profile' exists, but override it.
     323        if ( 'profile' === get_query_var( 'bbp_user' ) ) {
     324            if ( is_user_logged_in() ) {
     325                $user = wp_get_current_user();
     326                $url  = str_replace( '/profile/', "/{$user->user_nicename}/", $_SERVER['REQUEST_URI'] );
     327            } else {
     328                $url  = wp_login_url( home_url( $wp->request ) );
     329            }
     330
     331            wp_safe_redirect( $url );
     332            exit;
     333        }
    321334
    322335        if ( ! is_404() ) {
     
    345358        }
    346359
    347         if ( 'profile' === get_query_var( 'bbp_user' ) ) {
    348             if ( is_user_logged_in() ) {
    349                 $user = wp_get_current_user();
    350                 $url  = str_replace( '/profile/', "/{$user->user_nicename}/", $_SERVER['REQUEST_URI'] );
    351             } else {
    352                 $url  = wp_login_url( home_url( $wp->request ) );
    353             }
    354 
    355             wp_safe_redirect( $url );
    356             exit;
    357         }
    358360    }
    359361
Note: See TracChangeset for help on using the changeset viewer.