Ticket #5275: 5275.bp_is_user_spammer.patch
File 5275.bp_is_user_spammer.patch, 3.0 KB (added by , 11 years ago) |
---|
-
bp-members/bp-members-functions.php
add_action( 'make_ham_user', 'bp_core_mark_user_ham_admin' ); 642 642 * Checks if the user has been marked as a spammer. 643 643 * 644 644 * @package BuddyPress Core 645 * @param int $user_id int The id for the user. 645 * @param int|WP_User $user If integer, pass the user ID. Otherwise, pass the 646 * WP_User object. 646 647 * @return bool True if spammer, False if not. 647 648 */ 648 function bp_is_user_spammer( $user _id= 0 ) {649 function bp_is_user_spammer( $user = 0 ) { 649 650 650 651 // No user to check 651 if ( empty( $user _id) )652 if ( empty( $user ) ) 652 653 return false; 653 654 654 $bp = buddypress();655 656 655 // Assume user is not spam 657 656 $is_spammer = false; 658 657 659 // Setup our user660 $user = false;658 // If $user is numeric, get the user data 659 if( ! is_a( $user, 'WP_User' ) && is_numeric( $user ) ) { 661 660 662 // Get locally-cached data if available 663 switch ( $user_id ) { 664 case bp_loggedin_user_id() : 665 $user = ! empty( $bp->loggedin_user->userdata ) ? $bp->loggedin_user->userdata : false; 666 break; 661 $user_id = $user; 667 662 668 case bp_displayed_user_id() : 669 $user = ! empty( $bp->displayed_user->userdata ) ? $bp->displayed_user->userdata : false; 670 break; 671 } 663 $bp = buddypress(); 672 664 673 // Manually get userdata if still empty 674 if ( empty( $user ) ) { 675 $user = get_userdata( $user_id ); 676 } 665 // Get locally-cached userdata if available 666 switch ( $user_id ) { 667 case bp_loggedin_user_id() : 668 $user = ! empty( $bp->loggedin_user->userdata ) ? $bp->loggedin_user->userdata : false; 669 break; 677 670 678 // No user found 679 if ( empty( $user ) ) { 680 $is_spammer = false; 671 case bp_displayed_user_id() : 672 $user = ! empty( $bp->displayed_user->userdata ) ? $bp->displayed_user->userdata : false; 673 break; 674 } 681 675 682 // User found 683 } else { 676 // Manually get userdata if still empty 677 if ( empty( $user ) ) { 678 $user = get_userdata( $user_id ); 679 } 684 680 685 // Check if spam 686 if ( !empty( $user->spam ) ) 687 $is_spammer = true; 681 } 688 682 689 if ( 1 == $user->user_status ) 690 $is_spammer = true; 683 // Spam check 684 if ( ! empty( $user ) ) { 685 686 // Multisite 687 if ( is_multisite() ) { 688 if ( ! empty( $user->spam ) ) { 689 $is_spammer = true; 690 } 691 692 // Single-site 693 } else { 694 if ( 1 == $user->user_status ) { 695 $is_spammer = true; 696 } 697 } 691 698 } 692 699 693 700 return apply_filters( 'bp_is_user_spammer', (bool) $is_spammer ); … … function bp_core_boot_spammer( $user ) { 973 980 974 981 // the user exists; now do a check to see if the user is a spammer 975 982 // if the user is a spammer, stop them in their tracks! 976 if ( is_a( $user, 'WP_User' ) && ( ( is_multisite() && (int) $user->spam ) || 1 == $user->user_status ) )983 if ( bp_is_user_spammer( $user ) ) { 977 984 return new WP_Error( 'invalid_username', __( '<strong>ERROR</strong>: Your account has been marked as a spammer.', 'buddypress' ) ); 985 } 978 986 979 987 // user is good to go! 980 988 return $user;