Changeset 43654 for trunk/src/wp-includes/ms-functions.php
- Timestamp:
- 09/24/2018 03:08:32 PM (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-includes/ms-functions.php
r43571 r43654 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 … … 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 ); … … 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 ) ); 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 ); 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 ); 1331 1332 $blog_id = wp_insert_site( array_merge( $site_data, $site_initialization_data ) ); 1334 1333 1335 1334 if ( is_wp_error( $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 … … 1383 1348 * 1384 1349 * @since MU (3.0.0) 1385 * 1386 * @param int $blog_id The new site's ID. 1387 * @param string $deprecated Not used. 1350 * @since 5.0.0 $blog_id now supports input from the {@see 'wp_initialize_site'} action. 1351 * 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; … … 1527 1497 */ 1528 1498 return apply_filters( 'domain_exists', $result, $domain, $path, $network_id ); 1529 }1530 1531 /**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 1499 } 1625 1500 … … 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 ) {
Note: See TracChangeset
for help on using the changeset viewer.