Skip to:
Content

BuddyPress.org

Changeset 12356


Ignore:
Timestamp:
03/11/2019 06:58:06 PM (5 years ago)
Author:
boonebgorges
Message:

Improve wp-login and wp-signup redirects.

This changeset restores the following intended behavior:

  1. On non-Multisite, redirect from wp-login.php?action=register to the BP account registration page
  2. On Multisite, redirect from wp-signup.php to the BP "Create a Site" page when the wp-signup.php is intended to trigger new site creation and the Blogs component is enabled
  3. On Multisite, redirect from wp-signup.php to BP's registration in other cases

Props imath.

Fixes #6178. Fixes #8038.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/bp-members/bp-members-functions.php

    r12349 r12356  
    22922292    }
    22932293
    2294     $action = !empty( $_GET['action'] ) ? $_GET['action'] : '';
    2295 
    2296     // Not at the WP core signup page and action is not register.
    2297     if ( ! empty( $_SERVER['SCRIPT_NAME'] ) && false === strpos( 'wp-signup.php', $_SERVER['SCRIPT_NAME'] ) && ( 'register' != $action ) ) {
     2294    $is_wp_signup = false;
     2295    if ( ! empty( $_SERVER['SCRIPT_NAME'] ) ) {
     2296        $script_name_path = wp_parse_url( $_SERVER['SCRIPT_NAME'], PHP_URL_PATH );
     2297
     2298        if ( 'wp-signup.php' === basename( $script_name_path ) || ( 'wp-login.php' === basename( $script_name_path ) && ! empty( $_GET['action'] ) && 'register' === $_GET['action'] ) ) {
     2299            $is_wp_signup = true;
     2300        }
     2301    }
     2302
     2303    // If this is not wp-signup.php, there's nothing to do here.
     2304    if ( ! $is_wp_signup ) {
    22982305        return;
    22992306    }
    23002307
    2301     bp_core_redirect( bp_get_signup_page() );
     2308    /*
     2309     * We redirect wp-signup.php to the registration page except when it's a site signup.
     2310     * In that case, redirect to the BP site creation page if available, otherwise allow
     2311     * access to wp-signup.php.
     2312     */
     2313    $redirect_to = bp_get_signup_page();
     2314
     2315    $is_site_creation = false;
     2316
     2317    $referer = wp_get_referer();
     2318
     2319    // A new site is being added.
     2320    if ( isset( $_POST['stage'] ) && $_POST['stage'] === 'gimmeanotherblog' ) {
     2321        $is_site_creation = true;
     2322
     2323    // We've arrived at wp-signup.php from my-sites.php.
     2324    } elseif ( $referer ) {
     2325        $referer_path     = wp_parse_url( $referer, PHP_URL_PATH );
     2326        $is_site_creation = false !== strpos( $referer_path, 'wp-admin/my-sites.php' );
     2327    }
     2328
     2329    if ( $is_site_creation ) {
     2330        if ( bp_is_active( 'blogs' ) ) {
     2331            $redirect_to = trailingslashit( bp_get_blogs_directory_permalink() . 'create' );
     2332        } else {
     2333            // Perform no redirect in this case.
     2334            $redirect_to = '';
     2335        }
     2336    }
     2337
     2338    if ( ! $redirect_to ) {
     2339        return;
     2340    }
     2341
     2342    bp_core_redirect( $redirect_to );
    23022343}
    23032344add_action( 'bp_init', 'bp_core_wpsignup_redirect' );
Note: See TracChangeset for help on using the changeset viewer.