BuddyDev

Search

[Resolved] When user get spammed, Add a Login Error Alert

  • Participant
    Level: Enlightened
    Posts: 146
    Dandy Jefferson on #8555

    Hi, there

    Thanks for previous helps and suggestions and they helped me a lot.

    I just met an issue, as you know, BuddyPress provides a function to spam particular user. When user is marked as spam, he can’t log in.

    I’m wondering is there any way to add a custom Login error alert to tell user “You are suspended because of inappropriate messages” when they try to log in again?

    Thank you very much.

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #8561

    Hello Dandy,

    Try the following code in your bp-custom.php file and let me know if it works or not.

    
    function buddydev_custom_spammer_message( $user ) {
    
    	// Check to see if the $user has already failed logging in, if so return $user as-is.
    	if ( is_wp_error( $user ) || empty( $user ) ) {
    		return $user;
    	}
    
    	// The user exists; now do a check to see if the user is a spammer
    	// if the user is a spammer, stop them in their tracks!
    	if ( is_a( $user, 'WP_User' ) && ( ( is_multisite() && (int) $user->spam ) || 1 == $user->user_status ) ) {
    		return new WP_Error( 'invalid_username', __( '<strong>ERROR</strong>: You has been marked as a spammer.', 'buddypress' ) );
    	}
    
    	// User is good to go!
    	return $user;
    }
    add_filter( 'authenticate', 'buddydev_custom_spammer_message', 25 );
    
    

    Thank You
    Ravi

  • Participant
    Level: Enlightened
    Posts: 146
    Dandy Jefferson on #8566

    Hi, Ravi

    Thanks for the code snippet.

    I adjusted it a little bit and it worked very perfectly as I expected.

    Thank you very much.

  • Keymaster
    Level: Yogi
    (BuddyDev Team)
    Posts: 3115
    Ravi on #8575

    Hello Dandy,

    Thank you for acknowledgement. I am glad that I could help.

    Thank You
    Ravi

The topic ‘ [Resolved] When user get spammed, Add a Login Error Alert’ is closed to new replies.

This topic is: resolved