bp_core_process_spammer_status( int $user_id, string $status, bool $do_wp_cleanup = true )
Process a spammed or unspammed user.
Description 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 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 Return
(bool) True on success, false on failure.
Source Source
File: bp-members/bp-members-functions.php
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. bp_core_update_member_status( $user_id, $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 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 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 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 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 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 Changelog
Version | Description |
---|---|
1.6.0 | Introduced. |