コード例 #1
0
ファイル: tools.php プロジェクト: joeyblake/bbpress
/**
 * Handle the processing and feedback of the admin tools page
 *
 * @since 2.0.0 bbPress (r2613)
 *
 * @uses check_admin_referer() To verify the nonce and the referer
 * @uses wp_cache_flush() To flush the cache
 * @uses bbp_get_forum_post_type() To get the forum post type
 * @uses bbp_get_topic_post_type() To get the topic post type
 * @uses bbp_get_reply_post_type() To get the reply post type
 */
function bbp_admin_reset_handler()
{
    // Bail if not resetting
    if (!bbp_is_post_request() || empty($_POST['bbpress-are-you-sure'])) {
        return;
    }
    // Only keymasters can proceed
    if (!bbp_is_user_keymaster()) {
        return;
    }
    check_admin_referer('bbpress-reset');
    // Stores messages
    $messages = array();
    $failed = __('Failed!', 'bbpress');
    $success = __('Success!', 'bbpress');
    // Flush the cache; things are about to get ugly.
    wp_cache_flush();
    /** Posts *****************************************************************/
    // Post types and status
    $fpt = bbp_get_forum_post_type();
    $tpt = bbp_get_topic_post_type();
    $rpt = bbp_get_reply_post_type();
    // Define variables
    $bbp_db = bbp_db();
    $statement = __('Deleting Posts… %s', 'bbpress');
    $sql_posts = $bbp_db->get_results("SELECT `ID` FROM `{$bbp_db->posts}` WHERE `post_type` IN ('{$fpt}', '{$tpt}', '{$rpt}')", OBJECT_K);
    $sql_delete = "DELETE FROM `{$bbp_db->posts}` WHERE `post_type` IN ('{$fpt}', '{$tpt}', '{$rpt}')";
    $result = is_wp_error($bbp_db->query($sql_delete)) ? $failed : $success;
    $messages[] = sprintf($statement, $result);
    /** Post Meta *************************************************************/
    if (!empty($sql_posts)) {
        $sql_meta = array();
        foreach ($sql_posts as $key => $value) {
            $sql_meta[] = $key;
        }
        $statement = __('Deleting Post Meta… %s', 'bbpress');
        $sql_meta = implode("', '", $sql_meta);
        $sql_delete = "DELETE FROM `{$bbp_db->postmeta}` WHERE `post_id` IN ('{$sql_meta}');";
        $result = is_wp_error($bbp_db->query($sql_delete)) ? $failed : $success;
        $messages[] = sprintf($statement, $result);
    }
    /** Forum moderators ******************************************************/
    $statement = __('Deleting Forum Moderators… %s', 'bbpress');
    $sql_delete = "DELETE a,b,c FROM `{$bbp_db->terms}` AS a LEFT JOIN `{$bbp_db->term_taxonomy}` AS c ON a.term_id = c.term_id LEFT JOIN `{$bbp_db->term_relationships}` AS b ON b.term_taxonomy_id = c.term_taxonomy_id WHERE c.taxonomy = 'forum-mod';";
    $result = is_wp_error($bbp_db->query($sql_delete)) ? $failed : $success;
    $messages[] = sprintf($statement, $result);
    /** Topic Tags ************************************************************/
    $statement = __('Deleting Topic Tags… %s', 'bbpress');
    $sql_delete = "DELETE a,b,c FROM `{$bbp_db->terms}` AS a LEFT JOIN `{$bbp_db->term_taxonomy}` AS c ON a.term_id = c.term_id LEFT JOIN `{$bbp_db->term_relationships}` AS b ON b.term_taxonomy_id = c.term_taxonomy_id WHERE c.taxonomy = 'topic-tag';";
    $result = is_wp_error($bbp_db->query($sql_delete)) ? $failed : $success;
    $messages[] = sprintf($statement, $result);
    /** User ******************************************************************/
    // First, if we're deleting previously imported users, delete them now
    if (!empty($_POST['bbpress-delete-imported-users'])) {
        $sql_users = $bbp_db->get_results("SELECT `user_id` FROM `{$bbp_db->usermeta}` WHERE `meta_key` = '_bbp_user_id'", OBJECT_K);
        if (!empty($sql_users)) {
            $sql_meta = array();
            foreach ($sql_users as $key => $value) {
                $sql_meta[] = $key;
            }
            $statement = __('Deleting User… %s', 'bbpress');
            $sql_meta = implode("', '", $sql_meta);
            $sql_delete = "DELETE FROM `{$bbp_db->users}` WHERE `ID` IN ('{$sql_meta}');";
            $result = is_wp_error($bbp_db->query($sql_delete)) ? $failed : $success;
            $messages[] = sprintf($statement, $result);
            $statement = __('Deleting User Meta… %s', 'bbpress');
            $sql_delete = "DELETE FROM `{$bbp_db->usermeta}` WHERE `user_id` IN ('{$sql_meta}');";
            $result = is_wp_error($bbp_db->query($sql_delete)) ? $failed : $success;
            $messages[] = sprintf($statement, $result);
        }
    }
    // Next, if we still have users that were not imported delete that meta data
    $statement = __('Deleting User Meta… %s', 'bbpress');
    $sql_delete = "DELETE FROM `{$bbp_db->usermeta}` WHERE `meta_key` LIKE '%%_bbp_%%';";
    $result = is_wp_error($bbp_db->query($sql_delete)) ? $failed : $success;
    $messages[] = sprintf($statement, $result);
    /** Converter *************************************************************/
    $statement = __('Deleting Conversion Table… %s', 'bbpress');
    $table_name = $bbp_db->prefix . 'bbp_converter_translator';
    if ($bbp_db->get_var("SHOW TABLES LIKE '{$table_name}'") === $table_name) {
        $bbp_db->query("DROP TABLE {$table_name}");
        $result = $success;
    } else {
        $result = $failed;
    }
    $messages[] = sprintf($statement, $result);
    /** Options ***************************************************************/
    $statement = __('Deleting Settings… %s', 'bbpress');
    bbp_delete_options();
    $messages[] = sprintf($statement, $success);
    /** Roles *****************************************************************/
    $statement = __('Deleting Roles and Capabilities… %s', 'bbpress');
    bbp_remove_roles();
    bbp_remove_caps();
    $messages[] = sprintf($statement, $success);
    /** Output ****************************************************************/
    if (count($messages)) {
        foreach ($messages as $message) {
            bbp_admin_tools_feedback($message);
        }
    }
}
コード例 #2
0
/**
 * Query the DB and get a the child id's of all children
 *
 * @since 2.0.0 bbPress (r3325)
 *
 * @param int $parent_id  Parent id
 * @param string $post_type Post type. Defaults to 'post'
 * @uses wp_cache_get() To check if there is a cache of the children
 * @uses bbp_get_public_status_id() To get the public status id
 * @uses bbp_get_private_status_id() To get the private status id
 * @uses bbp_get_hidden_status_id() To get the hidden status id
 * @uses bbp_get_pending_status_id() To get the pending status id
 * @uses bbp_get_closed_status_id() To get the closed status id
 * @uses bbp_get_trash_status_id() To get the trash status id
 * @uses bbp_get_spam_status_id() To get the spam status id
 * @uses bbp_get_forum_post_type() To get the forum post type
 * @uses bbp_get_topic_post_type() To get the topic post type
 * @uses bbp_get_reply_post_type() To get the reply post type
 * @uses wpdb::prepare() To prepare the query
 * @uses wpdb::get_col() To get the result of the query in an array
 * @uses wp_cache_set() To set the cache for future use
 * @uses apply_filters() Calls 'bbp_get_all_child_ids' with the child ids,
 *                        parent id and post type
 * @return array The array of children
 */
