The original remove_action may not always work
remove_action( ‘bp_adminbar_menus’, ‘bp_adminbar_login_menu’, 2 );
since we can’t guarantee that buddypress plugin is parsed before this fix plugin. A slight modification I made works for me:
I change add_action( 'bp_adminbar_menus', 'custom_bp_adminbar_login_menu', 2 );
to add_action( 'bp_adminbar_menus', 'custom_bp_adminbar_login_menu', 1 );
so it will run before the original bp_adminbar_login_menu runs, but after the plugins are parsed and hooks are registered, and then in custom_bp_adminbar_login_menu, I added remove_action( 'bp_adminbar_menus', 'bp_adminbar_login_menu', 2 );
Therefore, the whole thing looks like:
function custom_bp_adminbar_login_menu() {
global $bp;
remove_action( 'bp_adminbar_menus', 'bp_adminbar_login_menu', 2 );
if ( is_user_logged_in() )
return false;
$redirecturl = $bp->root_domain . '/wp-login.php?redirect_to=' . urlencode( $bp->root_domain ) . esc_url( $_SERVER );
echo '
' . __( 'Log In', 'buddypress' ) . '
';
// Show “Sign Up” link if user registrations are allowed
if ( bp_get_signup_allowed() ) {
echo '
' . __( 'Sign Up', 'buddypress' ) . '
';
}
}
add_action( 'bp_adminbar_menus', 'custom_bp_adminbar_login_menu', 1 );
I agree with fbutera101, though — I am having a hard time imagining a use case where users want to leave where they already are after logging in.