Ticket #41333: 41333.3.diff
File 41333.3.diff, 31.4 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 ); 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' ); 147 101 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 ); 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 $result = false; 1314 $suppress = $wpdb->suppress_errors(); 1315 if ( $wpdb->get_results( "DESCRIBE {$wpdb->posts}" ) ) { 1316 $result = true; 1317 } 1318 $wpdb->suppress_errors( $suppress ); 1319 1320 if ( $switch ) { 1321 restore_current_blog(); 1322 add_action( 'switch_blog', 'wp_switch_roles_and_user', 1, 2 ); 1323 } 1324 1325 return $result; 1326 } 1327 1328 /** 916 1329 * Retrieve option value for a given blog id based on name of option. 917 1330 * 918 1331 * If the option does not exist or does not have a value, then the return value … … 1621 2034 1622 2035 $non_cached_ids = _get_non_cached_ids( $network_ids, 'networks' ); 1623 2036 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 ) ) ) ); 2037 $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 2038 1626 2039 update_network_cache( $fresh_networks ); 1627 2040 } … … 1757 2170 } 1758 2171 1759 2172 if ( $new_site->spam != $old_site->spam ) { 1760 if ( $new_site->spam == 1) {2173 if ( 1 == $new_site->spam ) { 1761 2174 1762 2175 /** 1763 2176 * Fires when the 'spam' status is added to a site. … … 1781 2194 } 1782 2195 1783 2196 if ( $new_site->mature != $old_site->mature ) { 1784 if ( $new_site->mature == 1) {2197 if ( 1 == $new_site->mature ) { 1785 2198 1786 2199 /** 1787 2200 * Fires when the 'mature' status is added to a site. … … 1805 2218 } 1806 2219 1807 2220 if ( $new_site->archived != $old_site->archived ) { 1808 if ( $new_site->archived == 1) {2221 if ( 1 == $new_site->archived ) { 1809 2222 1810 2223 /** 1811 2224 * Fires when the 'archived' status is added to a site. … … 1829 2242 } 1830 2243 1831 2244 if ( $new_site->deleted != $old_site->deleted ) { 1832 if ( $new_site->deleted == 1) {2245 if ( 1 == $new_site->deleted ) { 1833 2246 1834 2247 /** 1835 2248 * Fires when the 'deleted' status is added to a site. … … 1889 2302 * @param string $public The value of the site status. 1890 2303 */ 1891 2304 function wp_update_blog_public_option_on_site_update( $site_id, $public ) { 2305 2306 // Bail if the site's database tables do not exist (yet). 2307 if ( ! wp_is_site_initialized( $site_id ) ) { 2308 return; 2309 } 2310 1892 2311 update_blog_option( $site_id, 'blog_public', $public ); 1893 2312 } -
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 require_once( ABSPATH . 'wp-admin/includes/upgrade.php' ); 674 675 $suppress = $wpdb->suppress_errors(); 676 677 wp_install_defaults( $user_id ); 678 679 $wpdb->suppress_errors( $suppress ); 680 } -
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; … … 1321 1320 'network_id' => $network_id, 1322 1321 ), 1323 1322 array_intersect_key( 1324 $ meta,1323 $options, 1325 1324 array_flip( $site_data_whitelist ) 1326 1325 ) 1327 1326 ); 1328 1327 1329 $meta = array_diff_key( $meta, array_flip( $site_data_whitelist ) ); 1330 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 ); 1328 $blog_id = wp_insert_site( 1329 array_merge( 1330 $site_data, 1331 array( 1332 'title' => $title, 1333 'user_id' => $user_id, 1334 'options' => array_diff_key( $options, array_flip( $site_data_whitelist ) ), 1335 ) 1336 ) 1337 ); 1334 1338 1335 1339 if ( is_wp_error( $blog_id ) ) { 1336 1340 return $blog_id; 1337 1341 } 1338 1342 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 1343 wp_cache_set( 'last_changed', microtime(), 'sites' ); 1374 1344 1375 1345 return $blog_id; … … 1382 1352 * the notification email. 1383 1353 * 1384 1354 * @since MU (3.0.0) 1355 * @since 5.0.0 $blog_id now supports input from the {@see 'wp_initialize_site'} action. 1385 1356 * 1386 * @param int $blog_id The new site'sID.1387 * @param string $deprecated Not used.1357 * @param WP_Site|int $blog_id The new site's object or ID. 1358 * @param string $deprecated Not used. 1388 1359 * @return bool 1389 1360 */ 1390 1361 function newblog_notify_siteadmin( $blog_id, $deprecated = '' ) { 1362 if ( is_object( $blog_id ) ) { 1363 $blog_id = $blog_id->blog_id; 1364 } 1365 1391 1366 if ( get_site_option( 'registrationnotification' ) != 'yes' ) { 1392 1367 return false; 1393 1368 } … … 1529 1504 } 1530 1505 1531 1506 /** 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 1507 * Notify a user that their blog activation has been successful. 1628 1508 * 1629 1509 * Filter {@see 'wpmu_welcome_notification'} to disable or bypass. … … 2024 1904 * Logs the user email, IP, and registration date of a new site. 2025 1905 * 2026 1906 * @since MU (3.0.0) 1907 * @since 5.0.0 Parameters now support input from the {@see 'wp_initialize_site'} action. 2027 1908 * 2028 1909 * @global wpdb $wpdb WordPress database abstraction object. 2029 1910 * 2030 * @param int $blog_id2031 * @param int $user_id1911 * @param WP_Site|int $blog_id The new site's object or ID. 1912 * @param int|array $user_id User ID, or array of arguments including 'user_id'. 2032 1913 */ 2033 1914 function wpmu_log_new_registrations( $blog_id, $user_id ) { 2034 1915 global $wpdb; 1916 1917 if ( is_object( $blog_id ) ) { 1918 $blog_id = $blog_id->blog_id; 1919 } 1920 1921 if ( is_array( $user_id ) ) { 1922 $user_id = ! empty( $user_id['user_id'] ) ? $user_id['user_id'] : 0; 1923 } 1924 2035 1925 $user = get_userdata( (int) $user_id ); 2036 1926 if ( $user ) { 2037 1927 $wpdb->insert(