bp_core_wpsignup_redirect()

Redirect away from wp-signup.php if BP registration templates are present.


Source Source

File: bp-members/bp-members-functions.php

function bp_core_wpsignup_redirect() {

	// Bail in admin or if custom signup page is broken.
	if ( is_admin() || ! bp_has_custom_signup_page() ) {
		return;
	}

	$is_wp_signup = false;
	if ( ! empty( $_SERVER['SCRIPT_NAME'] ) ) {
		$script_name_path = wp_parse_url( $_SERVER['SCRIPT_NAME'], PHP_URL_PATH );

		if ( 'wp-signup.php' === basename( $script_name_path ) || ( 'wp-login.php' === basename( $script_name_path ) && ! empty( $_GET['action'] ) && 'register' === $_GET['action'] ) ) {
			$is_wp_signup = true;
		}
	}

	// If this is not wp-signup.php, there's nothing to do here.
	if ( ! $is_wp_signup ) {
		return;
	}

	/*
	 * We redirect wp-signup.php to the registration page except when it's a site signup.
	 * In that case, redirect to the BP site creation page if available, otherwise allow
	 * access to wp-signup.php.
	 */
	$redirect_to = bp_get_signup_page();

	$is_site_creation = false;

	$referer = wp_get_referer();

	// A new site is being added.
	if ( isset( $_POST['stage'] ) && $_POST['stage'] === 'gimmeanotherblog' ) {
		$is_site_creation = true;

	// We've arrived at wp-signup.php from my-sites.php.
	} elseif ( $referer ) {
		$referer_path     = wp_parse_url( $referer, PHP_URL_PATH );
		$is_site_creation = false !== strpos( $referer_path, 'wp-admin/my-sites.php' );
	}

	if ( $is_site_creation ) {
		if ( bp_is_active( 'blogs' ) ) {
			$redirect_to = trailingslashit( bp_get_blogs_directory_permalink() . 'create' );
		} else {
			// Perform no redirect in this case.
			$redirect_to = '';
		}
	}

	if ( ! $redirect_to ) {
		return;
	}

	bp_core_redirect( $redirect_to );
}


Top ↑

Changelog Changelog

Changelog
Version Description
1.1.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.