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.
Opens WPIDE on
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
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.