Toggle Side Panel
BuddyBoss Resources
  • Knowledge Base
    • All Articles
    • BuddyBoss Platform
    • BuddyBoss Theme
    • BuddyBoss App
    • Integrations
    • Advanced Setup
    • Troubleshooting
    • Release Notes
      • BuddyBoss Platform
      • BuddyBoss Platform Pro
      • BuddyBoss Theme
      • BuddyBoss App
      • BuddyBoss App Plugin
      • Other Products
  • Developers
    • Developer Tutorials
      • Web Development
      • App Development
    • Code Reference
      • Functions
      • Hooks
      • Classes
      • Methods
      • Commands
      • App Codex
    • REST API
      • BuddyBoss Platform
      • BuddyBoss App
    • Font Cheatsheet
    • Github Project
  • Roadmap
  • Go to BuddyBoss
More options
    Contact Support
    Filter
    • Knowledge Base
      • All Articles
      • BuddyBoss Platform
      • BuddyBoss Theme
      • BuddyBoss App
      • Integrations
      • Advanced Setup
      • Troubleshooting
      • Release Notes
        • BuddyBoss Platform
        • BuddyBoss Platform Pro
        • BuddyBoss Theme
        • BuddyBoss App
        • BuddyBoss App Plugin
        • Other Products
    • Developers
      • Developer Tutorials
        • Web Development
        • App Development
      • Code Reference
        • Functions
        • Hooks
        • Classes
        • Methods
        • Commands
        • App Codex
      • REST API
        • BuddyBoss Platform
        • BuddyBoss App
      • Font Cheatsheet
      • Github Project
    • Roadmap
    • Go to BuddyBoss
    Filter
    Close search
    Filter

    Contents

    • Description
    • Parameters
    • Return
    • Source
    • Related
    Code Reference Functions bp_core_login_redirect()

    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() );
    }
    

    Expand full source code Collapse full source code

    Related

    Uses

    Uses
    Uses Description
    bp-core/bp-core-template.php: bp_get_root_domain()

    Return the “root domain”, the URL of the BP root blog.

    bp-core/bp-core-functions.php: bp_is_root_blog()

    Is this the root blog?

    bp-core/bp-core-filters.php: bp_core_login_redirect

    Filters whether or not to redirect.

    bp-core/bp-core-filters.php: bp_core_login_redirect_to

    Filters the URL to redirect users to upon successful login.

    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.

    © 2025 • BuddyBoss