function bbp_get_all_child_ids($parent_id = 0, $post_type = 'post')
{
    // Bail if nothing passed
    if (empty($parent_id)) {
        return false;
    }
    // The ID of the cached query
    $cache_id = 'bbp_parent_all_' . $parent_id . '_type_' . $post_type . '_child_ids';
    // Check for cache and set if needed
    $child_ids = wp_cache_get($cache_id, 'bbpress_posts');
    if (false === $child_ids) {
        $post_status = array(bbp_get_public_status_id());
        // Extra post statuses based on post type
        switch ($post_type) {
            // Forum
            case bbp_get_forum_post_type():
                $post_status[] = bbp_get_private_status_id();
                $post_status[] = bbp_get_hidden_status_id();
                break;
                // Topic
            // Topic
            case bbp_get_topic_post_type():
                $post_status[] = bbp_get_pending_status_id();
                $post_status[] = bbp_get_closed_status_id();
                $post_status[] = bbp_get_trash_status_id();
                $post_status[] = bbp_get_spam_status_id();
                break;
                // Reply
            // Reply
            case bbp_get_reply_post_type():
                $post_status[] = bbp_get_pending_status_id();
                $post_status[] = bbp_get_trash_status_id();
                $post_status[] = bbp_get_spam_status_id();
                break;
        }
        // Join post statuses together
        $post_status = "'" . implode("', '", $post_status) . "'";
        $bbp_db = bbp_db();
        $query = $bbp_db->prepare("SELECT ID FROM {$bbp_db->posts} WHERE post_parent = %d AND post_status IN ( {$post_status} ) AND post_type = '%s' ORDER BY ID DESC;", $parent_id, $post_type);
        $child_ids = (array) $bbp_db->get_col($query);
        wp_cache_set($cache_id, $child_ids, 'bbpress_posts');
    } else {
        $child_ids = (array) $child_ids;
    }
    // Filter and return
    return (array) apply_filters('bbp_get_all_child_ids', $child_ids, $parent_id, $post_type);
}
コード例 #3
0
ファイル: admin.php プロジェクト: CompositeUK/clone.bbPress
        /**
         * Update all bbPress forums across all sites
         *
         * @since 2.1.0 bbPress (r3689)
         *
         * @uses get_blog_option()
         * @uses wp_remote_get()
         */
        public static function network_update_screen()
        {
            $bbp_db = bbp_db();
            // Get action
            $action = isset($_GET['action']) ? $_GET['action'] : '';
            ?>

		<div class="wrap">
			<h1><?php 
            esc_html_e('Update Forums', 'bbpress');
            ?>
</h1>

		<?php 
            // Taking action
            switch ($action) {
                case 'bbpress-update':
                    // Site counter
                    $n = isset($_GET['n']) ? intval($_GET['n']) : 0;
                    // Get blogs 5 at a time
                    $blogs = $bbp_db->get_results("SELECT * FROM {$bbp_db->blogs} WHERE site_id = '{$bbp_db->siteid}' AND spam = '0' AND deleted = '0' AND archived = '0' ORDER BY registered DESC LIMIT {$n}, 5", ARRAY_A);
                    // No blogs so all done!
                    if (empty($blogs)) {
                        ?>

					<p><?php 
                        esc_html_e('All done!', 'bbpress');
                        ?>
</p>
					<a class="button" href="update-core.php?page=bbpress-update"><?php 
                        esc_html_e('Go Back', 'bbpress');
                        ?>
</a>

				<?php 
                        // Still have sites to loop through
                    } else {
                        ?>

					<ul>

						<?php 
                        foreach ((array) $blogs as $details) {
                            $siteurl = get_blog_option($details['blog_id'], 'siteurl');
                            ?>

							<li><?php 
                            echo $siteurl;
                            ?>
</li>

							<?php 
                            // Get the response of the bbPress update on this site
                            $response = wp_remote_get(trailingslashit($siteurl) . 'wp-admin/index.php?page=bbp-update&action=bbp-update', array('timeout' => 30, 'httpversion' => '1.1'));
                            // Site errored out, no response?
                            if (is_wp_error($response)) {
                                wp_die(sprintf(__('Warning! Problem updating %1$s. Your server may not be able to connect to sites running on it. Error message: %2$s', 'bbpress'), $siteurl, '<em>' . $response->get_error_message() . '</em>'));
                            }
                            // Switch to the new blog
                            switch_to_blog($details['blog_id']);
                            $basename = bbpress()->basename;
                            // Run the updater on this site
                            if (is_plugin_active_for_network($basename) || is_plugin_active($basename)) {
                                bbp_version_updater();
                            }
                            // restore original blog
                            restore_current_blog();
                            // Do some actions to allow plugins to do things too
                            do_action('after_bbpress_upgrade', $response);
                            do_action('bbp_upgrade_site', $details['blog_id']);
                        }
                        ?>

					</ul>

					<p>
						<?php 
                        esc_html_e('If your browser doesn&#8217;t start loading the next page automatically, click this link:', 'bbpress');
                        ?>
						<a class="button" href="update-core.php?page=bbpress-update&amp;action=bbpress-update&amp;n=<?php 
                        echo $n + 5;
                        ?>
"><?php 
                        esc_html_e('Next Forums', 'bbpress');
                        ?>
</a>
					</p>
					<script type='text/javascript'>
						<!--
						function nextpage() {
							location.href = 'update-core.php?page=bbpress-update&action=bbpress-update&n=<?php 
                        echo $n + 5;
                        ?>
';
						}
						setTimeout( 'nextpage()', 250 );
						//-->
					</script><?php 
                    }
                    break;
                case 'show':
                default:
                    ?>

				<p><?php 
                    esc_html_e('You can update all the forums on your network through this page. It works by calling the update script of each site automatically. Hit the link below to update.', 'bbpress');
                    ?>
</p>
				<p><a class="button" href="update-core.php?page=bbpress-update&amp;action=bbpress-update"><?php 
                    esc_html_e('Update Forums', 'bbpress');
                    ?>
</a></p>

			<?php 
                    break;
            }
            ?>

		</div><?php 
        }
