Halloween Sale 15% off Ends in See the plans
PHP

BuddyPress: Send Members to Their Profile After Login

Sends members to their own BuddyPress profile (or activity stream) after logging in, instead of the WordPress dashboard.

Don’t have WPIDE yet? Install it on your site

Code

if ( ! function_exists( 'buddypress' ) ) {
    return;
}

// "profile" or "activity".
$wpide_bp_login_target = 'profile';

add_filter( 'login_redirect', function ( $redirect, $requested, $user ) use ( $wpide_bp_login_target ) {
    if ( ! $user instanceof WP_User || user_can( $user, 'edit_posts' ) ) {
        return $redirect;
    }

    if ( $requested && false === strpos( $requested, admin_url() ) ) {
        return $redirect;
    }

    if ( 'activity' === $wpide_bp_login_target && bp_is_active( 'activity' ) ) {
        return bp_get_activity_directory_permalink();
    }

    $url = function_exists( 'bp_members_get_user_url' ) ? bp_members_get_user_url( $user->ID ) : bp_core_get_user_domain( $user->ID );

    return $url ? $url : $redirect;
}, 10, 3 );

Notes

Set $wpide_bp_login_target to "activity" to land on the site-wide activity stream. Staff who can edit posts still go to wp-admin.

How to add this snippet

  1. Install WPIDE on your WordPress site (it is free) and open Code Snippets.
  2. Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
  3. It is added inactive: review the code and settings, then switch it on.

Have a snippet worth sharing?

Publish it to the library from WPIDE or right here. Sign in with any WordPress site that runs WPIDE, free or Pro. Public snippets are reviewed by the WPIDE team before they appear.

Which site should get this snippet?

Enter the address of your WordPress site. WPIDE opens there in a new tab with the snippet ready to review and save.

Remembered in this browser only, so you are asked once.

Report this snippet

Tell the WPIDE team what is wrong: broken code, something harmful, spam or copied work.