bp_core_login_redirect( string $redirect_to, string $redirect_to_raw, WP_User $user )
When a user logs in, redirect him in a logical way.
Description
Parameters
- $redirect_to
-
(Required) The URL to be redirected to, sanitized in wp-login.php.
- $redirect_to_raw
-
(Required) The unsanitized redirect_to URL ($_REQUEST['redirect_to']).
- $user
-
(Required) The WP_User object corresponding to a successfully logged-in user. Otherwise a WP_Error object.
Return
(string) The redirect URL.
Source
File: bp-core/bp-core-filters.php
function bp_core_login_redirect( $redirect_to, $redirect_to_raw, $user ) { // Only modify the redirect if we're on the main BP blog. if ( !bp_is_root_blog() ) { return $redirect_to; } // Only modify the redirect once the user is logged in. if ( !is_a( $user, 'WP_User' ) ) { return $redirect_to; } /** * Filters whether or not to redirect. * * Allows plugins to have finer grained control of redirect upon login. * * @since BuddyPress 1.6.0 * * @param bool $value Whether or not to redirect. * @param string $redirect_to Sanitized URL to be redirected to. * @param string $redirect_to_raw Unsanitized URL to be redirected to. * @param WP_User $user The WP_User object corresponding to a * successfully logged in user. */ $maybe_redirect = apply_filters( 'bp_core_login_redirect', false, $redirect_to, $redirect_to_raw, $user ); if ( false !== $maybe_redirect ) { return $maybe_redirect; } // If a 'redirect_to' parameter has been passed that contains 'wp-admin', verify that the // logged-in user has any business to conduct in the Dashboard before allowing the // redirect to go through. if ( !empty( $redirect_to ) && ( false === strpos( $redirect_to, 'wp-admin' ) || user_can( $user, 'edit_posts' ) ) ) { return $redirect_to; } if ( false === strpos( wp_get_referer(), 'wp-login.php' ) && false === strpos( wp_get_referer(), 'activate' ) && empty( $_REQUEST['nr'] ) ) { return wp_get_referer(); } /** * Filters the URL to redirect users to upon successful login. * * @since BuddyPress 1.9.0 * * @param string $value URL to redirect to. */ return apply_filters( 'bp_core_login_redirect_to', bp_get_root_domain() ); }
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.