コード例 #4
0
/**
 * Adjust the total anonymous reply count of a topic
 *
 * @since 2.0.0 bbPress (r2567)
 *
 * @param int $topic_id Optional. Topic id to update
 * @uses bbp_is_reply() To check if the passed topic id is a reply
 * @uses bbp_get_reply_topic_id() To get the reply topic id
 * @uses bbp_get_topic_id() To get the topic id
 * @uses bbp_get_reply_topic_id() To get the reply topic id
 * @uses bbp_get_reply_post_type() To get the reply post type
 * @uses bbp_get_topic_post_type() To get the topic post type
 * @uses wpdb::prepare() To prepare our sql query
 * @uses wpdb::get_var() To execute our query and get the column back
 * @uses update_post_meta() To update the topic anonymous reply count meta
 * @uses apply_filters() Calls 'bbp_update_topic_anonymous_reply_count' with the
 *                        anonymous reply count and topic id
 * @return int Anonymous reply count
 */
function bbp_update_topic_anonymous_reply_count($topic_id = 0)
{
    // If it's a reply, then get the parent (topic id)
    if (bbp_is_reply($topic_id)) {
        $topic_id = bbp_get_reply_topic_id($topic_id);
    } elseif (bbp_is_topic($topic_id)) {
        $topic_id = bbp_get_topic_id($topic_id);
    } else {
        return;
    }
    // Query the DB to get anonymous replies in this topic
    $bbp_db = bbp_db();
    $query = $bbp_db->prepare("SELECT COUNT( ID ) FROM {$bbp_db->posts} WHERE ( post_parent = %d AND post_status = '%s' AND post_type = '%s' AND post_author = 0 ) OR ( ID = %d AND post_type = '%s' AND post_author = 0 );", $topic_id, bbp_get_public_status_id(), bbp_get_reply_post_type(), $topic_id, bbp_get_topic_post_type());
    $replies = (int) $bbp_db->get_var($query);
    update_post_meta($topic_id, '_bbp_anonymous_reply_count', $replies);
    return (int) apply_filters('bbp_update_topic_anonymous_reply_count', $replies, $topic_id);
}
コード例 #5
0
/**
 * Helper function to add filter to option_wp_user_roles
 *
 * @since 2.2.0 bbPress (r4363)
 * @deprecated 2.6.0 bbPress (r6105)
 *
 * @see _bbp_reinit_dynamic_roles()
 */
