Skip to:
Content
Pages
Categories
Search
Top
Bottom

a little script that improves the BP experience during a login error

  • Avatar of Dwenaus
    Dwenaus
    Participant

    @dwenaus

    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);
    `

Viewing 11 replies - 1 through 11 (of 11 total)
  • Avatar of TM
    TM
    Participant

    @tiagom

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

    Avatar of vee_bee
    vee_bee
    Participant

    @vee_bee

    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

    Avatar of yu
    yu
    Participant

    @gerbilo

    For me redirects works fine, but not bp_core_add_message …

    Avatar of hmarshall
    hmarshall
    Member

    @hmarshall

    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

    Avatar of edinchez
    edinchez
    Participant

    @edinchez

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

    Avatar of nit3watch
    nit3watch
    Participant

    @nit3watch

    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

    Avatar of hmarshall
    hmarshall
    Member

    @hmarshall

    @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?

    Avatar of nit3watch
    nit3watch
    Participant

    @nit3watch

    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.

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

    @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

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

Viewing 11 replies - 1 through 11 (of 11 total)

You must be logged in to reply to this topic.