コード例 #1
0
ファイル: functions.php プロジェクト: sdh100shaun/pantheon
/**
 * Uninstall all bbPress options and capabilities from a specific site.
 *
 * @since bbPress (r3765)
 * @param type $site_id
 */
function bbp_do_uninstall($site_id = 0)
{
    if (empty($site_id)) {
        $site_id = get_current_blog_id();
    }
    switch_to_blog($site_id);
    bbp_delete_options();
    bbp_remove_caps();
    flush_rewrite_rules();
    restore_current_blog();
}
コード例 #2
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);
        }
    }
}
コード例 #3
0
ファイル: bbp-tools.php プロジェクト: hscale/webento
/**
 * Handle the processing and feedback of the admin tools page
 *
 * @since bbPress (r2613)
 *
 * @uses check_admin_referer() To verify the nonce and the referer
 * @uses wp_cache_flush() To flush the cache
 */
function bbp_admin_reset_handler()
{
    if ('post' == strtolower($_SERVER['REQUEST_METHOD']) && !empty($_POST['bbpress-are-you-sure'])) {
        check_admin_referer('bbpress-reset');
        global $wpdb;
        // Stores messages
        $messages = array();
        $failed = __('Failed', 'bbpress');
        $success = __('Success!', 'bbpress');
        // Flush the cache; things are about to get ugly.
        wp_cache_flush();
        /** Posts *************************************************************/
        $statement = __('Deleting Posts… %s', 'bbpress');
        $sql_posts = $wpdb->get_results("SELECT `ID` FROM `{$wpdb->posts}` WHERE `post_type` IN ('forum', 'topic', 'reply')", OBJECT_K);
        $sql_delete = "DELETE FROM `{$wpdb->posts}` WHERE `post_type` IN ('forum', 'topic', 'reply')";
        $result = is_wp_error($wpdb->query($sql_delete)) ? $failed : $success;
        $messages[] = sprintf($statement, $result);
        /** Post Meta *********************************************************/
        if (!empty($sql_posts)) {
            foreach ($sql_posts as $key => $value) {
                $sql_meta[] = $key;
            }
            $statement = __('Deleting Post Meta… %s', 'bbpress');
            $sql_meta = implode("', '", $sql_meta);
            $sql_delete = "DELETE FROM `{$wpdb->postmeta}` WHERE `post_id` IN ('{$sql_meta}');";
            $result = is_wp_error($wpdb->query($sql_delete)) ? $failed : $success;
            $messages[] = sprintf($statement, $result);
        }
        /** Topic Tags ********************************************************/
        // @todo
        /** User Meta *********************************************************/
        $statement = __('Deleting User Meta… %s', 'bbpress');
        $sql_delete = "DELETE FROM `{$wpdb->usermeta}` WHERE `meta_key` LIKE '%%_bbp_%%';";
        $result = is_wp_error($wpdb->query($sql_delete)) ? $failed : $success;
        $messages[] = sprintf($statement, $result);
        /** Converter *********************************************************/
        $statement = __('Deleting Conversion Table… %s', 'bbpress');
        $table_name = $wpdb->prefix . 'bbp_converter_translator';
        if ($wpdb->get_var("SHOW TABLES LIKE '{$table_name}'") == $table_name) {
            $wpdb->query("DROP TABLE {$table_name}");
            $result = $success;
        } else {
            $result = $failed;
        }
        $messages[] = sprintf($statement, $result);
        /** Options ***********************************************************/
        $statement = __('Deleting Settings… %s', 'bbpress');
        $sql_delete = bbp_delete_options();
        $messages[] = sprintf($statement, $success);
        /** Roles *************************************************************/
        $statement = __('Deleting Roles and Capabilities… %s', 'bbpress');
        $sql_delete = bbp_remove_roles();
        $sql_delete = bbp_remove_caps();
        $messages[] = sprintf($statement, $success);
        /** Output ************************************************************/
        if (count($messages)) {
            foreach ($messages as $message) {
                bbp_admin_tools_feedback($message);
            }
        }
    }
}