function bbp_filter_user_roles_option()
{
    $role_key = bbp_db()->prefix . 'user_roles';
    add_filter('option_' . $role_key, '_bbp_reinit_dynamic_roles');
}
コード例 #6
0
 private function setup_globals()
 {
     /** Get database connections ******************************************/
     $this->wpdb = bbp_db();
     $this->max_rows = (int) $_POST['_bbp_converter_rows'];
     $this->opdb = new wpdb($_POST['_bbp_converter_db_user'], $_POST['_bbp_converter_db_pass'], $_POST['_bbp_converter_db_name'], $_POST['_bbp_converter_db_server']);
     $this->opdb->prefix = $_POST['_bbp_converter_db_prefix'];
     /**
      * Error Reporting
      */
     $this->wpdb->show_errors();
     $this->opdb->show_errors();
     /**
      * Syncing
      */
     $this->sync_table_name = $this->wpdb->prefix . 'bbp_converter_translator';
     if ($this->wpdb->get_var("SHOW TABLES LIKE '" . $this->sync_table_name . "'") == $this->sync_table_name) {
         $this->sync_table = true;
     } else {
         $this->sync_table = false;
     }
     /**
      * Charset
      */
     if (empty($this->wpdb->charset)) {
         $this->charset = 'UTF8';
     } else {
         $this->charset = $this->wpdb->charset;
     }
     /**
      * Default mapping.
      */
     /** Forum Section *****************************************************/
     $this->field_map[] = array('to_type' => 'forum', 'to_fieldname' => 'post_status', 'default' => 'publish');
     $this->field_map[] = array('to_type' => 'forum', 'to_fieldname' => 'comment_status', 'default' => 'closed');
     $this->field_map[] = array('to_type' => 'forum', 'to_fieldname' => 'ping_status', 'default' => 'closed');
     $this->field_map[] = array('to_type' => 'forum', 'to_fieldname' => 'post_type', 'default' => 'forum');
     /** Topic Section *****************************************************/
     $this->field_map[] = array('to_type' => 'topic', 'to_fieldname' => 'post_status', 'default' => 'publish');
     $this->field_map[] = array('to_type' => 'topic', 'to_fieldname' => 'comment_status', 'default' => 'closed');
     $this->field_map[] = array('to_type' => 'topic', 'to_fieldname' => 'ping_status', 'default' => 'closed');
     $this->field_map[] = array('to_type' => 'topic', 'to_fieldname' => 'post_type', 'default' => 'topic');
     /** Post Section ******************************************************/
     $this->field_map[] = array('to_type' => 'reply', 'to_fieldname' => 'post_status', 'default' => 'publish');
     $this->field_map[] = array('to_type' => 'reply', 'to_fieldname' => 'comment_status', 'default' => 'closed');
     $this->field_map[] = array('to_type' => 'reply', 'to_fieldname' => 'ping_status', 'default' => 'closed');
     $this->field_map[] = array('to_type' => 'reply', 'to_fieldname' => 'post_type', 'default' => 'reply');
     /** User Section ******************************************************/
     $this->field_map[] = array('to_type' => 'user', 'to_fieldname' => 'role', 'default' => get_option('default_role'));
 }
