/** * @group delete */ public function test_follow_and_delete_blog() { if (!is_multisite()) { return; } // create user and blog $u = $this->factory->user->create(); $b = $this->factory->blog->create(array('title' => 'The Foo Bar Blog', 'user_id' => $u)); // make blog creator follow own blog $f = bp_follow_start_following(array('leader_id' => $b, 'follower_id' => $u, 'follow_type' => 'blogs')); // assert that follow relationship worked $this->assertTrue($f); // now delete blog wpmu_delete_blog($b); // check if cache was deleted $this->assertEmpty(wp_cache_get($u, 'bp_follow_following_blogs_count')); $this->assertEmpty(wp_cache_get($b, 'bp_follow_followers_blogs_count')); // check if follow relationship was deleted $is_following = bp_follow_is_following(array('leader_id' => $b, 'follower_id' => $u, 'follow_type' => 'blogs')); $this->assertSame(0, $is_following); }
/** * When a site is deleted with wpmu_delete_blog(), only the files associated with * that site should be removed. When wpmu_delete_blog() is run a second time, nothing * should change with upload directories. */ function test_upload_directories_after_multiple_wpmu_delete_blog_with_ms_files() { $filename = rand_str().'.jpg'; $contents = rand_str(); // Upload a file to the main site on the network. $file1 = wp_upload_bits( $filename, null, $contents ); $blog_id = $this->factory->blog->create(); switch_to_blog( $blog_id ); $file2 = wp_upload_bits( $filename, null, $contents ); restore_current_blog(); wpmu_delete_blog( $blog_id, true ); // The file on the main site should still exist. The file on the deleted site should not. $this->assertTrue( file_exists( $file1['file'] ) ); $this->assertFalse( file_exists( $file2['file'] ) ); wpmu_delete_blog( $blog_id, true ); // The file on the main site should still exist. The file on the deleted site should not. $this->assertTrue( file_exists( $file1['file'] ) ); $this->assertFalse( file_exists( $file2['file'] ) ); }
public static function wpTearDownAfterClass() { foreach (self::$site_ids as $id) { wpmu_delete_blog($id, true); } wp_update_network_site_counts(); }
public function tearDown() { global $wpdb; remove_action('bp_blogs_recorded_existing_blogs', array($this, 'set_autocommit_flag')); parent::tearDown(); // If we detect that a COMMIT has been triggered during the test, clean up blog and user fixtures. if ($this->autocommitted) { if (is_multisite()) { foreach ($wpdb->get_col("SELECT blog_id FROM {$wpdb->blogs} WHERE blog_id != 1") as $blog_id) { wpmu_delete_blog($blog_id, true); } } foreach ($wpdb->get_col("SELECT ID FROM {$wpdb->users} WHERE ID != 1") as $user_id) { if (is_multisite()) { wpmu_delete_user($user_id); } else { wp_delete_user($user_id); } } } $this->commit_transaction(); // Reactivate any components that have been deactivated. foreach ($this->deactivated_components as $component) { buddypress()->active_components[$component] = 1; } $this->deactivated_components = array(); }
public static function wpTearDownAfterClass() { self::delete_user(self::$user); self::delete_user(self::$editor); if (is_multisite()) { wpmu_delete_blog(self::$site, true); } }
/** * Removes completely a blog from the network * @since 0.2.0 * @param int $blog_id the blog id */ public static function remove_blog($blog_id) { switch_to_blog($blog_id); $wp_upload_info = wp_upload_dir(); $dir = str_replace(' ', "\\ ", trailingslashit($wp_upload_info['basedir'])); restore_current_blog(); wpmu_delete_blog($blog_id, true); // wpmu_delete_blog leaves an empty site upload directory, that we want to remove : MUCD_Files::rrmdir($dir); }
/** * @ticket 38355 */ public function test_get_active_blog_for_user_with_spam_site() { $current_site_id = get_current_blog_id(); $site_id = self::factory()->blog->create(array('user_id' => self::$user_id, 'meta' => array('spam' => 1))); add_user_to_blog($site_id, self::$user_id, 'subscriber'); update_user_meta(self::$user_id, 'primary_blog', $site_id); $result = get_active_blog_for_user(self::$user_id); wpmu_delete_blog($site_id, true); $this->assertEquals($current_site_id, $result->id); }
function tearDown() { parent::tearDown(); if (is_multisite()) { $blogs = wp_get_sites(); foreach ($blogs as $blog) { if (1 !== (int) $blog['blog_id']) { wpmu_delete_blog($blog['blog_id'], true); } } } }
public static function wpTearDownAfterClass() { global $wpdb; foreach (self::$site_ids as $id) { wpmu_delete_blog($id, true); } foreach (self::$network_ids as $id) { $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->sitemeta} WHERE site_id = %d", $id)); $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->site} WHERE id= %d", $id)); } wp_update_network_site_counts(); }
/** * @ticket 39065 */ public function test_get_dashboard_url_for_administrator_of_different_site() { if (!is_multisite()) { $this->markTestSkipped('Test only runs in multisite.'); } $site_id = self::factory()->blog->create(array('user_id' => self::$user_id)); remove_user_from_blog(self::$user_id, get_current_blog_id()); $expected = get_admin_url($site_id); $result = get_dashboard_url(self::$user_id); remove_user_from_blog(self::$user_id, $site_id); add_user_to_blog(get_current_blog_id(), self::$user_id, 'administrator'); wpmu_delete_blog($site_id, true); $this->assertEquals($expected, $result); }
public function tearDown() { global $wpdb; parent::tearDown(); if (is_multisite()) { foreach ($wpdb->get_col("SELECT blog_id FROM {$wpdb->blogs} WHERE blog_id != 1") as $blog_id) { wpmu_delete_blog($blog_id, true); } } foreach ($wpdb->get_col("SELECT ID FROM {$wpdb->users} WHERE ID != 1") as $user_id) { if (is_multisite()) { wpmu_delete_user($user_id); } else { wp_delete_user($user_id); } } $this->commit_transaction(); }
/** * When a site is deleted with wpmu_delete_blog(), only the files associated with * that site should be removed. When wpmu_delete_blog() is run a second time, nothing * should change with upload directories. */ function test_upload_directories_after_multiple_wpmu_delete_blog_with_ms_files() { $filename = __FUNCTION__ . '.jpg'; $contents = __FUNCTION__ . '_contents'; // Upload a file to the main site on the network. $file1 = wp_upload_bits($filename, null, $contents); $blog_id = self::factory()->blog->create(); switch_to_blog($blog_id); $file2 = wp_upload_bits($filename, null, $contents); restore_current_blog(); wpmu_delete_blog($blog_id, true); // The file on the main site should still exist. The file on the deleted site should not. $this->assertFileExists($file1['file']); $this->assertFileNotExists($file2['file']); wpmu_delete_blog($blog_id, true); // The file on the main site should still exist. The file on the deleted site should not. $this->assertFileExists($file1['file']); $this->assertFileNotExists($file2['file']); }
/** * @ticket 22917 */ function test_enable_live_network_site_counts_filter() { $site_count_start = get_blog_count(); // false for large networks by default add_filter( 'enable_live_network_counts', '__return_false' ); $this->factory->blog->create_many( 4 ); // count only updated when cron runs, so unchanged $this->assertEquals( $site_count_start, (int) get_blog_count() ); add_filter( 'enable_live_network_counts', '__return_true' ); $site_ids = $this->factory->blog->create_many( 4 ); $this->assertEquals( $site_count_start + 9, (int) get_blog_count() ); //clean up remove_filter( 'enable_live_network_counts', '__return_false' ); remove_filter( 'enable_live_network_counts', '__return_true' ); foreach ( $site_ids as $site_id ) { wpmu_delete_blog( $site_id, true ); } }
/** * @group delete */ public function test_follow_and_delete_blog() { if (!is_multisite()) { return; } // create user and blog $u = $this->factory->user->create(); $b = $this->factory->blog->create(array('title' => 'The Foo Bar Blog', 'user_id' => $u)); // make blog creator follow own blog $f = bp_follow_start_following(array('leader_id' => $b, 'follower_id' => $u, 'follow_type' => 'blogs')); // assert that follow relationship worked $this->assertTrue($f); // prime cache new BP_Follow($b, $u, 'blogs'); bp_follow_get_the_following_count(array('user_id' => $u, 'follow_type' => 'blogs')); bp_follow_get_the_followers_count(array('object_id' => $b, 'follow_type' => 'blogs')); // now delete blog wpmu_delete_blog($b); // check if cache was deleted $this->assertEmpty(wp_cache_get("{$b}:{$u}:blogs", 'bp_follow_data')); $this->assertEmpty(wp_cache_get($u, 'bp_follow_user_blogs_following_count')); $this->assertEmpty(wp_cache_get($b, 'bp_follow_blogs_followers_count')); }
/** * Delete a network and all its blogs * * @param integer id ID of network to delete * @param boolean $delete_blogs Flag to permit blog deletion - default setting * of false will prevent deletion of occupied networks */ function delete_network($id, $delete_blogs = false) { global $wpdb; $id = (int) $id; // Ensure we have a valid network id $network = $wpdb->get_row($wpdb->prepare("SELECT * FROM {$wpdb->site} WHERE id = %d", $id)); // Bail if network does not exist if (empty($network)) { return new WP_Error('network_not_exist', __('Network does not exist.', 'wp-multi-network')); } // ensure there are no blogs attached to this network */ $sites = $wpdb->get_results($wpdb->prepare("SELECT * FROM {$wpdb->blogs} WHERE site_id = %d", $id)); // Bail if network has blogs and blog deletion is off if (false == $delete_blogs && !empty($sites)) { return new WP_Error('network_not_empty', __('Cannot delete network with sites.', 'wp-multi-network')); } // Are we rescuing orphans or deleting them? if (true == $delete_blogs && !empty($sites)) { foreach ($sites as $site) { if (RESCUE_ORPHANED_BLOGS && ENABLE_NETWORK_ZERO) { move_site($site->blog_id, 0); } else { wpmu_delete_blog($site->blog_id, true); } } } // Delete from sites table $wpdb->query($wpdb->prepare("DELETE FROM {$wpdb->site} WHERE id = %d", $id)); // Delete from site meta table $wpdb->query($wpdb->prepare($query = "DELETE FROM {$wpdb->sitemeta} WHERE site_id = %d", $id)); do_action('delete_network', $network); }
/** * Delete a site and all its blogs * * @uses move_blog() * @uses wpmu_delete_blog() * * @param integer id ID of site to delete * @param boolean $delete_blogs flag to permit blog deletion - default setting of FALSE will prevent deletion of occupied sites */ function delete_site($id, $delete_blogs = FALSE) { global $wpdb; $override = $delete_blogs; /* ensure we got a valid site id */ $query = "SELECT * FROM {$wpdb->site} WHERE id=" . (int) $id; $site = $wpdb->get_row($query); if (!$site) { return new WP_Error('site_not_exist', __('Network does not exist.', 'njsl-networks')); } /* ensure there are no blogs attached to this site */ $query = "SELECT * FROM {$wpdb->blogs} WHERE site_id=" . (int) $id; $blogs = $wpdb->get_results($query); if ($blogs && !$override) { return new WP_Error('site_not_empty', __('Cannot delete network with sites.', 'njsl-networks')); } if ($override) { if ($blogs) { foreach ($blogs as $blog) { if (RESCUE_ORPHANED_BLOGS && ENABLE_HOLDING_SITE) { move_blog($blog->blog_id, 0); } else { wpmu_delete_blog($blog->blog_id, true); } } } } $query = "DELETE FROM {$wpdb->site} WHERE id=" . (int) $id; $wpdb->query($query); $query = "DELETE FROM {$wpdb->sitemeta} WHERE site_id=" . (int) $id; $wpdb->query($query); do_action('wpmu_delete_site', $site); do_action('wpms_delete_network', $site); }
public function deleteBlog($session_id, $blogId) { $retour = false; if ($this->_isSessionValid($session_id) and $this->_isUserAllowed($session_id, CS_ROLE_MOD, $blogId)) { switch_to_blog($blogId); include_once 'wp-admin/includes/ms.php'; wpmu_delete_blog($blogId, true); restore_current_blog(); $retour = true; } else { if (!$this->_isSessionValid($session_id)) { throw new SoapFault('deleteblog', 'Delete Blog failed: Session-ID (' . $session_id . ') is not valid'); } else { throw new SoapFault('deleteblog', 'Delete Blog failed: User (' . $this->_sessionid_to_userid_array[$session_id] . ') is not allowed to delete this blog (' . $blogId . ').'); } } return $retour; }
function cfgp_reset_shadow_blog() { $results = array(); /* Get list of all blogs */ $blog_list = get_blog_list(null, 'all'); /* Delete all post_meta in all blogs */ foreach ($blog_list as $blog_info) { cfgp_delete_cfgp_post_meta($blog_info['blog_id']); } $results['meta_deleted'] = true; /* Delete the sitemeta, if this is a legacy install of plugin */ global $wpdb; $sql = ' DELETE FROM wp_sitemeta WHERE meta_key = "cfgp_blog_id" '; $results['sitemeta_deleted'] = $wpdb->query($sql); /* Delete the shadow blog */ if (!function_exists('wpmu_delete_blog')) { require_once ABSPATH . 'wp-admin/includes/ms.php'; } wpmu_delete_blog(cfgp_get_shadow_blog_id(), true); $results['success'] = 'true'; return $results; }
/** * When deleted with the drop parameter as true, the cache will first be false, then set to * -1 after an attempt at `get_blog_id_from_url()` is made. */ function test_get_blog_id_from_url_after_dropped() { $blog_id = self::factory()->blog->create(); $details = get_blog_details($blog_id, false); $key = md5($details->domain . $details->path); wpmu_delete_blog($blog_id, true); $this->assertEquals(false, wp_cache_get($key, 'blog-id-cache')); $this->assertEquals(0, get_blog_id_from_url($details->domain, $details->path)); $this->assertEquals(-1, wp_cache_get($key, 'blog-id-cache')); }
function admin_footer() { global $wpdb, $current_blog, $current_site; if ($current_blog->domain . $current_blog->path == $current_site->domain . $current_site->path) { return false; } if ($this->reallydeleteblog == true) { wpmu_delete_blog($wpdb->blogid); } }
/** * Delete a network and all its blogs * * @param integer id ID of network to delete * @param boolean $delete_blogs Flag to permit blog deletion - default setting * of false will prevent deletion of occupied networks */ function delete_network($id, $delete_blogs = false) { global $wpdb; // Get network $network = wp_get_network($id); // Bail if network does not exist if (empty($network)) { return new WP_Error('network_not_exist', __('Network does not exist.', 'wp-multi-network')); } // ensure there are no blogs attached to this network */ $sql = "SELECT * FROM {$wpdb->blogs} WHERE site_id = %d"; $prep = $wpdb->prepare($sql, $network->id); $sites = $wpdb->get_results($prep); // Bail if network has blogs and blog deletion is off if (empty($delete_blogs) && !empty($sites)) { return new WP_Error('network_not_empty', __('Cannot delete network with sites.', 'wp-multi-network')); } // Are we rescuing orphans or deleting them? if (true == $delete_blogs && !empty($sites)) { foreach ($sites as $site) { if (RESCUE_ORPHANED_BLOGS) { move_site($site->blog_id, 0); } else { wpmu_delete_blog($site->blog_id, true); } } } // Delete from sites table $sql = "DELETE FROM {$wpdb->site} WHERE id = %d"; $prep = $wpdb->prepare($sql, $network->id); $wpdb->query($prep); // Delete from site meta table $sql = "DELETE FROM {$wpdb->sitemeta} WHERE site_id = %d"; $prep = $wpdb->prepare($sql, $network->id); $wpdb->query($prep); // Network deleted do_action('delete_network', $network); }
function moderation_overview() { global $wpdb, $wp_roles, $current_user, $user_id, $current_site; if (!is_moderator()) { die; } if (isset($_GET['updated'])) { ?> <div id="message" class="updated fade"><p><?php _e(urldecode($_GET['updatedmsg']), 'moderation'); ?> </p></div><?php } echo '<div class="wrap">'; if (!isset($_GET['action'])) { $_GET['action'] = ''; } switch ($_GET['action']) { //---------------------------------------------------// default: $moderators_can_remove_users = get_site_option('moderators_can_remove_users', 'no'); $moderators_can_remove_blogs = get_site_option('moderators_can_remove_blogs', 'no'); $post_count = $wpdb->get_var("SELECT COUNT(*) FROM " . $wpdb->base_prefix . "moderation_reports WHERE report_object_type = 'post' AND report_status = 'new'"); $blog_count = $wpdb->get_var("SELECT COUNT(*) FROM " . $wpdb->base_prefix . "moderation_reports WHERE report_object_type = 'blog' AND report_status = 'new'"); $comment_count = $wpdb->get_var("SELECT COUNT(*) FROM " . $wpdb->base_prefix . "moderation_reports WHERE report_object_type = 'comment' AND report_status = 'new'"); ?> <h2><?php _e('Moderation', 'moderation'); ?> </h2> <h3><?php _e('Reports', 'moderation'); ?> </h3> <p> <strong><?php _e('Posts', 'moderation'); ?> </strong>: <?php echo $blog_count; ?> <br /> <strong><?php _e('Comments', 'moderation'); ?> </strong>: <?php echo $comment_count; ?> <br /> <strong><?php _e('Blogs', 'moderation'); ?> </strong>: <?php echo $blog_count; ?> </p> <h3><?php _e('User Information', 'moderation'); ?> </h3> <form name="user_information" method="POST" action="admin.php?page=moderation&action=user_information"> <table class="form-table"> <tr valign="top"> <th scope="row"><?php _e('Username', 'moderation'); ?> </th> <td><input type="text" name="user_login" id="user_login" style="width: 95%" value="" /> <br /> <?php //_e('') ?> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('User ID', 'moderation'); ?> </th> <td><input type="text" name="uid" id="uid" style="width: 95%" value="" /> <br /> <?php //_e('') ?> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('User Email', 'moderation'); ?> </th> <td><input type="text" name="user_email" id="user_email" style="width: 95%" value="" /> <br /> <?php //_e('') ?> </td> </tr> </table> <p class="submit"> <input class="button button-primary" type="submit" name="Submit" value="<?php _e('Continue', 'moderation'); ?> " /> </p> </form> <?php if ($moderators_can_remove_users == 'yes') { ?> <h3><?php _e('Remove User', 'moderation'); ?> </h3> <form name="remove_user" method="POST" action="admin.php?page=moderation&action=remove_user"> <table class="form-table"> <tr valign="top"> <th scope="row"><?php _e('Username', 'moderation'); ?> </th> <td><input type="text" name="user_login" id="user_login" style="width: 95%" value="" /> <br /></td> </tr> <tr valign="top"> <th scope="row"><?php _e('User ID', 'moderation'); ?> </th> <td><input type="text" name="uid" id="uid" style="width: 95%" value="" /> <br /> <?php //_e('') ?> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('User Email', 'moderation'); ?> </th> <td><input type="text" name="user_email" id="user_email" style="width: 95%" value="" /> <br /> <?php //_e('') ?> </td> </tr> </table> <p class="submit"> <input class="button button-primary" type="submit" name="Submit" value="<?php _e('Continue', 'moderation'); ?> " /> </p> </form> <?php } if ($moderators_can_remove_blogs == 'yes') { ?> <h3><?php _e('Remove Blog', 'moderation'); ?> </h3> <form name="remove_blog" method="POST" action="admin.php?page=moderation&action=remove_blog"> <table class="form-table"> <tr valign="top"> <th scope="row"><?php _e('Blog ID', 'moderation'); ?> </th> <td><input type="text" name="bid" id="bid" style="width: 95%" value="" /> <br /> <?php //_e('') ?> </td> </tr> <tr valign="top"> <th scope="row"><?php _e('Blogname', 'moderation'); ?> </th> <td><input type="text" name="blog_name" id="blog_name" style="width: 95%" value="" /> <br /> <?php //_e('') ?> </td> </tr> </table> <p class="submit"> <input class="button button-primary" type="submit" name="Submit" value="<?php _e('Continue', 'moderation'); ?> " /> </p> </form> <?php } break; //---------------------------------------------------// //---------------------------------------------------// case "user_information": $uid = $_POST['uid']; if (empty($uid)) { $uid = $_GET['uid']; } $user_login = $_POST['user_login']; if (empty($user_login)) { $user_login = $_GET['user_login']; } $user_email = $_POST['user_email']; if (empty($user_email)) { $user_email = $_GET['user_email']; } if (!empty($user_login)) { $uid = $wpdb->get_var($wpdb->prepare("SELECT ID FROM " . $wpdb->users . " WHERE user_login = %s", $user_login)); } if (!empty($user_email)) { $uid = $wpdb->get_var($wpdb->prepare("SELECT ID FROM " . $wpdb->users . " WHERE user_email = %s", $user_email)); } $user_count = $wpdb->get_var("SELECT COUNT(*) FROM " . $wpdb->base_prefix . "users WHERE ID = '" . $uid . "'"); if ($user_count > 0) { $user_login = $wpdb->get_var("SELECT user_login FROM " . $wpdb->base_prefix . "users WHERE ID = '" . $uid . "'"); $warning_count = $wpdb->get_var("SELECT COUNT(*) FROM " . $wpdb->base_prefix . "moderation_warnings WHERE warning_user_ID = '" . $uid . "'"); $user_registered = $wpdb->get_var("SELECT user_registered FROM " . $wpdb->base_prefix . "users WHERE ID = '" . $uid . "'"); $user_email = $wpdb->get_var("SELECT user_email FROM " . $wpdb->base_prefix . "users WHERE ID = '" . $uid . "'"); $user_blogs = get_blogs_of_user($uid, true); ?> <h2><?php _e('User Information', 'moderation'); ?> : <?php echo $user_login; ?> </h2> <form name="user_information" method="POST" action="admin.php?page=moderation"> <p> <strong><?php _e('Email', 'moderation'); ?> </strong>: <?php echo $user_email; ?> <br /> <strong><?php _e('Registered', 'moderation'); ?> </strong>: <?php echo mysql2date(get_option('date_format'), $user_registered); ?> <br /> <strong><?php _e('Warnings', 'moderation'); ?> </strong>: <?php echo $warning_count; ?> <br /> <strong><?php _e('Post Archive', 'moderation'); ?> </strong>: <a href="admin.php?page=moderation-post-archive&object_type=post&uid=<?php echo $uid; ?> " style="text-decoration:none;" ><?php _e('View', 'moderation'); ?> </a> <br /> <strong><?php _e('Blogs', 'moderation'); ?> </strong>: <?php if (is_array($user_blogs)) { echo '<br />'; foreach ((array) $user_blogs as $key => $val) { $path = $val->path == '/' ? '' : $val->path; echo '<a href="http://' . $val->domain . $path . '">' . str_replace('.' . $current_site->domain, '', $val->domain . $path) . '</a>'; echo '<br />'; } } else { echo __('None', 'moderation'); } ?> </p> <p class="submit"> <input class="button button-primary" type="submit" name="Submit" value="<?php _e('Back', 'moderation'); ?> " /> </p> </form> <?php } else { ?> <h2><?php _e('Error', 'moderation'); ?> </h2> <?php echo '<p>' . __('User not found.', 'moderation') . '</p>'; } break; //---------------------------------------------------// //---------------------------------------------------// case "remove_user": $uid = $_POST['uid']; if (empty($uid)) { $uid = $_GET['uid']; } $user_login = $_POST['user_login']; if (empty($user_login)) { $user_login = $_GET['user_login']; } $user_email = $_POST['user_email']; if (empty($user_email)) { $user_email = $_GET['user_email']; } if (!empty($user_login)) { $uid = $wpdb->get_var($wpdb->prepare("SELECT ID FROM " . $wpdb->users . " WHERE user_login = %s", $user_login)); } if (!empty($user_email)) { $uid = $wpdb->get_var($wpdb->prepare("SELECT ID FROM " . $wpdb->users . " WHERE user_email = %s", $user_email)); } $user_count = $wpdb->get_var("SELECT COUNT(*) FROM " . $wpdb->base_prefix . "users WHERE ID = '" . $uid . "'"); if ($user_count > 0) { $user_login = $wpdb->get_var("SELECT user_login FROM " . $wpdb->base_prefix . "users WHERE ID = '" . $uid . "'"); if (!is_moderator($user_login)) { ?> <h2><?php _e('Remove User', 'moderation'); ?> : <?php echo $user_login; ?> </h2> <form name="remove_user" method="POST" action="admin.php?page=moderation&action=remove_user_process&uid=<?php echo $uid; ?> "> <table class="form-table"> <tr valign="top"> <th scope="row"><?php _e('Are you sure?', 'moderation'); ?> </th> <td> <select name="remove_user" id="remove_user"> <option value="yes"><?php _e('Yes', 'moderation'); ?> </option> <option value="no" selected="selected" ><?php _e('No', 'moderation'); ?> </option> </select> <br /><?php //_e('') ?> </td> </tr> </table> <p class="submit"> <input class="button button-primary" type="submit" name="Submit" value="<?php _e('Continue', 'moderation'); ?> " /> </p> </form> <?php } else { ?> <h2><?php _e('Error', 'moderation'); ?> </h2> <?php echo '<p>' . __('You cannot remove a moderator or site admin.', 'moderation') . '</p>'; } } else { ?> <h2><?php _e('Error', 'moderation'); ?> </h2> <?php echo '<p>' . __('User not found.', 'moderation') . '</p>'; } break; //---------------------------------------------------// //---------------------------------------------------// case "remove_user_process": if ($_POST['remove_user'] == 'no') { echo "\n\t\t\t\t<SCRIPT LANGUAGE='JavaScript'>\n\t\t\t\twindow.location='admin.php?page=moderation';\n\t\t\t\t</script>\n\t\t\t\t"; } else { wpmu_delete_user($_GET['uid']); echo "\n\t\t\t\t<SCRIPT LANGUAGE='JavaScript'>\n\t\t\t\twindow.location='admin.php?page=moderation&updated=true&updatedmsg=" . urlencode('User removed') . "';\n\t\t\t\t</script>\n\t\t\t\t"; } break; //---------------------------------------------------// //---------------------------------------------------// case "remove_blog": $bid = $_POST['bid']; if (empty($bid)) { $bid = $_GET['bid']; } $blog_name = $_POST['blog_name']; if (empty($blog_name)) { $blog_name = $_GET['blog_name']; } if (!empty($blog_name)) { if (VHOST == 'yes') { $bid = $wpdb->get_var("SELECT blog_id FROM " . $wpdb->blogs . " WHERE domain = '" . $blog_name . "." . $current_site->domains . "'"); } else { $bid = $wpdb->get_var($wpdb->prepare("SELECT blog_id FROM " . $wpdb->blogs . " WHERE path = %s", $current_site->path . $blog_name . "/")); } } $blog_count = $wpdb->get_var("SELECT COUNT(*) FROM " . $wpdb->base_prefix . "blogs WHERE blog_id = '" . $bid . "'"); if ($blog_count > 0) { $blog_details = get_blog_details($bid); if ($bid != '1') { ?> <h2><?php _e('Remove Blog', 'moderation'); ?> : <a href="<?php echo $blog_details->siteurl; ?> " style="text-decoration:none;"><?php echo $blog_details->blogname; ?> </a></h2> <form name="remove_blog" method="POST" action="admin.php?page=moderation&action=remove_blog_process&bid=<?php echo $bid; ?> "> <table class="form-table"> <tr valign="top"> <th scope="row"><?php _e('Are you sure?', 'moderation'); ?> </th> <td> <select name="remove_blog" id="remove_blog"> <option value="yes"><?php _e('Yes', 'moderation'); ?> </option> <option value="no" selected="selected" ><?php _e('No', 'moderation'); ?> </option> </select> <br /><?php //_e('') ?> </td> </tr> </table> <p class="submit"> <input class="button button-primary" type="submit" name="Submit" value="<?php _e('Continue', 'moderation'); ?> " /> </p> </form> <?php } else { ?> <h2><?php _e('Error', 'moderation'); ?> </h2> <?php echo '<p>' . __('You cannot remove the main blog.', 'moderation') . '</p>'; } } else { ?> <h2><?php _e('Error', 'moderation'); ?> </h2> <?php echo '<p>' . __('Blog not found.', 'moderation') . '</p>'; } break; //---------------------------------------------------// //---------------------------------------------------// case "remove_blog_process": if ($_POST['remove_blog'] == 'no') { echo "\n\t\t\t\t<SCRIPT LANGUAGE='JavaScript'>\n\t\t\t\twindow.location='admin.php?page=moderation';\n\t\t\t\t</script>\n\t\t\t\t"; } else { wpmu_delete_blog($_GET['bid']); echo "\n\t\t\t\t<SCRIPT LANGUAGE='JavaScript'>\n\t\t\t\twindow.location='admin.php?page=moderation&updated=true&updatedmsg=" . urlencode('Blog removed') . "';\n\t\t\t\t</script>\n\t\t\t\t"; } break; //---------------------------------------------------// } echo '</div>'; }
/** * Delete a site in a multisite install. * * ## OPTIONS * * [<site-id>] * : The id of the site to delete. If not provided, you must set the --slug parameter. * * [--slug=<slug>] * : Path of the blog to be deleted. Subdomain on subdomain installs, directory on subdirectory installs. * * [--yes] * : Answer yes to the confirmation message. * * [--keep-tables] * : Delete the blog from the list, but don't drop it's tables. */ function delete($args, $assoc_args) { if (!is_multisite()) { WP_CLI::error('This is not a multisite install.'); } if (isset($assoc_args['slug'])) { $blog = get_blog_details(trim($assoc_args['slug'], '/')); } else { if (empty($args)) { WP_CLI::error("Need to specify a blog id."); } $blog_id = $args[0]; $blog = get_blog_details($blog_id); } if (!$blog) { WP_CLI::error("Site not found."); } WP_CLI::confirm("Are you sure you want to delete the {$blog->siteurl} site?", $assoc_args); wpmu_delete_blog($blog->blog_id, !\WP_CLI\Utils\get_flag_value($assoc_args, 'keep-tables')); WP_CLI::success("The site at {$blog->siteurl} was deleted."); }
if ((isset($_POST['action']) || isset($_POST['action2'])) && isset($_POST['allblogs'])) { check_admin_referer('bulk-sites'); if (!current_user_can('manage_sites')) { wp_die(__('You do not have permission to access this page.')); } $doaction = $_POST['action'] != -1 ? $_POST['action'] : $_POST['action2']; $blogfunction = ''; foreach ((array) $_POST['allblogs'] as $key => $val) { if ($val != '0' && $val != $current_site->blog_id) { switch ($doaction) { case 'delete': if (!current_user_can('delete_site', $val)) { wp_die(__('You are not allowed to delete the site.')); } $blogfunction = 'all_delete'; wpmu_delete_blog($val, true); break; case 'spam': $blogfunction = 'all_spam'; update_blog_status($val, 'spam', '1'); set_time_limit(60); break; case 'notspam': $blogfunction = 'all_notspam'; update_blog_status($val, 'spam', '0'); set_time_limit(60); break; } } else { wp_die(__('You are not allowed to change the current site.')); }
/** * Delete a blog in a multisite install. * * @synopsis --slug=<slug> [--yes] [--keep-tables] */ function delete($_, $assoc_args) { $slug = '/' . trim($assoc_args['slug'], '/') . '/'; $blog_id = self::get_blog_id_by_slug($slug); if (!$blog_id) { WP_CLI::error(sprintf("'%s' blog not found.", $slug)); } WP_CLI::confirm("Are you sure you want to delete the '{$slug}' blog?", $assoc_args); wpmu_delete_blog($blog_id, !isset($assoc_args['keep-tables'])); WP_CLI::success("Blog '{$slug}' deleted."); }
function xtec_user_deleted_blogs_page() { if (isset($_POST['delete'])) { if (isset($_POST['idblogs'])) { foreach ((array) $_POST['idblogs'] as $key => $val) { if ($val != '0' && $val != '1') { wpmu_delete_blog($val, true); } } ?> <div class="updated fade"> <p>S'han eliminat correctament els blocs seleccionats.</p> </div> <?php } } ?> <div class="wrap" style="position:relative;"> <h2>Blocs eliminats pels usuaris</h2> <form action="?page=xtec-user-deleted-blogs" method="post"> <?php global $wpdb; $apage = isset($_GET['apage']) ? intval($_GET['apage']) : 1; $num = isset($_GET['num']) ? intval($_GET['num']) : 25; $query = "SELECT * FROM {$wpdb->blogs} WHERE deleted=1"; $total = $wpdb->get_var("SELECT COUNT(blog_id) FROM {$wpdb->blogs} WHERE deleted=1"); $query .= " LIMIT " . intval(($apage - 1) * $num) . ", " . intval($num); $blog_list = $wpdb->get_results($query, ARRAY_A); $blog_navigation = paginate_links(array('base' => add_query_arg('apage', '%#%'), 'format' => '', 'total' => ceil($total / $num), 'current' => $apage)); ?> <p>Número de blocs eliminats pels usuaris: <strong><?php echo $total; ?> </strong></p> <p><a href="?page=xtec-inactivity-deleted-blogs">Llista els blocs eliminats per inactivitat</a></p> <div class="tablenav"> <?php if ($blog_navigation) { echo "<div class='tablenav-pages'>{$blog_navigation}</div>"; } ?> <div class="alignleft"> <input type="submit" value="Elimina permanentment els blocs seleccionats" name="delete" class="button-secondary delete" /> <br class="clear" /> </div> </div> <br class="clear" /> <?php $blogname_columns = constant("VHOST") == 'yes' ? __('Domain') : __('Path'); ?> <table width="100%" cellpadding="3" cellspacing="3" class="widefat"> <thead> <tr> <th class="check-column" scope="col"><input type="checkbox"/></th> <th scope="col"><?php echo __('ID'); ?> </th> <th scope="col"><?php echo $blogname_columns; ?> </th> <th scope="col"><?php echo __('Last Updated'); ?> </th> <th scope="col"><?php echo __('Registered'); ?> </th> <th scope="col"><?php echo __('Actions'); ?> </th> </tr> </thead> <tbody id="the-list"> <?php if ($blog_list) { foreach ($blog_list as $blog) { ?> <tr style='background:#f55' class='alternate'> <th scope="row" class="check-column"> <input type='checkbox' id='blog_<?php echo $blog['blog_id']; ?> ' name='idblogs[]' value='<?php echo $blog['blog_id']; ?> ' /> </th> <th scope="row"> <?php echo $blog['blog_id']; ?> </th> <td valign="top"> <a href="http://<?php echo $blog['domain'] . $blog['path']; ?> " rel="permalink"><?php echo $blog['path']; ?> </a> </td> <td valign="top"> <?php echo $blog['last_updated']; ?> </td> <td valign="top"> <?php echo $blog['registered']; ?> </td> <td valign="top"> <a class='delete' href="wpmu-edit.php?action=confirm&action2=deleteblog&id=<?php echo $blog['blog_id']; ?> &msg=<?php echo urlencode(sprintf(__("You are about to delete the blog %s"), $blogname)); ?> "><?php _e("Delete"); ?> </a> </td> </tr> <?php } } ?> </tbody> </table> </form> </div> <?php }
/** * Multisite delete site panel. * * @package WordPress * @subpackage Multisite * @since 3.0.0 */ require_once dirname(__FILE__) . '/admin.php'; wp_die(__('Multisite support is not enabled.')); if (!current_user_can('delete_site')) { wp_die(__('You do not have sufficient permissions to delete this site.')); } if (isset($_GET['h']) && $_GET['h'] != '' && get_option('delete_blog_hash') != false) { if (get_option('delete_blog_hash') == $_GET['h']) { wpmu_delete_blog($wpdb->blogid); wp_die(sprintf(__('Thank you for using %s, your site has been deleted. Happy trails to you until we meet again.'), $current_site->site_name)); } else { wp_die(__("I'm sorry, the link you clicked is stale. Please select another option.")); } } $blog = get_blog_details(); $user = wp_get_current_user(); $title = __('Delete Site'); $parent_file = 'tools.php'; require_once ABSPATH . 'wp-admin/admin-header.php'; echo '<div class="wrap">'; echo '<h1>' . esc_html($title) . '</h1>'; if (isset($_POST['action']) && $_POST['action'] == 'deleteblog' && isset($_POST['confirmdelete']) && $_POST['confirmdelete'] == '1') { check_admin_referer('delete-blog'); $hash = wp_generate_password(20, false);
public static function downgrade_paypal_site($entry, $config) { global $current_site; $action = $config['meta']['update_site_action']; if (!$action) { return; } $site_id = GFUserData::get_site_by_entry_id($entry['id']); if (!$site_id) { return; } switch ($action) { case 'deactivate': do_action('deactivate_blog', $site_id); update_blog_status($site_id, 'deleted', '1'); break; case 'delete': require_once ABSPATH . 'wp-admin/includes/ms.php'; if ($site_id != '0' && $site_id != $current_site->blog_id) { wpmu_delete_blog($site_id, true); } break; } }
function test_get_blog_id_from_url() { $user_id = $this->factory->user->create( array( 'role' => 'administrator' ) ); $blog_id = $this->factory->blog->create( array( 'user_id' => $user_id, 'path' => '/testdomainexists', 'title' => 'Test Title' ) ); $details = get_blog_details( $blog_id, false ); $this->assertEquals( $blog_id, get_blog_id_from_url( $details->domain, $details->path ) ); $key = md5( $details->domain . $details->path ); $this->assertEquals( $blog_id, wp_cache_get( $key, 'blog-id-cache' ) ); $this->assertEquals( 0, get_blog_id_from_url( $details->domain, 'foo' ) ); wpmu_delete_blog( $blog_id ); $this->assertEquals( $blog_id, get_blog_id_from_url( $details->domain, $details->path ) ); wpmu_delete_blog( $blog_id, true ); $this->assertEquals( false, wp_cache_get( $key, 'blog-id-cache' ) ); $this->assertEquals( 0, get_blog_id_from_url( $details->domain, $details->path ) ); }
function tearDown() { if (is_multisite()) { switch_to_blog(1); $sites = Timber::get_sites(); foreach ($sites as $site) { if ($site->ID > 0) { wpmu_delete_blog($site->ID, true); } } } }