/** * 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(); }
/** * 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); } } }
/** * Update all bbPress forums across all sites * * @since bbPress (r3689) * * @global WPDB $wpdb * @uses get_blog_option() * @uses wp_remote_get() */ public static function update_screen() { // Get action $action = isset($_GET['action']) ? $_GET['action'] : ''; ?> <div class="wrap"> <div id="icon-edit" class="icon32 icon32-posts-topic"><br /></div> <h2><?php _e('Update Forum', 'bbpress'); ?> </h2> <?php // Taking action switch ($action) { case 'bbpress-update': // @todo more update stuff here, evaluate performance // Remove roles and caps bbp_remove_roles(); bbp_remove_caps(); // Make sure roles, capabilities, and options exist bbp_add_roles(); bbp_add_caps(); bbp_add_options(); // Ensure any new permalinks are created flush_rewrite_rules(); // Ensure proper version in the DB bbp_version_bump(); ?> <p><?php _e('All done!', 'bbpress'); ?> </p> <a class="button" href="index.php?page=bbpress-update"><?php _e('Go Back', 'bbpress'); ?> </a> <?php break; case 'show': default: ?> <p><?php _e('You can update your forum through this page. Hit the link below to update.', 'bbpress'); ?> </p> <p><a class="button" href="index.php?page=bbpress-update&action=bbpress-update"><?php _e('Update Forum', 'bbpress'); ?> </a></p> <?php break; } ?> </div><?php }
/** * bbPress's version updater looks at what the current database version is, and * runs whatever other code is needed. * * This is most-often used when the data schema changes, but should also be used * to correct issues with bbPress meta-data silently on software update. * * @since bbPress (r4104) */ function bbp_version_updater() { // Get the raw database version $raw_db_version = (int) bbp_get_db_version_raw(); /** 2.0 Branch ************************************************************/ // 2.0, 2.0.1, 2.0.2, 2.0.3 if ($raw_db_version < 200) { // No changes } /** 2.1 Branch ************************************************************/ // 2.1, 2.1.1 if ($raw_db_version < 211) { /** * Repair private and hidden forum data * * @link http://bbpress.trac.wordpress.org/ticket/1891 */ bbp_admin_repair_forum_visibility(); } /** 2.2 Branch ************************************************************/ // 2.2 if ($raw_db_version < 220) { // Remove the Moderator role from the database remove_role(bbp_get_moderator_role()); // Remove the Participant role from the database remove_role(bbp_get_participant_role()); // Remove capabilities bbp_remove_caps(); } /** 2.3 Branch ************************************************************/ // 2.3 if ($raw_db_version < 230) { // No changes } /** All done! *************************************************************/ // Bump the version bbp_version_bump(); // Delete rewrite rules to force a flush bbp_delete_rewrite_rules(); }
/** * 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); } } } }
/** * bbPress's version updater looks at what the current database version is, and * runs whatever other code is needed. * * This is most-often used when the data schema changes, but should also be used * to correct issues with bbPress meta-data silently on software update. * * @since bbPress (r4104) */ function bbp_version_updater() { // Get the raw database version $raw_db_version = (int) bbp_get_db_version_raw(); /** 2.0 Branch ************************************************************/ // 2.0, 2.0.1, 2.0.2, 2.0.3 if ($raw_db_version < 200) { // Do nothing } /** 2.1 Branch ************************************************************/ // 2.1, 2.1.1 if ($raw_db_version < 211) { /** * Repair private and hidden forum data * * @link http://bbpress.trac.wordpress.org/ticket/1891 */ bbp_admin_repair_forum_visibility(); } /** 2.2 Branch ************************************************************/ // 2.2 if ($raw_db_version < 214) { // Remove bbPress 1.1 roles (BuddyPress) remove_role('member'); remove_role('inactive'); remove_role('blocked'); remove_role('moderator'); remove_role('keymaster'); // Remove bbPress 2.1 roles remove_role('bbp_moderator'); remove_role('bbp_participant'); // Refresh capabilities bbp_remove_caps(); bbp_add_caps(); } /** All done! *************************************************************/ // Bump the version bbp_version_bump(); // Delete rewrite rules to force a flush bbp_delete_rewrite_rules(); }
/** * bbPress's version updater looks at what the current database version is, and * runs whatever other code is needed. * * This is most-often used when the data schema changes, but should also be used * to correct issues with bbPress meta-data silently on software update. * * @since 2.2.0 bbPress (r4104) */ function bbp_version_updater() { // Get the raw database version $raw_db_version = (int) bbp_get_db_version_raw(); // Only run updater if previous installation exists if (!empty($raw_db_version)) { /** 2.0 Branch ********************************************************/ // 2.0, 2.0.1, 2.0.2, 2.0.3 if ($raw_db_version < 200) { // No changes } /** 2.1 Branch ********************************************************/ // 2.1, 2.1.1 if ($raw_db_version < 211) { /** * Repair private and hidden forum data * * @link https://bbpress.trac.wordpress.org/ticket/1891 */ bbp_admin_repair_forum_visibility(); } /** 2.2 Branch ********************************************************/ // 2.2 if ($raw_db_version < 220) { // Remove any old bbPress roles bbp_remove_roles(); // Remove capabilities bbp_remove_caps(); } /** 2.3 Branch ********************************************************/ // 2.3 if ($raw_db_version < 230) { // No changes } } /** All done! *************************************************************/ // Bump the version bbp_version_bump(); // Delete rewrite rules to force a flush bbp_delete_rewrite_rules(); }