コード例 #7
0
/**
 * Mark the forum as hidden
 *
 * @since 2.0.0 bbPress (r2996)
 *
 * @param int $forum_id Optional. Forum id
 * @uses update_post_meta() To update the forum private meta
 * @return bool False on failure, true on success
 */
function bbp_hide_forum($forum_id = 0, $current_visibility = '')
{
    $forum_id = bbp_get_forum_id($forum_id);
    do_action('bbp_hide_forum', $forum_id);
    // Only run queries if visibility is changing
    if (bbp_get_hidden_status_id() !== $current_visibility) {
        // Get private forums
        $private = bbp_get_private_forum_ids();
        // Find this forum in the array
        if (in_array($forum_id, $private)) {
            $offset = array_search($forum_id, $private);
            // Splice around it
            array_splice($private, $offset, 1);
            // Update private forums minus this one
            update_option('_bbp_private_forums', array_unique(array_filter(array_values($private))));
        }
        // Add to '_bbp_hidden_forums' site option
        $hidden = bbp_get_hidden_forum_ids();
        $hidden[] = $forum_id;
        update_option('_bbp_hidden_forums', array_unique(array_filter(array_values($hidden))));
        // Update forums visibility setting
        $bbp_db = bbp_db();
        $bbp_db->update($bbp_db->posts, array('post_status' => bbp_get_hidden_status_id()), array('ID' => $forum_id));
        wp_transition_post_status(bbp_get_hidden_status_id(), $current_visibility, get_post($forum_id));
        bbp_clean_post_cache($forum_id);
    }
    do_action('bbp_hid_forum', $forum_id);
    return $forum_id;
}
コード例 #8
0
/**
 * Convert passwords from previous platfrom encryption to WordPress encryption.
 *
 * @since 2.1.0 bbPress (r3813)
 */
