bp_core_process_spammer_status( int $user_id, string $status, bool $do_wp_cleanup = true )
Process a spammed or unspammed user.
Description
This function is called from three places:
- in bp_settings_action_capabilities() (from the front-end)
- by bp_core_mark_user_spam_admin() (from wp-admin)
- bp_core_mark_user_ham_admin() (from wp-admin)
Parameters
- $user_id
-
(Required) The ID of the user being spammed/hammed.
- $status
-
(Required) 'spam' if being marked as spam, 'ham' otherwise.
- $do_wp_cleanup
-
(Optional) True to force the cleanup of WordPress content and status, otherwise false. Generally, this should only be false if WordPress is expected to have performed this cleanup independently, as when hooked to 'make_spam_user'.
Default value: true
Return
(bool) True on success, false on failure.
Source
File: bp-members/bp-members-functions.php
745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 | function bp_core_process_spammer_status( $user_id , $status , $do_wp_cleanup = true ) { global $wpdb ; // Bail if no user ID. if ( empty ( $user_id ) ) { return ; } // Bail if user ID is super admin. if ( is_super_admin( $user_id ) ) { return ; } // Get the functions file. if ( is_multisite() ) { require_once ( ABSPATH . 'wp-admin/includes/ms.php' ); } $is_spam = ( 'spam' == $status ); // Only you can prevent infinite loops. remove_action( 'make_spam_user' , 'bp_core_mark_user_spam_admin' ); remove_action( 'make_ham_user' , 'bp_core_mark_user_ham_admin' ); // Force the cleanup of WordPress content and status for multisite configs. if ( $do_wp_cleanup ) { // Get the blogs for the user. $blogs = get_blogs_of_user( $user_id , true ); foreach ( ( array ) array_values ( $blogs ) as $details ) { // Do not mark the main or current root blog as spam. if ( 1 == $details ->userblog_id || bp_get_root_blog_id() == $details ->userblog_id ) { continue ; } // Update the blog status. update_blog_status( $details ->userblog_id, 'spam' , $is_spam ); } // Finally, mark this user as a spammer. if ( is_multisite() ) { update_user_status( $user_id , 'spam' , $is_spam ); } } // Update the user status. $wpdb ->update( $wpdb ->users, array ( 'user_status' => $is_spam ), array ( 'ID' => $user_id ) ); // Clean user cache. clean_user_cache( $user_id ); if ( ! is_multisite() ) { // Call multisite actions in single site mode for good measure. if ( true === $is_spam ) { /** * Fires at end of processing spammer in Dashboard if not multisite and user is spam. * * @since BuddyPress 1.5.0 * * @param int $value user ID. */ do_action( 'make_spam_user' , $user_id ); } else { /** * Fires at end of processing spammer in Dashboard if not multisite and user is not spam. * * @since BuddyPress 1.5.0 * * @param int $value user ID. */ do_action( 'make_ham_user' , $user_id ); } } // Hide this user's activity. if ( ( true === $is_spam ) && bp_is_active( 'activity' ) ) { bp_activity_hide_user_activity( $user_id ); } // We need a special hook for is_spam so that components can delete data at spam time. if ( true === $is_spam ) { /** * Fires at the end of the process spammer process if the user is spam. * * @since BuddyPress 1.5.0 * * @param int $value Displayed user ID. */ do_action( 'bp_make_spam_user' , $user_id ); } else { /** * Fires at the end of the process spammer process if the user is not spam. * * @since BuddyPress 1.5.0 * * @param int $value Displayed user ID. */ do_action( 'bp_make_ham_user' , $user_id ); } /** * Fires at the end of the process for hanlding spammer status. * * @since BuddyPress 1.5.5 * * @param int $user_id ID of the processed user. * @param bool $is_spam The determined spam status of processed user. */ do_action( 'bp_core_process_spammer_status' , $user_id , $is_spam ); // Put things back how we found them. add_action( 'make_spam_user' , 'bp_core_mark_user_spam_admin' ); add_action( 'make_ham_user' , 'bp_core_mark_user_ham_admin' ); return true; } |
Changelog
Version | Description |
---|---|
BuddyPress 1.6.0 | Introduced. |
Questions?
We're always happy to help with code or other questions you might have! Search our developer docs, contact support, or connect with our sales team.