Changeset 43654 for trunk/src/wp-admin/includes/ms.php
- Timestamp:
- 09/24/2018 03:08:32 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/ms.php
r43571 r43654 74 74 75 75 $blog = get_site( $blog_id ); 76 /**77 * Fires before a site is deleted.78 *79 * @since MU (3.0.0)80 *81 * @param int $blog_id The site ID.82 * @param bool $drop True if site's table should be dropped. Default is false.83 */84 do_action( 'delete_blog', $blog_id, $drop );85 86 $users = get_users(87 array(88 'blog_id' => $blog_id,89 'fields' => 'ids',90 )91 );92 93 // Remove users from this blog.94 if ( ! empty( $users ) ) {95 foreach ( $users as $user_id ) {96 remove_user_from_blog( $user_id, $blog_id );97 }98 }99 100 update_blog_status( $blog_id, 'deleted', 1 );101 76 102 77 $current_network = get_network(); … … 120 95 121 96 if ( $drop ) { 122 $uploads = wp_get_upload_dir(); 123 124 $tables = $wpdb->tables( 'blog' ); 125 /** 126 * Filters the tables to drop when the site is deleted. 127 * 128 * @since MU (3.0.0) 129 * 130 * @param string[] $tables Array of names of the site tables to be dropped. 131 * @param int $blog_id The ID of the site to drop tables for. 132 */ 133 $drop_tables = apply_filters( 'wpmu_drop_tables', $tables, $blog_id ); 134 135 foreach ( (array) $drop_tables as $table ) { 136 $wpdb->query( "DROP TABLE IF EXISTS `$table`" ); 137 } 138 139 if ( is_site_meta_supported() ) { 140 $blog_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->blogmeta WHERE blog_id = %d ", $blog_id ) ); 141 foreach ( $blog_meta_ids as $mid ) { 142 delete_metadata_by_mid( 'blog', $mid ); 97 wp_delete_site( $blog_id ); 98 } else { 99 /** This action is documented in wp-includes/ms-blogs.php */ 100 do_action_deprecated( 'delete_blog', array( $blog_id, false ), '5.0.0' ); 101 102 $users = get_users( 103 array( 104 'blog_id' => $blog_id, 105 'fields' => 'ids', 106 ) 107 ); 108 109 // Remove users from this blog. 110 if ( ! empty( $users ) ) { 111 foreach ( $users as $user_id ) { 112 remove_user_from_blog( $user_id, $blog_id ); 143 113 } 144 114 } 145 115 146 wp_delete_site( $blog_id ); 147 148 /** 149 * Filters the upload base directory to delete when the site is deleted. 150 * 151 * @since MU (3.0.0) 152 * 153 * @param string $uploads['basedir'] Uploads path without subdirectory. @see wp_upload_dir() 154 * @param int $blog_id The site ID. 155 */ 156 $dir = apply_filters( 'wpmu_delete_blog_upload_dir', $uploads['basedir'], $blog_id ); 157 $dir = rtrim( $dir, DIRECTORY_SEPARATOR ); 158 $top_dir = $dir; 159 $stack = array( $dir ); 160 $index = 0; 161 162 while ( $index < count( $stack ) ) { 163 // Get indexed directory from stack 164 $dir = $stack[ $index ]; 165 166 $dh = @opendir( $dir ); 167 if ( $dh ) { 168 while ( ( $file = @readdir( $dh ) ) !== false ) { 169 if ( $file == '.' || $file == '..' ) { 170 continue; 171 } 172 173 if ( @is_dir( $dir . DIRECTORY_SEPARATOR . $file ) ) { 174 $stack[] = $dir . DIRECTORY_SEPARATOR . $file; 175 } elseif ( @is_file( $dir . DIRECTORY_SEPARATOR . $file ) ) { 176 @unlink( $dir . DIRECTORY_SEPARATOR . $file ); 177 } 178 } 179 @closedir( $dh ); 180 } 181 $index++; 182 } 183 184 $stack = array_reverse( $stack ); // Last added dirs are deepest 185 foreach ( (array) $stack as $dir ) { 186 if ( $dir != $top_dir ) { 187 @rmdir( $dir ); 188 } 189 } 190 191 clean_blog_cache( $blog ); 192 } 193 194 /** 195 * Fires after the site is deleted from the network. 196 * 197 * @since 4.8.0 198 * 199 * @param int $blog_id The site ID. 200 * @param bool $drop True if site's tables should be dropped. Default is false. 201 */ 202 do_action( 'deleted_blog', $blog_id, $drop ); 116 update_blog_status( $blog_id, 'deleted', 1 ); 117 118 /** This action is documented in wp-includes/ms-blogs.php */ 119 do_action_deprecated( 'deleted_blog', array( $blog_id, false ), '5.0.0' ); 120 } 203 121 204 122 if ( $switch ) {
Note: See TracChangeset
for help on using the changeset viewer.