Ticket #41333: 41333.4.diff
File 41333.4.diff, 42.2 KB (added by , 6 years ago) |
---|
-
src/wp-admin/includes/ms.php
73 73 } 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(); 103 78 … … 119 94 } 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 );143 }144 }145 146 97 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 ); 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 ); 180 113 } 181 $index++;182 114 } 183 115 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 } 116 update_blog_status( $blog_id, 'deleted', 1 ); 190 117 191 clean_blog_cache( $blog ); 118 /** This action is documented in wp-includes/ms-blogs.php */ 119 do_action_deprecated( 'deleted_blog', array( $blog_id, false ), '5.0.0' ); 192 120 } 193 121 194 /**195 * Fires after the site is deleted from the network.196 *197 * @since 4.8.0198 *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 );203 204 122 if ( $switch ) { 205 123 restore_current_blog(); 206 124 } -
src/wp-includes/ms-blogs.php
442 442 'lang_id' => 0, 443 443 ); 444 444 445 // Extract the passed arguments that may be relevant for site initialization. 446 $args = array_diff_key( $data, $defaults ); 447 if ( isset( $args['site_id'] ) ) { 448 unset( $args['site_id'] ); 449 } 450 445 451 $data = wp_prepare_site_data( $data, $defaults ); 446 452 if ( is_wp_error( $data ) ) { 447 453 return $data; … … 464 470 */ 465 471 do_action( 'wp_insert_site', $new_site ); 466 472 473 /** 474 * Fires when a site's initialization routine should be executed. 475 * 476 * @since 5.0.0 477 * 478 * @param WP_Site $new_site New site object. 479 * @param array $args Arguments for the initialization. 480 */ 481 do_action( 'wp_initialize_site', $new_site, $args ); 482 483 // Only compute extra hook parameters if the deprecated hook is actually in use. 484 if ( has_action( 'wpmu_new_blog' ) ) { 485 $user_id = ! empty( $args['user_id'] ) ? $args['user_id'] : 0; 486 $meta = ! empty( $args['options'] ) ? $args['options'] : array(); 487 488 /** 489 * Fires immediately after a new site is created. 490 * 491 * @since MU (3.0.0) 492 * @deprecated 5.0.0 Use wp_insert_site 493 * 494 * @param int $site_id Site ID. 495 * @param int $user_id User ID. 496 * @param string $domain Site domain. 497 * @param string $path Site path. 498 * @param int $network_id Network ID. Only relevant on multi-network installations. 499 * @param array $meta Meta data. Used to set initial site options. 500 */ 501 do_action_deprecated( 'wpmu_new_blog', array( $new_site->id, $user_id, $new_site->domain, $new_site->path, $new_site->network_id, $meta ), '5.0.0', 'wp_insert_site' ); 502 } 503 467 504 return (int) $new_site->id; 468 505 } 469 506 … … 543 580 return new WP_Error( 'site_not_exist', __( 'Site does not exist.' ) ); 544 581 } 545 582 583 $errors = new WP_Error(); 584 585 /** 586 * Fires before a site should be deleted from the database. 587 * 588 * Plugins should amend the `$errors` object via its `WP_Error::add()` method. If any errors 589 * are present, the site will not be deleted. 590 * 591 * @since 5.0.0 592 * 593 * @param WP_Error $errors Error object to add validation errors to. 594 * @param WP_Site $old_site The site object to be deleted. 595 */ 596 do_action( 'wp_validate_site_deletion', $errors, $old_site ); 597 598 if ( ! empty( $errors->errors ) ) { 599 return $errors; 600 } 601 602 /** 603 * Fires before a site is deleted. 604 * 605 * @since MU (3.0.0) 606 * @deprecated 5.0.0 607 * 608 * @param int $site_id The site ID. 609 * @param bool $drop True if site's table should be dropped. Default is false. 610 */ 611 do_action_deprecated( 'delete_blog', array( $old_site->id, true ), '5.0.0' ); 612 613 /** 614 * Fires when a site's uninitialization routine should be executed. 615 * 616 * @since 5.0.0 617 * 618 * @param WP_Site $old_site Deleted site object. 619 */ 620 do_action( 'wp_uninitialize_site', $old_site ); 621 622 if ( is_site_meta_supported() ) { 623 $blog_meta_ids = $wpdb->get_col( $wpdb->prepare( "SELECT meta_id FROM $wpdb->blogmeta WHERE blog_id = %d ", $old_site->id ) ); 624 foreach ( $blog_meta_ids as $mid ) { 625 delete_metadata_by_mid( 'blog', $mid ); 626 } 627 } 628 546 629 if ( false === $wpdb->delete( $wpdb->blogs, array( 'blog_id' => $old_site->id ) ) ) { 547 630 return new WP_Error( 'db_delete_error', __( 'Could not delete site from the database.' ), $wpdb->last_error ); 548 631 } … … 558 641 */ 559 642 do_action( 'wp_delete_site', $old_site ); 560 643 644 /** 645 * Fires after the site is deleted from the network. 646 * 647 * @since 4.8.0 648 * @deprecated 5.0.0 649 * 650 * @param int $site_id The site ID. 651 * @param bool $drop True if site's tables should be dropped. Default is false. 652 */ 653 do_action_deprecated( 'deleted_blog', array( $old_site->id, true ), '5.0.0' ); 654 561 655 return $old_site; 562 656 } 563 657 … … 619 713 620 714 $non_cached_ids = _get_non_cached_ids( $ids, 'sites' ); 621 715 if ( ! empty( $non_cached_ids ) ) { 622 $fresh_sites = $wpdb->get_results( sprintf( "SELECT * FROM $wpdb->blogs WHERE blog_id IN (%s)", join( ',', array_map( 'intval', $non_cached_ids ) ) ) ); 716 $fresh_sites = $wpdb->get_results( sprintf( "SELECT * FROM $wpdb->blogs WHERE blog_id IN (%s)", join( ',', array_map( 'intval', $non_cached_ids ) ) ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared 623 717 624 718 update_site_cache( $fresh_sites, $update_meta_cache ); 625 719 } … … 913 1007 } 914 1008 915 1009 /** 1010 * Runs the initialization routine for a given site. 1011 * 1012 * This process includes creating the site's database tables and 1013 * populating them with defaults. 1014 * 1015 * @since 5.0.0 1016 * 1017 * @global wpdb $wpdb WordPress database abstraction object. 1018 * @global WP_Roles $wp_roles WordPress role management object. 1019 * 1020 * @param int|WP_Site $site_id Site ID or object. 1021 * @param array $args { 1022 * Optional. Arguments to modify the initialization behavior. 1023 * 1024 * @type int $user_id Required. User ID for the site administrator. 1025 * @type string $title Site title. Default is 'Site %d' where %d is the 1026 * site ID. 1027 * @type array $options Custom option $key => $value pairs to use. Default 1028 * empty array. 1029 * @type array $meta Custom site metadata $key => $value pairs to use. 1030 * Default empty array. 1031 * } 1032 * @return bool|WP_Error True on success, or error object on failure. 1033 */ 1034 function wp_initialize_site( $site_id, array $args = array() ) { 1035 global $wpdb, $wp_roles; 1036 1037 if ( empty( $site_id ) ) { 1038 return new WP_Error( 'site_empty_id', __( 'Site ID must not be empty.' ) ); 1039 } 1040 1041 $site = get_site( $site_id ); 1042 if ( ! $site ) { 1043 return new WP_Error( 'site_invalid_id', __( 'Site with the ID does not exist.' ) ); 1044 } 1045 1046 if ( wp_is_site_initialized( $site ) ) { 1047 return new WP_Error( 'site_already_initialized', __( 'The site appears to be already initialized.' ) ); 1048 } 1049 1050 $network = get_network( $site->network_id ); 1051 if ( ! $network ) { 1052 $network = get_network(); 1053 } 1054 1055 $args = wp_parse_args( 1056 $args, 1057 array( 1058 'user_id' => 0, 1059 /* translators: %d: site ID */ 1060 'title' => sprintf( __( 'Site %d' ), $site->id ), 1061 'options' => array(), 1062 'meta' => array(), 1063 ) 1064 ); 1065 1066 /** 1067 * Filters the arguments for initializing a site. 1068 * 1069 * @since 5.0.0 1070 * 1071 * @param array $args Arguments to modify the initialization behavior. 1072 * @param WP_Site $site Site that is being initialized. 1073 * @param WP_Network $network Network that the site belongs to. 1074 */ 1075 $args = apply_filters( 'wp_initialize_site_args', $args, $site, $network ); 1076 1077 $orig_installing = wp_installing(); 1078 if ( ! $orig_installing ) { 1079 wp_installing( true ); 1080 } 1081 1082 $switch = false; 1083 if ( get_current_blog_id() !== $site->id ) { 1084 $switch = true; 1085 switch_to_blog( $site->id ); 1086 } 1087 1088 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 1089 1090 // Set up the database tables. 1091 make_db_current_silent( 'blog' ); 1092 1093 $home_scheme = 'http'; 1094 $siteurl_scheme = 'http'; 1095 if ( ! is_subdomain_install() ) { 1096 if ( 'https' === parse_url( get_home_url( $network->site_id ), PHP_URL_SCHEME ) ) { 1097 $home_scheme = 'https'; 1098 } 1099 if ( 'https' === parse_url( get_network_option( $network->id, 'siteurl' ), PHP_URL_SCHEME ) ) { 1100 $siteurl_scheme = 'https'; 1101 } 1102 } 1103 1104 // Populate the site's options. 1105 populate_options( 1106 array_merge( 1107 array( 1108 'home' => untrailingslashit( $home_scheme . '://' . $site->domain . $site->path ), 1109 'siteurl' => untrailingslashit( $siteurl_scheme . '://' . $site->domain . $site->path ), 1110 'blogname' => wp_unslash( $args['title'] ), 1111 'admin_email' => '', 1112 'upload_path' => get_network_option( $network->id, 'ms_files_rewriting' ) ? UPLOADBLOGSDIR . "/{$site->id}/files" : get_blog_option( $network->site_id, 'upload_path' ), 1113 'blog_public' => (int) $site->public, 1114 'WPLANG' => get_network_option( $network->id, 'WPLANG' ), 1115 ), 1116 $args['options'] 1117 ) 1118 ); 1119 1120 // Populate the site's roles. 1121 populate_roles(); 1122 $wp_roles = new WP_Roles(); 1123 1124 // Populate metadata for the site. 1125 populate_site_meta( $site->id, $args['meta'] ); 1126 1127 // Remove all permissions that may exist for the site. 1128 $table_prefix = $wpdb->get_blog_prefix(); 1129 delete_metadata( 'user', 0, $table_prefix . 'user_level', null, true ); // delete all 1130 delete_metadata( 'user', 0, $table_prefix . 'capabilities', null, true ); // delete all 1131 1132 // Install default site content. 1133 wp_install_defaults( $args['user_id'] ); 1134 1135 // Set the site administrator. 1136 add_user_to_blog( $site->id, $args['user_id'], 'administrator' ); 1137 if ( ! user_can( $args['user_id'], 'manage_network' ) && ! get_user_meta( $args['user_id'], 'primary_blog', true ) ) { 1138 update_user_meta( $args['user_id'], 'primary_blog', $site->id ); 1139 } 1140 1141 if ( $switch ) { 1142 restore_current_blog(); 1143 } 1144 1145 wp_installing( $orig_installing ); 1146 1147 return true; 1148 } 1149 1150 /** 1151 * Runs the uninitialization routine for a given site. 1152 * 1153 * This process includes dropping the site's database tables and deleting its uploads directory. 1154 * 1155 * @since 5.0.0 1156 * 1157 * @global wpdb $wpdb WordPress database abstraction object. 1158 * 1159 * @param int|WP_Site $site_id Site ID or object. 1160 * @return bool|WP_Error True on success, or error object on failure. 1161 */ 1162 function wp_uninitialize_site( $site_id ) { 1163 global $wpdb; 1164 1165 if ( empty( $site_id ) ) { 1166 return new WP_Error( 'site_empty_id', __( 'Site ID must not be empty.' ) ); 1167 } 1168 1169 $site = get_site( $site_id ); 1170 if ( ! $site ) { 1171 return new WP_Error( 'site_invalid_id', __( 'Site with the ID does not exist.' ) ); 1172 } 1173 1174 if ( ! wp_is_site_initialized( $site ) ) { 1175 return new WP_Error( 'site_already_uninitialized', __( 'The site appears to be already uninitialized.' ) ); 1176 } 1177 1178 $users = get_users( array( 1179 'blog_id' => $site->id, 1180 'fields' => 'ids', 1181 ) ); 1182 1183 // Remove users from the site. 1184 if ( ! empty( $users ) ) { 1185 foreach ( $users as $user_id ) { 1186 remove_user_from_blog( $user_id, $site->id ); 1187 } 1188 } 1189 1190 $switch = false; 1191 if ( get_current_blog_id() !== $site->id ) { 1192 $switch = true; 1193 switch_to_blog( $site->id ); 1194 } 1195 1196 $uploads = wp_get_upload_dir(); 1197 1198 $tables = $wpdb->tables( 'blog' ); 1199 1200 /** 1201 * Filters the tables to drop when the site is deleted. 1202 * 1203 * @since MU (3.0.0) 1204 * 1205 * @param string[] $tables Array of names of the site tables to be dropped. 1206 * @param int $site_id The ID of the site to drop tables for. 1207 */ 1208 $drop_tables = apply_filters( 'wpmu_drop_tables', $tables, $site->id ); 1209 1210 foreach ( (array) $drop_tables as $table ) { 1211 $wpdb->query( "DROP TABLE IF EXISTS `$table`" ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared 1212 } 1213 1214 /** 1215 * Filters the upload base directory to delete when the site is deleted. 1216 * 1217 * @since MU (3.0.0) 1218 * 1219 * @param string $uploads['basedir'] Uploads path without subdirectory. @see wp_upload_dir() 1220 * @param int $site_id The site ID. 1221 */ 1222 $dir = apply_filters( 'wpmu_delete_blog_upload_dir', $uploads['basedir'], $site->id ); 1223 $dir = rtrim( $dir, DIRECTORY_SEPARATOR ); 1224 $top_dir = $dir; 1225 $stack = array( $dir ); 1226 $index = 0; 1227 1228 while ( $index < count( $stack ) ) { 1229 // Get indexed directory from stack 1230 $dir = $stack[ $index ]; 1231 1232 // phpcs:disable Generic.PHP.NoSilencedErrors.Discouraged 1233 $dh = @opendir( $dir ); 1234 if ( $dh ) { 1235 $file = @readdir( $dh ); 1236 while ( false !== $file ) { 1237 if ( '.' === $file || '..' === $file ) { 1238 $file = @readdir( $dh ); 1239 continue; 1240 } 1241 1242 if ( @is_dir( $dir . DIRECTORY_SEPARATOR . $file ) ) { 1243 $stack[] = $dir . DIRECTORY_SEPARATOR . $file; 1244 } elseif ( @is_file( $dir . DIRECTORY_SEPARATOR . $file ) ) { 1245 @unlink( $dir . DIRECTORY_SEPARATOR . $file ); 1246 } 1247 1248 $file = @readdir( $dh ); 1249 } 1250 @closedir( $dh ); 1251 } 1252 $index++; 1253 } 1254 1255 $stack = array_reverse( $stack ); // Last added dirs are deepest 1256 foreach ( (array) $stack as $dir ) { 1257 if ( $dir != $top_dir ) { 1258 @rmdir( $dir ); 1259 } 1260 } 1261 1262 // phpcs:enable Generic.PHP.NoSilencedErrors.Discouraged 1263 if ( $switch ) { 1264 restore_current_blog(); 1265 } 1266 1267 return true; 1268 } 1269 1270 /** 1271 * Checks whether a site is initialized. 1272 * 1273 * A site is considered initialized when its database tables are present. 1274 * 1275 * @since 5.0.0 1276 * 1277 * @global wpdb $wpdb WordPress database abstraction object. 1278 * 1279 * @param int|WP_Site $site_id Site ID or object. 1280 * @return bool True if the site is initialized, false otherwise. 1281 */ 1282 function wp_is_site_initialized( $site_id ) { 1283 global $wpdb; 1284 1285 if ( is_object( $site_id ) ) { 1286 $site_id = $site_id->blog_id; 1287 } 1288 $site_id = (int) $site_id; 1289 1290 /** 1291 * Filters the check for whether a site is initialized before the database is accessed. 1292 * 1293 * Returning a non-null value will effectively short-circuit the function, returning 1294 * that value instead. 1295 * 1296 * @since 5.0.0 1297 * 1298 * @param bool|null $pre The value to return, if not null. 1299 * @param int $site_id The site ID that is being checked. 1300 */ 1301 $pre = apply_filters( 'pre_wp_is_site_initialized', null, $site_id ); 1302 if ( null !== $pre ) { 1303 return (bool) $pre; 1304 } 1305 1306 $switch = false; 1307 if ( get_current_blog_id() !== $site_id ) { 1308 $switch = true; 1309 remove_action( 'switch_blog', 'wp_switch_roles_and_user', 1 ); 1310 switch_to_blog( $site_id ); 1311 } 1312 1313 $suppress = $wpdb->suppress_errors(); 1314 $result = (bool) $wpdb->get_results( "DESCRIBE {$wpdb->posts}" ); 1315 $wpdb->suppress_errors( $suppress ); 1316 1317 if ( $switch ) { 1318 restore_current_blog(); 1319 add_action( 'switch_blog', 'wp_switch_roles_and_user', 1, 2 ); 1320 } 1321 1322 return $result; 1323 } 1324 1325 /** 916 1326 * Retrieve option value for a given blog id based on name of option. 917 1327 * 918 1328 * If the option does not exist or does not have a value, then the return value … … 1621 2031 1622 2032 $non_cached_ids = _get_non_cached_ids( $network_ids, 'networks' ); 1623 2033 if ( ! empty( $non_cached_ids ) ) { 1624 $fresh_networks = $wpdb->get_results( sprintf( "SELECT $wpdb->site.* FROM $wpdb->site WHERE id IN (%s)", join( ',', array_map( 'intval', $non_cached_ids ) ) ) ); 2034 $fresh_networks = $wpdb->get_results( sprintf( "SELECT $wpdb->site.* FROM $wpdb->site WHERE id IN (%s)", join( ',', array_map( 'intval', $non_cached_ids ) ) ) ); // phpcs:ignore WordPress.DB.PreparedSQL.NotPrepared 1625 2035 1626 2036 update_network_cache( $fresh_networks ); 1627 2037 } … … 1757 2167 } 1758 2168 1759 2169 if ( $new_site->spam != $old_site->spam ) { 1760 if ( $new_site->spam == 1) {2170 if ( 1 == $new_site->spam ) { 1761 2171 1762 2172 /** 1763 2173 * Fires when the 'spam' status is added to a site. … … 1781 2191 } 1782 2192 1783 2193 if ( $new_site->mature != $old_site->mature ) { 1784 if ( $new_site->mature == 1) {2194 if ( 1 == $new_site->mature ) { 1785 2195 1786 2196 /** 1787 2197 * Fires when the 'mature' status is added to a site. … … 1805 2215 } 1806 2216 1807 2217 if ( $new_site->archived != $old_site->archived ) { 1808 if ( $new_site->archived == 1) {2218 if ( 1 == $new_site->archived ) { 1809 2219 1810 2220 /** 1811 2221 * Fires when the 'archived' status is added to a site. … … 1829 2239 } 1830 2240 1831 2241 if ( $new_site->deleted != $old_site->deleted ) { 1832 if ( $new_site->deleted == 1) {2242 if ( 1 == $new_site->deleted ) { 1833 2243 1834 2244 /** 1835 2245 * Fires when the 'deleted' status is added to a site. … … 1889 2299 * @param string $public The value of the site status. 1890 2300 */ 1891 2301 function wp_update_blog_public_option_on_site_update( $site_id, $public ) { 2302 2303 // Bail if the site's database tables do not exist (yet). 2304 if ( ! wp_is_site_initialized( $site_id ) ) { 2305 return; 2306 } 2307 1892 2308 update_blog_option( $site_id, 'blog_public', $public ); 1893 2309 } -
src/wp-includes/ms-default-filters.php
37 37 38 38 // Blogs 39 39 add_filter( 'wpmu_validate_blog_signup', 'signup_nonce_check' ); 40 add_action( 'wpmu_new_blog', 'wpmu_log_new_registrations', 10, 2 );41 add_action( 'wpmu_new_blog', 'newblog_notify_siteadmin', 10, 2 );42 40 add_action( 'wpmu_activate_blog', 'wpmu_welcome_notification', 10, 5 ); 43 41 add_action( 'after_signup_site', 'wpmu_signup_blog_notification', 10, 7 ); 44 42 add_filter( 'wp_normalize_site_data', 'wp_normalize_site_data', 10, 1 ); … … 49 47 add_action( 'wp_insert_site', 'wp_maybe_transition_site_statuses_on_update', 10, 1 ); 50 48 add_action( 'wp_update_site', 'wp_maybe_transition_site_statuses_on_update', 10, 2 ); 51 49 add_action( 'wp_update_site', 'wp_maybe_clean_new_site_cache_on_update', 10, 2 ); 50 add_action( 'wp_initialize_site', 'wp_initialize_site', 10, 2 ); 51 add_action( 'wp_initialize_site', 'wpmu_log_new_registrations', 100, 2 ); 52 add_action( 'wp_initialize_site', 'newblog_notify_siteadmin', 100, 1 ); 53 add_action( 'wp_uninitialize_site', 'wp_uninitialize_site', 10, 1 ); 52 54 add_action( 'update_blog_public', 'wp_update_blog_public_option_on_site_update', 1, 2 ); 53 55 54 56 // Register Nonce -
src/wp-includes/ms-deprecated.php
580 580 581 581 return $site_id; 582 582 } 583 584 /** 585 * Install an empty blog. 586 * 587 * Creates the new blog tables and options. If calling this function 588 * directly, be sure to use switch_to_blog() first, so that $wpdb 589 * points to the new blog. 590 * 591 * @since MU (3.0.0) 592 * @deprecated 5.0.0 593 * 594 * @global wpdb $wpdb 595 * @global WP_Roles $wp_roles 596 * 597 * @param int $blog_id The value returned by wp_insert_site(). 598 * @param string $blog_title The title of the new site. 599 */ 600 function install_blog( $blog_id, $blog_title = '' ) { 601 global $wpdb, $wp_roles; 602 603 _deprecated_function( __FUNCTION__, '5.0.0' ); 604 605 // Cast for security 606 $blog_id = (int) $blog_id; 607 608 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 609 610 $suppress = $wpdb->suppress_errors(); 611 if ( $wpdb->get_results( "DESCRIBE {$wpdb->posts}" ) ) { 612 die( '<h1>' . __( 'Already Installed' ) . '</h1><p>' . __( 'You appear to have already installed WordPress. To reinstall please clear your old database tables first.' ) . '</p></body></html>' ); 613 } 614 $wpdb->suppress_errors( $suppress ); 615 616 $url = get_blogaddress_by_id( $blog_id ); 617 618 // Set everything up 619 make_db_current_silent( 'blog' ); 620 populate_options(); 621 populate_roles(); 622 623 // populate_roles() clears previous role definitions so we start over. 624 $wp_roles = new WP_Roles(); 625 626 $siteurl = $home = untrailingslashit( $url ); 627 628 if ( ! is_subdomain_install() ) { 629 630 if ( 'https' === parse_url( get_site_option( 'siteurl' ), PHP_URL_SCHEME ) ) { 631 $siteurl = set_url_scheme( $siteurl, 'https' ); 632 } 633 if ( 'https' === parse_url( get_home_url( get_network()->site_id ), PHP_URL_SCHEME ) ) { 634 $home = set_url_scheme( $home, 'https' ); 635 } 636 } 637 638 update_option( 'siteurl', $siteurl ); 639 update_option( 'home', $home ); 640 641 if ( get_site_option( 'ms_files_rewriting' ) ) { 642 update_option( 'upload_path', UPLOADBLOGSDIR . "/$blog_id/files" ); 643 } else { 644 update_option( 'upload_path', get_blog_option( get_network()->site_id, 'upload_path' ) ); 645 } 646 647 update_option( 'blogname', wp_unslash( $blog_title ) ); 648 update_option( 'admin_email', '' ); 649 650 // remove all perms 651 $table_prefix = $wpdb->get_blog_prefix(); 652 delete_metadata( 'user', 0, $table_prefix . 'user_level', null, true ); // delete all 653 delete_metadata( 'user', 0, $table_prefix . 'capabilities', null, true ); // delete all 654 } 655 656 /** 657 * Set blog defaults. 658 * 659 * This function creates a row in the wp_blogs table. 660 * 661 * @since MU (3.0.0) 662 * @deprecated MU 663 * @deprecated Use wp_install_defaults() 664 * 665 * @global wpdb $wpdb WordPress database abstraction object. 666 * 667 * @param int $blog_id Ignored in this function. 668 * @param int $user_id 669 */ 670 function install_blog_defaults( $blog_id, $user_id ) { 671 global $wpdb; 672 673 _deprecated_function( __FUNCTION__, 'MU' ); 674 675 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 676 677 $suppress = $wpdb->suppress_errors(); 678 679 wp_install_defaults( $user_id ); 680 681 $wpdb->suppress_errors( $suppress ); 682 } -
src/wp-includes/ms-functions.php
1285 1285 * @param string $path The new site's path. 1286 1286 * @param string $title The new site's title. 1287 1287 * @param int $user_id The user ID of the new site's admin. 1288 * @param array $ metaOptional. Array of key=>value pairs used to set initial site options.1288 * @param array $options Optional. Array of key=>value pairs used to set initial site options. 1289 1289 * If valid status keys are included ('public', 'archived', 'mature', 1290 1290 * 'spam', 'deleted', or 'lang_id') the given site status(es) will be 1291 1291 * updated. Otherwise, keys and values will be used to set options for … … 1293 1293 * @param int $network_id Optional. Network ID. Only relevant on multi-network installations. 1294 1294 * @return int|WP_Error Returns WP_Error object on failure, the new site ID on success. 1295 1295 */ 1296 function wpmu_create_blog( $domain, $path, $title, $user_id, $ meta= array(), $network_id = 1 ) {1296 function wpmu_create_blog( $domain, $path, $title, $user_id, $options = array(), $network_id = 1 ) { 1297 1297 $defaults = array( 1298 1298 'public' => 0, 1299 'WPLANG' => get_network_option( $network_id, 'WPLANG' ),1300 1299 ); 1301 $ meta = wp_parse_args( $meta, $defaults );1300 $options = wp_parse_args( $options, $defaults ); 1302 1301 1303 1302 $title = strip_tags( $title ); 1304 1303 $user_id = (int) $user_id; … … 1320 1319 'path' => $path, 1321 1320 'network_id' => $network_id, 1322 1321 ), 1323 array_intersect_key( 1324 $meta, 1325 array_flip( $site_data_whitelist ) 1326 ) 1322 array_intersect_key( $options, array_flip( $site_data_whitelist ) ) 1327 1323 ); 1328 1324 1329 $meta = array_diff_key( $meta, array_flip( $site_data_whitelist ) ); 1325 // Data to pass to wp_initialize_site(). 1326 $site_initialization_data = array( 1327 'title' => $title, 1328 'user_id' => $user_id, 1329 'options' => array_diff_key( $options, array_flip( $site_data_whitelist ) ), 1330 ); 1330 1331 1331 remove_action( 'update_blog_public', 'wp_update_blog_public_option_on_site_update', 1 ); 1332 $blog_id = wp_insert_site( $site_data ); 1333 add_action( 'update_blog_public', 'wp_update_blog_public_option_on_site_update', 1, 2 ); 1332 $blog_id = wp_insert_site( array_merge( $site_data, $site_initialization_data ) ); 1334 1333 1335 1334 if ( is_wp_error( $blog_id ) ) { 1336 1335 return $blog_id; 1337 1336 } 1338 1337 1339 switch_to_blog( $blog_id );1340 install_blog( $blog_id, $title );1341 wp_install_defaults( $user_id );1342 1343 add_user_to_blog( $blog_id, $user_id, 'administrator' );1344 1345 foreach ( $meta as $key => $value ) {1346 update_option( $key, $value );1347 }1348 1349 update_option( 'blog_public', (int) $site_data['public'] );1350 1351 if ( ! is_super_admin( $user_id ) && ! get_user_meta( $user_id, 'primary_blog', true ) ) {1352 update_user_meta( $user_id, 'primary_blog', $blog_id );1353 }1354 1355 restore_current_blog();1356 1357 $site = get_site( $blog_id );1358 1359 /**1360 * Fires immediately after a new site is created.1361 *1362 * @since MU (3.0.0)1363 *1364 * @param int $blog_id Site ID.1365 * @param int $user_id User ID.1366 * @param string $domain Site domain.1367 * @param string $path Site path.1368 * @param int $network_id Network ID. Only relevant on multi-network installations.1369 * @param array $meta Meta data. Used to set initial site options.1370 */1371 do_action( 'wpmu_new_blog', $blog_id, $user_id, $site->domain, $site->path, $site->network_id, $meta );1372 1373 1338 wp_cache_set( 'last_changed', microtime(), 'sites' ); 1374 1339 1375 1340 return $blog_id; … … 1382 1347 * the notification email. 1383 1348 * 1384 1349 * @since MU (3.0.0) 1350 * @since 5.0.0 $blog_id now supports input from the {@see 'wp_initialize_site'} action. 1385 1351 * 1386 * @param int $blog_id The new site'sID.1387 * @param string $deprecated Not used.1352 * @param WP_Site|int $blog_id The new site's object or ID. 1353 * @param string $deprecated Not used. 1388 1354 * @return bool 1389 1355 */ 1390 1356 function newblog_notify_siteadmin( $blog_id, $deprecated = '' ) { 1357 if ( is_object( $blog_id ) ) { 1358 $blog_id = $blog_id->blog_id; 1359 } 1360 1391 1361 if ( get_site_option( 'registrationnotification' ) != 'yes' ) { 1392 1362 return false; 1393 1363 } … … 1529 1499 } 1530 1500 1531 1501 /** 1532 * Install an empty blog.1533 *1534 * Creates the new blog tables and options. If calling this function1535 * directly, be sure to use switch_to_blog() first, so that $wpdb1536 * points to the new blog.1537 *1538 * @since MU (3.0.0)1539 *1540 * @global wpdb $wpdb1541 * @global WP_Roles $wp_roles1542 *1543 * @param int $blog_id The value returned by wp_insert_site().1544 * @param string $blog_title The title of the new site.1545 */1546 function install_blog( $blog_id, $blog_title = '' ) {1547 global $wpdb, $wp_roles;1548 1549 // Cast for security1550 $blog_id = (int) $blog_id;1551 1552 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );1553 1554 $suppress = $wpdb->suppress_errors();1555 if ( $wpdb->get_results( "DESCRIBE {$wpdb->posts}" ) ) {1556 die( '<h1>' . __( 'Already Installed' ) . '</h1><p>' . __( 'You appear to have already installed WordPress. To reinstall please clear your old database tables first.' ) . '</p></body></html>' );1557 }1558 $wpdb->suppress_errors( $suppress );1559 1560 $url = get_blogaddress_by_id( $blog_id );1561 1562 // Set everything up1563 make_db_current_silent( 'blog' );1564 populate_options();1565 populate_roles();1566 1567 // populate_roles() clears previous role definitions so we start over.1568 $wp_roles = new WP_Roles();1569 1570 $siteurl = $home = untrailingslashit( $url );1571 1572 if ( ! is_subdomain_install() ) {1573 1574 if ( 'https' === parse_url( get_site_option( 'siteurl' ), PHP_URL_SCHEME ) ) {1575 $siteurl = set_url_scheme( $siteurl, 'https' );1576 }1577 if ( 'https' === parse_url( get_home_url( get_network()->site_id ), PHP_URL_SCHEME ) ) {1578 $home = set_url_scheme( $home, 'https' );1579 }1580 }1581 1582 update_option( 'siteurl', $siteurl );1583 update_option( 'home', $home );1584 1585 if ( get_site_option( 'ms_files_rewriting' ) ) {1586 update_option( 'upload_path', UPLOADBLOGSDIR . "/$blog_id/files" );1587 } else {1588 update_option( 'upload_path', get_blog_option( get_network()->site_id, 'upload_path' ) );1589 }1590 1591 update_option( 'blogname', wp_unslash( $blog_title ) );1592 update_option( 'admin_email', '' );1593 1594 // remove all perms1595 $table_prefix = $wpdb->get_blog_prefix();1596 delete_metadata( 'user', 0, $table_prefix . 'user_level', null, true ); // delete all1597 delete_metadata( 'user', 0, $table_prefix . 'capabilities', null, true ); // delete all1598 }1599 1600 /**1601 * Set blog defaults.1602 *1603 * This function creates a row in the wp_blogs table.1604 *1605 * @since MU (3.0.0)1606 * @deprecated MU1607 * @deprecated Use wp_install_defaults()1608 *1609 * @global wpdb $wpdb WordPress database abstraction object.1610 *1611 * @param int $blog_id Ignored in this function.1612 * @param int $user_id1613 */1614 function install_blog_defaults( $blog_id, $user_id ) {1615 global $wpdb;1616 1617 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' );1618 1619 $suppress = $wpdb->suppress_errors();1620 1621 wp_install_defaults( $user_id );1622 1623 $wpdb->suppress_errors( $suppress );1624 }1625 1626 /**1627 1502 * Notify a user that their blog activation has been successful. 1628 1503 * 1629 1504 * Filter {@see 'wpmu_welcome_notification'} to disable or bypass. … … 2024 1899 * Logs the user email, IP, and registration date of a new site. 2025 1900 * 2026 1901 * @since MU (3.0.0) 1902 * @since 5.0.0 Parameters now support input from the {@see 'wp_initialize_site'} action. 2027 1903 * 2028 1904 * @global wpdb $wpdb WordPress database abstraction object. 2029 1905 * 2030 * @param int $blog_id2031 * @param int $user_id1906 * @param WP_Site|int $blog_id The new site's object or ID. 1907 * @param int|array $user_id User ID, or array of arguments including 'user_id'. 2032 1908 */ 2033 1909 function wpmu_log_new_registrations( $blog_id, $user_id ) { 2034 1910 global $wpdb; 1911 1912 if ( is_object( $blog_id ) ) { 1913 $blog_id = $blog_id->blog_id; 1914 } 1915 1916 if ( is_array( $user_id ) ) { 1917 $user_id = ! empty( $user_id['user_id'] ) ? $user_id['user_id'] : 0; 1918 } 1919 2035 1920 $user = get_userdata( (int) $user_id ); 2036 1921 if ( $user ) { 2037 1922 $wpdb->insert( -
tests/phpunit/tests/multisite/site.php
9 9 * @group multisite 10 10 */ 11 11 class Tests_Multisite_Site extends WP_UnitTestCase { 12 protected $suppress = false; 13 protected $site_status_hooks = array(); 12 protected $suppress = false; 13 protected $site_status_hooks = array(); 14 protected $wp_initialize_site_args = array(); 14 15 protected static $network_ids; 15 16 protected static $site_ids; 17 protected static $uninitialized_site_id; 16 18 17 19 function setUp() { 18 20 global $wpdb; … … 56 58 $id = $factory->blog->create( $id ); 57 59 } 58 60 unset( $id ); 61 62 remove_action( 'wp_initialize_site', 'wp_initialize_site', 10 ); 63 self::$uninitialized_site_id = wp_insert_site( array( 64 'domain' => 'uninitialized.org', 65 'path' => '/', 66 'site_id' => self::$network_ids['make.wordpress.org/'], 67 ) ); 68 add_action( 'wp_initialize_site', 'wp_initialize_site', 10, 2 ); 59 69 } 60 70 61 71 public static function wpTearDownAfterClass() { 62 72 global $wpdb; 63 73 74 remove_action( 'wp_uninitialize_site', 'wp_uninitialize_site', 10 ); 75 wp_delete_site( self::$uninitialized_site_id ); 76 add_action( 'wp_uninitialize_site', 'wp_uninitialize_site', 10, 1 ); 77 64 78 foreach ( self::$site_ids as $id ) { 65 79 wpmu_delete_blog( $id, true ); 66 80 } … … 1266 1280 * @dataProvider data_wp_insert_site 1267 1281 */ 1268 1282 public function test_wp_insert_site( $site_data, $expected_data ) { 1283 remove_action( 'wp_initialize_site', 'wp_initialize_site', 10 ); 1269 1284 $site_id = wp_insert_site( $site_data ); 1270 1285 1271 1286 $this->assertInternalType( 'integer', $site_id ); … … 1360 1375 * @ticket 40364 1361 1376 */ 1362 1377 public function test_wp_insert_site_empty_domain() { 1378 remove_action( 'wp_initialize_site', 'wp_initialize_site', 10 ); 1363 1379 $site_id = wp_insert_site( array( 'public' => 0 ) ); 1364 1380 1365 1381 $this->assertWPError( $site_id ); … … 1497 1513 } 1498 1514 1499 1515 /** 1516 * @ticket 41333 1517 */ 1518 public function test_wp_delete_site_validate_site_deletion_action() { 1519 add_action( 'wp_validate_site_deletion', array( $this, 'action_wp_validate_site_deletion_prevent_deletion' ) ); 1520 $result = wp_delete_site( self::$site_ids['make.wordpress.org/'] ); 1521 $this->assertWPError( $result ); 1522 $this->assertSame( 'action_does_not_like_deletion', $result->get_error_code() ); 1523 } 1524 1525 public function action_wp_validate_site_deletion_prevent_deletion( $errors ) { 1526 $errors->add( 'action_does_not_like_deletion', 'You cannot delete this site because the action does not like it.' ); 1527 } 1528 1529 /** 1500 1530 * @ticket 40364 1501 1531 * @dataProvider data_wp_normalize_site_data 1502 1532 */ … … 1709 1739 */ 1710 1740 public function test_site_dates_are_gmt() { 1711 1741 $first_date = current_time( 'mysql', true ); 1712 $site_id = wp_insert_site( 1742 1743 remove_action( 'wp_initialize_site', 'wp_initialize_site', 10 ); 1744 $site_id = wp_insert_site( 1713 1745 array( 1714 1746 'domain' => 'valid-domain.com', 1715 1747 'path' => '/valid-path/', … … 2015 2047 public function action_site_status_hook( $site_id ) { 2016 2048 $this->site_status_hooks[ current_action() ] = $site_id; 2017 2049 } 2050 2051 /** 2052 * @ticket 41333 2053 * @dataProvider data_wp_initialize_site 2054 */ 2055 public function test_wp_initialize_site( $args, $expected_options, $expected_meta ) { 2056 $result = wp_initialize_site( self::$uninitialized_site_id, $args ); 2057 2058 switch_to_blog( self::$uninitialized_site_id ); 2059 2060 $options = array(); 2061 foreach ( $expected_options as $option => $value ) { 2062 $options[ $option ] = get_option( $option ); 2063 } 2064 2065 $meta = array(); 2066 foreach ( $expected_meta as $meta_key => $value ) { 2067 $meta[ $meta_key ] = get_site_meta( self::$uninitialized_site_id, $meta_key, true ); 2068 } 2069 2070 restore_current_blog(); 2071 2072 $initialized = wp_is_site_initialized( self::$uninitialized_site_id ); 2073 2074 wp_uninitialize_site( self::$uninitialized_site_id ); 2075 2076 $this->assertTrue( $result ); 2077 $this->assertTrue( $initialized ); 2078 $this->assertEquals( $expected_options, $options ); 2079 $this->assertEquals( $expected_meta, $meta ); 2080 } 2081 2082 public function data_wp_initialize_site() { 2083 return array( 2084 array( 2085 array(), 2086 array( 2087 'home' => 'http://uninitialized.org', 2088 'siteurl' => 'http://uninitialized.org', 2089 'admin_email' => '', 2090 'blog_public' => '1', 2091 ), 2092 array(), 2093 ), 2094 array( 2095 array( 2096 'options' => array( 2097 'home' => 'https://uninitialized.org', 2098 'siteurl' => 'https://uninitialized.org', 2099 'key' => 'value', 2100 ), 2101 'meta' => array( 2102 'key1' => 'value1', 2103 'key2' => 'value2', 2104 ), 2105 ), 2106 array( 2107 'home' => 'https://uninitialized.org', 2108 'siteurl' => 'https://uninitialized.org', 2109 'key' => 'value', 2110 ), 2111 array( 2112 'key1' => 'value1', 2113 'key2' => 'value2', 2114 'key3' => '', 2115 ), 2116 ), 2117 array( 2118 array( 2119 'title' => 'My New Site', 2120 'options' => array( 2121 'blogdescription' => 'Just My New Site', 2122 ), 2123 ), 2124 array( 2125 'blogname' => 'My New Site', 2126 'blogdescription' => 'Just My New Site', 2127 ), 2128 array(), 2129 ), 2130 ); 2131 } 2132 2133 /** 2134 * @ticket 41333 2135 */ 2136 public function test_wp_initialize_site_user_roles() { 2137 global $wpdb; 2138 2139 $result = wp_initialize_site( self::$uninitialized_site_id, array() ); 2140 2141 switch_to_blog( self::$uninitialized_site_id ); 2142 $table_prefix = $wpdb->get_blog_prefix( self::$uninitialized_site_id ); 2143 $roles = get_option( $table_prefix . 'user_roles' ); 2144 restore_current_blog(); 2145 2146 wp_uninitialize_site( self::$uninitialized_site_id ); 2147 2148 $this->assertTrue( $result ); 2149 $this->assertEqualSets( 2150 array( 2151 'administrator', 2152 'editor', 2153 'author', 2154 'contributor', 2155 'subscriber', 2156 ), 2157 array_keys( $roles ) 2158 ); 2159 } 2160 2161 /** 2162 * @ticket 41333 2163 */ 2164 public function test_wp_initialize_site_user_is_admin() { 2165 $result = wp_initialize_site( self::$uninitialized_site_id, array( 'user_id' => 1 ) ); 2166 2167 switch_to_blog( self::$uninitialized_site_id ); 2168 $user_is_admin = user_can( 1, 'manage_options' ); 2169 $admin_email = get_option( 'admin_email' ); 2170 restore_current_blog(); 2171 2172 wp_uninitialize_site( self::$uninitialized_site_id ); 2173 2174 $this->assertTrue( $result ); 2175 $this->assertTrue( $user_is_admin ); 2176 $this->assertEquals( get_userdata( 1 )->user_email, $admin_email ); 2177 } 2178 2179 /** 2180 * @ticket 41333 2181 */ 2182 public function test_wp_initialize_site_args_filter() { 2183 add_filter( 'wp_initialize_site_args', array( $this, 'filter_wp_initialize_site_args' ), 10, 3 ); 2184 $result = wp_initialize_site( self::$uninitialized_site_id, array( 'title' => 'My Site' ) ); 2185 2186 switch_to_blog( self::$uninitialized_site_id ); 2187 $site_title = get_option( 'blogname' ); 2188 restore_current_blog(); 2189 2190 wp_uninitialize_site( self::$uninitialized_site_id ); 2191 2192 $this->assertSame( 2193 sprintf( 'My Site %1$d in Network %2$d', self::$uninitialized_site_id, get_site( self::$uninitialized_site_id )->network_id ), 2194 $site_title 2195 ); 2196 } 2197 2198 public function filter_wp_initialize_site_args( $args, $site, $network ) { 2199 $args['title'] = sprintf( 'My Site %1$d in Network %2$d', $site->id, $network->id ); 2200 2201 return $args; 2202 } 2203 2204 /** 2205 * @ticket 41333 2206 */ 2207 public function test_wp_initialize_site_empty_id() { 2208 $result = wp_initialize_site( 0 ); 2209 $this->assertWPError( $result ); 2210 $this->assertSame( 'site_empty_id', $result->get_error_code() ); 2211 } 2212 2213 /** 2214 * @ticket 41333 2215 */ 2216 public function test_wp_initialize_site_invalid_id() { 2217 $result = wp_initialize_site( 123 ); 2218 $this->assertWPError( $result ); 2219 $this->assertSame( 'site_invalid_id', $result->get_error_code() ); 2220 } 2221 2222 /** 2223 * @ticket 41333 2224 */ 2225 public function test_wp_initialize_site_already_initialized() { 2226 $result = wp_initialize_site( get_current_blog_id() ); 2227 $this->assertWPError( $result ); 2228 $this->assertSame( 'site_already_initialized', $result->get_error_code() ); 2229 } 2230 2231 /** 2232 * @ticket 41333 2233 */ 2234 public function test_wp_uninitialize_site() { 2235 $site_id = self::factory()->blog->create(); 2236 2237 $result = wp_uninitialize_site( $site_id ); 2238 $this->assertTrue( $result ); 2239 $this->assertFalse( wp_is_site_initialized( $site_id ) ); 2240 } 2241 2242 /** 2243 * @ticket 41333 2244 */ 2245 public function test_wp_uninitialize_site_empty_id() { 2246 $result = wp_uninitialize_site( 0 ); 2247 $this->assertWPError( $result ); 2248 $this->assertSame( 'site_empty_id', $result->get_error_code() ); 2249 } 2250 2251 /** 2252 * @ticket 41333 2253 */ 2254 public function test_wp_uninitialize_site_invalid_id() { 2255 $result = wp_uninitialize_site( 123 ); 2256 $this->assertWPError( $result ); 2257 $this->assertSame( 'site_invalid_id', $result->get_error_code() ); 2258 } 2259 2260 /** 2261 * @ticket 41333 2262 */ 2263 public function test_wp_uninitialize_site_already_uninitialized() { 2264 $result = wp_uninitialize_site( self::$uninitialized_site_id ); 2265 $this->assertWPError( $result ); 2266 $this->assertSame( 'site_already_uninitialized', $result->get_error_code() ); 2267 } 2268 2269 /** 2270 * @ticket 41333 2271 */ 2272 public function test_wp_is_site_initialized() { 2273 $this->assertTrue( wp_is_site_initialized( get_current_blog_id() ) ); 2274 $this->assertFalse( wp_is_site_initialized( self::$uninitialized_site_id ) ); 2275 } 2276 2277 /** 2278 * @ticket 41333 2279 */ 2280 public function test_wp_is_site_initialized_prefilter() { 2281 add_filter( 'pre_wp_is_site_initialized', '__return_false' ); 2282 $this->assertFalse( wp_is_site_initialized( get_current_blog_id() ) ); 2283 2284 add_filter( 'pre_wp_is_site_initialized', '__return_true' ); 2285 $this->assertTrue( wp_is_site_initialized( self::$uninitialized_site_id ) ); 2286 } 2287 2288 /** 2289 * @ticket 41333 2290 */ 2291 public function test_wp_insert_site_forwards_args_to_wp_initialize_site() { 2292 $args = array( 2293 'user_id' => 1, 2294 'title' => 'My Site', 2295 'options' => array( 'option1' => 'value1' ), 2296 'meta' => array( 'meta1' => 'value1' ), 2297 ); 2298 2299 add_filter( 'wp_initialize_site_args', array( $this, 'filter_wp_initialize_site_args_catch_args' ) ); 2300 $site_id = wp_insert_site( 2301 array_merge( 2302 array( 2303 'domain' => 'testsite.org', 2304 'path' => '/', 2305 ), 2306 $args 2307 ) 2308 ); 2309 $passed_args = $this->wp_initialize_site_args; 2310 2311 $this->wp_initialize_site_args = null; 2312 2313 $this->assertEqualSetsWithIndex( $args, $passed_args ); 2314 } 2315 2316 public function filter_wp_initialize_site_args_catch_args( $args ) { 2317 $this->wp_initialize_site_args = $args; 2318 2319 return $args; 2320 } 2018 2321 } 2019 2322 2020 2323 endif;