/**
 * Process a spammed or unspammed user.
 *
 * 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)
 *
 * @since 1.6.0
 *
 * @param int    $user_id       The ID of the user being spammed/hammed.
 * @param string $status        'spam' if being marked as spam, 'ham' otherwise.
 * @param bool   $do_wp_cleanup 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'.
 * @return bool True on success, false on failure.
 */
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 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;
}
/**
 * Processes a spammed or unspammed user
 *
 * This function is called in three ways:
 *  - 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)
 *
 * @since BuddyPress (1.6)
 *
 * @param int $user_id The user being spammed/hammed
 * @param string $status 'spam' if being marked as spam, 'ham' otherwise
 */
function bp_core_process_spammer_status($user_id, $status)
{
    global $wpdb;
    // Only super admins can currently spam users
    if (!is_super_admin() || bp_is_my_profile()) {
        return;
    }
    // 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');
    // When marking as spam in the Dashboard, these actions are handled by WordPress
    if (!is_admin()) {
        // Get the blogs for the user
        $blogs = get_blogs_of_user($user_id, true);
        foreach ((array) $blogs as $key => $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);
        }
        // Always set single site status
        $wpdb->update($wpdb->users, array('user_status' => $is_spam), array('ID' => $user_id));
        // Call multisite actions in single site mode for good measure
        if (!is_multisite()) {
            $wp_action = true === $is_spam ? 'make_spam_user' : 'make_ham_user';
            do_action($wp_action, bp_displayed_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
    $bp_action = true === $is_spam ? 'bp_make_spam_user' : 'bp_make_ham_user';
    do_action($bp_action, $user_id);
    // Allow plugins to do neat things
    do_action('bp_core_process_spammer_status', $user_id, $is_spam);
    return true;
}
 /**
  * set spammeer status
  *
  * @param <int|array> $user_ids member ids
  * @param <bool> $is_spam mark spammer (true) or unmark (false)
  * @param <callback> $end_callback function to execute after marking/unmarking, after this bpcore will redirect back & die
  */
 function set_spammer_status($user_ids, $is_spam, $end_callback)
 {
     global $wpdb;
     $user_ids = (array) $user_ids;
     $successes = array();
     foreach ($user_ids as $user_id) {
         // Bail if user ID is super admin
         if (is_super_admin($user_id)) {
             continue;
         }
         // Get the blogs for the user
         $blogs = get_blogs_of_user($user_id, true);
         foreach ((array) $blogs as $key => $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);
         }
         // Always set single site status
         $wpdb->update($wpdb->users, array('user_status' => (int) $is_spam), array('ID' => $user_id));
         // Hide this user's activity
         if ($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
         $bp_action = $is_spam ? 'bp_make_spam_user' : 'bp_make_ham_user';
         do_action($bp_action, $user_id);
         // Call multisite actions in single site mode for good measure
         if (!is_multisite()) {
             $wp_action = $is_spam ? 'make_spam_user' : 'make_ham_user';
             do_action($wp_action, $user_id);
         }
         // Allow plugins to do neat things
         do_action('bp_core_action_set_spammer_status', $user_id, $is_spam);
         $successes[] = $user_id;
     }
     $errors = array_diff($user_ids, $successes);
     call_user_func($end_callback, $successes, $errors, $is_spam);
 }
Beispiel #4
0
/**
 * Process a spammed or unspammed user.
 *
 * 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)
 *
 * @since BuddyPress (1.6.0)
 *
 * @param int $user_id The ID of the user being spammed/hammed.
 * @param string $status 'spam' if being marked as spam, 'ham' otherwise.
 * @param bool $do_wp_cleanup 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'.
 * @return bool True on success, false on failure.
 */
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');
    // Determine if we are on an admin page
    $is_admin = is_admin();
    if ($is_admin && !defined('DOING_AJAX')) {
        $is_admin = (bool) (buddypress()->members->admin->user_page !== get_current_screen()->id);
    }
    // When marking as spam in the Dashboard, these actions are handled by WordPress
    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);
        }
        // Always set single site status
        $wpdb->update($wpdb->users, array('user_status' => $is_spam), array('ID' => $user_id));
        // Call multisite actions in single site mode for good measure
        if (!is_multisite()) {
            $wp_action = true === $is_spam ? 'make_spam_user' : 'make_ham_user';
            do_action($wp_action, bp_displayed_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
    $bp_action = true === $is_spam ? 'bp_make_spam_user' : 'bp_make_ham_user';
    do_action($bp_action, $user_id);
    // Allow plugins to do neat things
    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;
}
/**
 * When a site admin selects "Mark as Spammer/Not Spammer" from the admin menu
 * this action will fire and mark or unmark the user and their blogs as spam.
 * Must be a site admin for this function to run.
 *
 * @package BuddyPress Core
 * @param int $user_id Optional user ID to mark as spam
 * @global object $wpdb Global WordPress Database object
 */
function bp_core_action_set_spammer_status($user_id = 0)
{
    global $wpdb;
    // Only super admins can currently spam users
    if (!is_super_admin() || bp_is_my_profile()) {
        return;
    }
    // Use displayed user if it's not yourself
    if (empty($user_id) && bp_is_user()) {
        $user_id = bp_displayed_user_id();
    }
    // Bail if no user ID
    if (empty($user_id)) {
        return;
    }
    // Bail if user ID is super admin
    if (is_super_admin($user_id)) {
        return;
    }
    if (bp_is_current_component('admin') && in_array(bp_current_action(), array('mark-spammer', 'unmark-spammer'))) {
        // Check the nonce
        check_admin_referer('mark-unmark-spammer');
        // Get the functions file
        if (is_multisite()) {
            require ABSPATH . 'wp-admin/includes/ms.php';
        }
        // To spam or not to spam
        $is_spam = bp_is_current_action('mark-spammer') ? 1 : 0;
        // Get the blogs for the user
        $blogs = get_blogs_of_user($user_id, true);
        foreach ((array) $blogs as $key => $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);
        }
        // Always set single site status
        $wpdb->update($wpdb->users, array('user_status' => $is_spam), array('ID' => $user_id));
        // Add feedback message
        if ($is_spam) {
            bp_core_add_message(__('User marked as spammer. Spam users are visible only to site admins.', 'buddypress'));
        } else {
            bp_core_add_message(__('User removed as spammer.', 'buddypress'));
        }
        // Hide this user's activity
        if ($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
        $bp_action = $is_spam ? 'bp_make_spam_user' : 'bp_make_ham_user';
        do_action($bp_action, bp_displayed_user_id());
        // Call multisite actions in single site mode for good measure
        if (!is_multisite()) {
            $wp_action = $is_spam ? 'make_spam_user' : 'make_ham_user';
            do_action($wp_action, bp_displayed_user_id());
        }
        // Allow plugins to do neat things
        do_action('bp_core_action_set_spammer_status', bp_displayed_user_id(), $is_spam);
        // Redirect back to where we came from
        bp_core_redirect(wp_get_referer());
    }
}
Beispiel #6
0
/**
 * bp_core_action_set_spammer_status()
 *
 * When a site admin selects "Mark as Spammer/Not Spammer" from the admin menu
 * this action will fire and mark or unmark the user and their blogs as spam.
 * Must be a site admin for this function to run.
 *
 * @package BuddyPress Core
 * @global $bp The global BuddyPress settings variable created in bp_core_setup_globals()
 */
function bp_core_action_set_spammer_status() {
	global $bp, $wpdb, $wp_version;

	if ( !is_super_admin() || bp_is_my_profile() || !$bp->displayed_user->id )
		return false;

	if ( 'admin' == $bp->current_component && ( 'mark-spammer' == $bp->current_action || 'unmark-spammer' == $bp->current_action ) ) {
		/* Check the nonce */
		check_admin_referer( 'mark-unmark-spammer' );

		/* Get the functions file */
		if ( bp_core_is_multisite() ) {
			if ( $wp_version >= '3.0' )
				require_once( ABSPATH . '/wp-admin/includes/ms.php' );
			else
				require_once( ABSPATH . '/wp-admin/includes/mu.php' );
		}

		if ( 'mark-spammer' == $bp->current_action )
			$is_spam = 1;
		else
			$is_spam = 0;

		/* Get the blogs for the user */
		$blogs = get_blogs_of_user( $bp->displayed_user->id, true );

		foreach ( (array) $blogs as $key => $details ) {
			/* Do not mark the main or current root blog as spam */
			if ( 1 == $details->userblog_id || BP_ROOT_BLOG == $details->userblog_id )
				continue;

			/* Update the blog status */
			update_blog_status( $details->userblog_id, 'spam', $is_spam );

			/* Fire the standard WPMU hook */
			do_action( 'make_spam_blog', $details->userblog_id );
		}

		/* Finally, mark this user as a spammer */
		if ( bp_core_is_multisite() )
			$wpdb->update( $wpdb->users, array( 'spam' => $is_spam ), array( 'ID' => $bp->displayed_user->id ) );

		$wpdb->update( $wpdb->users, array( 'user_status' => $is_spam ), array( 'ID' => $bp->displayed_user->id ) );

		if ( $is_spam )
			bp_core_add_message( __( 'User marked as spammer. Spam users are visible only to site admins.', 'buddypress' ) );
		else
			bp_core_add_message( __( 'User removed as spammer.', 'buddypress' ) );

		/* Hide this user's activity */
		if ( $is_spam && function_exists( 'bp_activity_hide_user_activity' ) )
			bp_activity_hide_user_activity( $bp->displayed_user->id );

		do_action( 'bp_core_action_set_spammer_status', $bp->displayed_user->id, $is_spam );

		bp_core_redirect( wp_get_referer() );
	}
}