function bbp_user_maybe_convert_pass()
{
    // Sanitize username
    $username = !empty($_POST['log']) ? sanitize_user($_POST['log']) : '';
    // Bail if no username
    if (empty($username)) {
        return;
    }
    // Bail if no user password to convert
    $bbp_db = bbp_db();
    $query = $bbp_db->prepare("SELECT * FROM {$bbp_db->users} INNER JOIN {$bbp_db->usermeta} ON user_id = ID WHERE meta_key = '_bbp_class' AND user_login = '******' LIMIT 1", $username);
    $row = $bbp_db->get_row($query);
    if (empty($row) || is_wp_error($row)) {
        return;
    }
    // Setup admin (to include converter)
    require_once bbpress()->includes_dir . 'admin/admin.php';
    // Create the admin object
    bbp_admin();
    // Convert password
    require_once bbpress()->admin->admin_dir . 'converter.php';
    require_once bbpress()->admin->admin_dir . 'converters/' . $row->meta_value . '.php';
    // Create the converter
    $converter = bbp_new_converter($row->meta_value);
    // Try to call the conversion method
    if (is_a($converter, 'BBP_Converter_Base') && method_exists($converter, 'callback_pass')) {
        $converter->callback_pass($username, $_POST['pwd']);
    }
}
コード例 #9
0
/**
 * Used by bbp_has_replies() to add the lead topic post to the posts loop
 *
 * This function filters the 'post_where' of the WP_Query, and changes the query
 * to include both the topic AND its children in the same loop.
 *
 * @since 2.1.0 bbPress (r4058)
 *
 * @param string $where
 * @return string
 */
