Ticket #46351: 46351.2.diff
File 46351.2.diff, 4.9 KB (added by , 6 years ago) |
---|
-
src/wp-includes/ms-site.php
52 52 'lang_id' => 0, 53 53 ); 54 54 55 // Extract the passed arguments that may be relevant for site initialization. 56 $args = array_diff_key( $data, $defaults ); 57 if ( isset( $args['site_id'] ) ) { 58 unset( $args['site_id'] ); 55 $prepared_data = wp_prepare_site_data( $data, $defaults ); 56 if ( is_wp_error( $prepared_data ) ) { 57 return $prepared_data; 59 58 } 60 59 61 $data = wp_prepare_site_data( $data, $defaults ); 62 if ( is_wp_error( $data ) ) { 63 return $data; 64 } 65 66 if ( false === $wpdb->insert( $wpdb->blogs, $data ) ) { 60 if ( false === $wpdb->insert( $wpdb->blogs, $prepared_data ) ) { 67 61 return new WP_Error( 'db_insert_error', __( 'Could not insert site into the database.' ), $wpdb->last_error ); 68 62 } 69 63 … … 80 74 */ 81 75 do_action( 'wp_insert_site', $new_site ); 82 76 77 // Extract the passed arguments that may be relevant for site initialization. 78 $args = array_diff_key( $data, $defaults ); 79 if ( isset( $args['site_id'] ) ) { 80 unset( $args['site_id'] ); 81 } 82 83 83 /** 84 84 * Fires when a site's initialization routine should be executed. 85 85 * … … 95 95 $user_id = ! empty( $args['user_id'] ) ? $args['user_id'] : 0; 96 96 $meta = ! empty( $args['options'] ) ? $args['options'] : array(); 97 97 98 // Restore WPLANG which used to be part of the meta prior 5.1.0. 99 if ( ! array_key_exists( 'WPLANG', $meta ) ) { 100 $meta['WPLANG'] = get_network_option( $new_site->network_id, 'WPLANG' ); 101 } 102 103 // Restore site status which used to be part of the meta prior 5.1.0. 104 // The `$site_data_whitelist` matches the one used in `wpmu_create_blog`. 105 $site_data_whitelist = array( 'public', 'archived', 'mature', 'spam', 'deleted', 'lang_id' ); 106 $meta = array_merge( array_intersect_key( $data, array_flip( $site_data_whitelist ) ), $meta ); 107 98 108 /** 99 109 * Fires immediately after a new site is created. 100 110 * -
tests/phpunit/tests/multisite/site.php
12 12 protected $suppress = false; 13 13 protected $site_status_hooks = array(); 14 14 protected $wp_initialize_site_args = array(); 15 protected $wp_initialize_site_meta = array(); 15 16 protected static $network_ids; 16 17 protected static $site_ids; 17 18 protected static $uninitialized_site_id; … … 2348 2349 // Set siteurl 2349 2350 update_option( 'siteurl', 'http://testsite1.example.org/test' ); 2350 2351 } 2352 2353 /** 2354 * Tests whether all expected meta are provided in deprecated `wpmu_new_blog` action. 2355 * 2356 * @dataProvider data_wpmu_new_blog_action_backward_commpatible 2357 * 2358 * @ticket 46351 2359 */ 2360 public function test_wpmu_new_blog_action_backward_compatible( $meta, $expected_meta ) { 2361 // We are testing deprecated hook. Register it to expected deprecated notices. 2362 $this->setExpectedDeprecated( 'wpmu_new_blog' ); 2363 add_action( 'wpmu_new_blog', array( $this, 'wpmu_new_blog_callback' ), 10, 6 ); 2364 2365 $blog_id = wpmu_create_blog( 'testsite1.example.org', '/new-blog/', 'New Blog', get_current_user_id(), $meta, 1 ); 2366 2367 $this->assertEquals( $expected_meta, $this->wp_initialize_site_meta ); 2368 2369 remove_action( 'populate_options', array( $this, 'wpmu_new_blog_callback' ), 10 ); 2370 $this->wp_initialize_site_meta = array(); 2371 } 2372 2373 /** 2374 * Capture the $meta value passed to the wpmu_new_blog action and compare it. 2375 */ 2376 public function wpmu_new_blog_callback( $blog_id, $user_id, $domain, $path, $network_id, $meta ) { 2377 $this->wp_initialize_site_meta = $meta; 2378 } 2379 2380 public function data_wpmu_new_blog_action_backward_commpatible() { 2381 return array( 2382 'default values' => array( 2383 array( 2384 ), 2385 array( 2386 'public' => 0, // `public` is one of the defaults metas in `wpmu_create_blog' function prior WordPress 5.1.0 2387 'WPLANG' => 'en_US', // WPLANG is another default meta in `wpmu_create_blog` function prior WordPress 5.1.0. 2388 ), 2389 ), 2390 'public site' => array( 2391 array( 2392 'public' => 1, 2393 ), 2394 array( 2395 'public' => 1, 2396 'WPLANG' => 'en_US' 2397 ), 2398 ), 2399 'all whitelisted' => array( 2400 array( 2401 'public' => -1, 2402 'archived' => 0, 2403 'mature' => 0, 2404 'spam' => 0, 2405 'deleted' => 0, 2406 'lang_id' => 11, 2407 2408 ), 2409 array( 2410 'public' => -1, 2411 'WPLANG' => 'en_US', 2412 'archived' => 0, 2413 'mature' => 0, 2414 'spam' => 0, 2415 'deleted' => 0, 2416 'lang_id' => 11, 2417 ), 2418 ), 2419 'extra meta key' => array( 2420 array( 2421 'foo' => 'bar', 2422 ), 2423 array( 2424 'public' => 0, 2425 'WPLANG' => 'en_US', 2426 'foo' => 'bar', 2427 ), 2428 ), 2429 ); 2430 } 2351 2431 } 2352 2432 2353 2433 endif;