Group Mods

  • Profile picture of @mercime
  • Profile picture of r-a-y
  • Profile picture of hnla

a little script that improves the BP experience during a login error (12 posts)

Started 1 year, 8 months ago by: Dwenaus

  • Profile picture of Dwenaus Dwenaus said 1 year, 8 months ago:

    This script replaces the default WP login scheme with my own customized for BuddyPress. Now if users enter the wrong username or password they won’t get sent to the non-buddypress wp-login.php page. Only lightly tested, but work ok.

    // replacement for regular login - gets rif of wp-login.php page
    function bp_authenticate_username_password($user, $username, $password) {
    	if ( is_a($user, 'WP_User') ) { return $user; }
    
    	if ( empty($username) || empty($password) ) {
    		bp_core_add_message( __('ERROR: Empty Username field or empty Password field. See the sidebar for log in support.', 'scg') , 'error' );
    		wp_redirect(get_option('siteurl'));
    		return false;
    	}
    
    	$userdata = get_userdatabylogin($username);
    
    	if ( !$userdata ) {
    		bp_core_add_message( __('ERROR: Incorrect Username. See the sidebar for log in support.', 'scg') , 'error' );
    		wp_redirect(get_option('siteurl'));
    		return false;
    	}
    
    	$userdata = apply_filters('wp_authenticate_user', $userdata, $password);
    
    	if ( is_wp_error($userdata) ) {
    		bp_core_add_message( __('ERROR: Invalid username or incorrect password.. See the sidebar for log in support.', 'scg') , 'error' );
    		wp_redirect(get_option('siteurl'));
    		return false;
    	}
    
    	if ( !wp_check_password($password, $userdata->user_pass, $userdata->ID) ) {
    		bp_core_add_message( __('ERROR: Incorrect Password. See the sidebar for log in support.', 'scg') , 'error' );
    		wp_redirect(get_option('siteurl'));
    		return false;
    	}
    
    	$user =  new WP_User($userdata->ID);
    	return $user;
    }
    
    add_filter('authenticate', 'bp_authenticate_username_password', 10, 3);
    remove_filter('authenticate', 'wp_authenticate_username_password', 20, 3);
  • Profile picture of TM TM said 1 year, 6 months ago:

    Excellent work! I’m quite pleased with the results on my own site. Works fine!

  • Profile picture of vee_bee vee_bee said 1 year, 4 months ago:

    Hiya @dwenaus
    Do you know if this creates an issue with authentication keys??
    I have this in my bp-custom, and when an activation key is sent, the user does not require it, as a username and password will still work.
    V

  • Profile picture of yu yu said 1 year, 2 months ago:

    For me redirects works fine, but not bp_core_add_message …

  • Profile picture of hmarshall hmarshall said 10 months, 1 week ago:

    Hi @dwenaus

    Please could you tell me which file I have to insert this in as I’m very new to BP? I have a child theme based on the default theme.
    Thanks

  • Profile picture of edinchez edinchez said 10 months, 1 week ago:

    hmarshall, just make a new blank file called bp-custom.php, paste the code in that file and upload it to wp-custom/plugins.

  • Profile picture of nit3watch nit3watch said 10 months, 1 week ago:

    The script it over 10 months old, whilst it probably would still work, there is a plug-in that achieves the same thing: Login with AJAX

  • Profile picture of hmarshall hmarshall said 10 months, 1 week ago:

    @nit3watch that’s useful thanks. But my normal login still shows up above, and my facebook login too. Is there a way to remove the normal buddypress login and have the facebook login bar below the ajax login?

  • Profile picture of nit3watch nit3watch said 10 months ago:

    You have to edit sidebar.php and remove the log-in/log out stuff, as for the facebook log-in – I will get back to you.

  • Profile picture of ibn.nadir ibn.nadir said 8 months, 2 weeks ago:

    @Dwenaus, there’s no message appear when login failed. How to get that message appear?

  • Profile picture of ankurm ankurm said 5 months ago:

    @Dwenaus , i have the same problem which @ibn.nadir had..
    there are no error messages appearing after the redirection. How to get that message appear?

    thanks

  • Profile picture of ankurm ankurm said 5 months ago:

    btw @Dwenaus the code worked perfectly fine otherwise…
    Thanks..