function _bbp_has_replies_where($where = '', $query = false)
{
    /** Bail ******************************************************************/
    // Bail if the sky is falling
    if (empty($where) || empty($query)) {
        return $where;
    }
    // Bail if no post_parent to replace
    if (!is_numeric($query->get('post_parent'))) {
        return $where;
    }
    // Bail if not a topic and reply query
    if (array(bbp_get_topic_post_type(), bbp_get_reply_post_type()) !== $query->get('post_type')) {
        return $where;
    }
    // Bail if including specific post ID's
    if ($query->get('post__in')) {
        return $where;
    }
    /** Proceed ***************************************************************/
    // Table name for posts
    $table_name = bbp_db()->prefix . 'posts';
    // Get the topic ID from the post_parent, set in bbp_has_replies()
    $topic_id = bbp_get_topic_id($query->get('post_parent'));
    // The texts to search for
    $search = array("FROM {$table_name} ", "WHERE 1=1  AND {$table_name}.post_parent = {$topic_id}", ") AND {$table_name}.post_parent = {$topic_id}");
    // The texts to replace them with
    $replace = array($search[0] . "FORCE INDEX (PRIMARY, post_parent) ", "WHERE 1=1 AND ({$table_name}.ID = {$topic_id} OR {$table_name}.post_parent = {$topic_id})", ") AND ({$table_name}.ID = {$topic_id} OR {$table_name}.post_parent = {$topic_id})");
    // Try to replace the search text with the replacement
    $new_where = str_replace($search, $replace, $where);
    if (!empty($new_where)) {
        $where = $new_where;
    }
    return $where;
}
コード例 #10
0
ファイル: capabilities.php プロジェクト: joeyblake/bbpress
/**
 * Mark a users topics and replies as spam when the user is marked as spam
 *
 * @since 2.0.0 bbPress (r3405)
 *
 * @param int $user_id Optional. User ID to unspam. Defaults to displayed user.
 *
 * @uses bbp_is_single_user()
 * @uses bbp_is_user_home()
 * @uses bbp_get_displayed_user_id()
 * @uses bbp_is_user_keymaster()
 * @uses get_blogs_of_user()
 * @uses bbp_get_topic_post_type()
 * @uses bbp_get_reply_post_type()
 * @uses switch_to_blog()
 * @uses get_post_type()
 * @uses bbp_unspam_topic()
 * @uses bbp_unspam_reply()
 * @uses restore_current_blog()
 *
 * @return If no user ID passed
 */
function bbp_make_ham_user($user_id = 0)
{
    // Use displayed user if it's not yourself
    if (empty($user_id) && bbp_is_single_user() && !bbp_is_user_home()) {
        $user_id = bbp_get_displayed_user_id();
    }
    // Bail if no user ID
    if (empty($user_id)) {
        return false;
    }
    // Bail if user ID is keymaster
    if (bbp_is_user_keymaster($user_id)) {
        return false;
    }
    // Arm the torpedos
    $bbp_db = bbp_db();
    // Get the blog IDs of the user to mark as spam
    $blogs = get_blogs_of_user($user_id, true);
    // If user has no blogs, they are a guest on this site
    if (empty($blogs)) {
        $blogs[$bbp_db->blogid] = array();
    }
    // Make array of post types to mark as spam
    $post_types = array(bbp_get_topic_post_type(), bbp_get_reply_post_type());
    $post_types = "'" . implode("', '", $post_types) . "'";
    // Loop through blogs and remove their posts
    foreach ((array) array_keys($blogs) as $blog_id) {
        // Switch to the blog ID
        switch_to_blog($blog_id);
        // Get topics and replies
        $query = $bbp_db->prepare("SELECT ID FROM {$bbp_db->posts} WHERE post_author = %d AND post_status = '%s' AND post_type IN ( {$post_types} )", $user_id, bbp_get_spam_status_id());
        $posts = $bbp_db->get_col($query);
        // Loop through posts and spam them
        if (!empty($posts)) {
            foreach ($posts as $post_id) {
                // The routines for topics ang replies are different, so use the
                // correct one based on the post type
                switch (get_post_type($post_id)) {
                    case bbp_get_topic_post_type():
                        bbp_unspam_topic($post_id);
                        break;
                    case bbp_get_reply_post_type():
                        bbp_unspam_reply($post_id);
                        break;
                }
            }
        }
        // Switch back to current blog
        restore_current_blog();
    }
    // Success
    return true;
}