Ticket #49263: 49263.2.diff
File 49263.2.diff, 6.1 KB (added by , 5 years ago) |
---|
-
src/wp-includes/l10n.php
28 28 * @return string The locale of the blog or from the {@see 'locale'} hook. 29 29 */ 30 30 function get_locale() { 31 global $locale , $wp_local_package;31 global $locale; 32 32 33 33 if ( isset( $locale ) ) { 34 34 /** … … 41 41 return apply_filters( 'locale', $locale ); 42 42 } 43 43 44 $locale = _get_raw_site_locale(); 45 46 /** This filter is documented in wp-includes/l10n.php */ 47 return apply_filters( 'locale', $locale ); 48 } 49 50 // todo explain internal and should not be used by plugins? 51 // or let it be external? no harm? 52 function _get_raw_site_locale() { 53 global $wp_local_package; 54 44 55 if ( isset( $wp_local_package ) ) { 45 56 $locale = $wp_local_package; 46 57 } … … 57 68 $ms_locale = get_site_option( 'WPLANG' ); 58 69 } else { 59 70 $ms_locale = get_option( 'WPLANG' ); 71 60 72 if ( false === $ms_locale ) { 61 73 $ms_locale = get_site_option( 'WPLANG' ); 62 74 } … … 65 77 if ( $ms_locale !== false ) { 66 78 $locale = $ms_locale; 67 79 } 80 68 81 } else { 69 82 $db_locale = get_option( 'WPLANG' ); 83 70 84 if ( $db_locale !== false ) { 71 85 $locale = $db_locale; 72 86 } … … 76 90 $locale = 'en_US'; 77 91 } 78 92 79 /** This filter is documented in wp-includes/l10n.php */ 80 return apply_filters( 'locale', $locale ); 93 return $locale; 81 94 } 82 95 83 96 /** -
src/wp-includes/ms-blogs.php
486 486 * 487 487 * @param int $new_blog_id The ID of the blog to switch to. Default: current blog. 488 488 * @param bool $deprecated Not used. 489 * @param what to name it? 489 490 * @return true Always returns true. 490 491 */ 491 function switch_to_blog( $new_blog_id, $deprecated = null ) {492 function switch_to_blog( $new_blog_id, $deprecated = null, $options = array() ) { 492 493 global $wpdb; 493 494 495 // better name - flags? switches? what_to_switch? there's gotta be something more descriptive 496 497 $default_options = array( 498 'blog_id' => true, // any valid use case for this being false? 499 'table_prefix' => true, // any valid use case for this being false? 500 'object_cache' => true, 501 'locale' => false, 502 ); 503 504 // add filter for default options too? 505 506 // document filter 507 $options = apply_filters( 508 'switch_blog_options', 509 wp_parse_args( $options, $default_options ) 510 ); 511 512 // add conditions around everything based on existing options 513 494 514 $prev_blog_id = get_current_blog_id(); 495 515 if ( empty( $new_blog_id ) ) { 496 516 $new_blog_id = $prev_blog_id; … … 514 534 * @param int $prev_blog_id Previous blog ID. 515 535 * @param string $context Additional context. Accepts 'switch' when called from switch_to_blog() 516 536 * or 'restore' when called from restore_current_blog(). 537 * @param array $optons explain 517 538 */ 518 do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'switch' );539 do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'switch', $options ); 519 540 $GLOBALS['switched'] = true; 520 541 return true; 521 542 } … … 546 567 } 547 568 } 548 569 570 $switcher_initialized = isset( $GLOBALS['wp_locale_switcher'] ); 571 // also check $GLOBALS['wp_locale_switcher'] instanceof WP_Locale_Switcher ? 572 // make DRY w/ restore_current_blog() 573 574 if ( true === $options['locale'] && $switcher_initialized ) { 575 $new_locale = _get_raw_site_locale(); 576 switch_to_locale( $new_locale ); 577 } 578 549 579 /** This filter is documented in wp-includes/ms-blogs.php */ 550 do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'switch' );580 do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'switch', $options ); 551 581 $GLOBALS['switched'] = true; 552 582 553 583 return true; … … 613 643 } 614 644 } 615 645 646 $should_restore = true; 647 // how to determine? always true? only if the corresponding switch_to_blog() call passed locale=>true ? any other concerns? 648 // or just automatically restonre what the last switch enabled, but do automatically w/out asking ? 649 $switcher_initialized = isset( $GLOBALS['wp_locale_switcher'] ); 650 // also check $GLOBALS['wp_locale_switcher'] instanceof WP_Locale_Switcher ? 651 652 if ( $should_restore && $switcher_initialized ) { 653 // should check is_locale_switched() as well? 654 restore_current_locale(); 655 } 656 616 657 /** This filter is documented in wp-includes/ms-blogs.php */ 617 658 do_action( 'switch_blog', $new_blog_id, $prev_blog_id, 'restore' ); 618 659 -
tests/phpunit/tests/multisite/site.php
133 133 $this->assertFalse( restore_current_blog() ); 134 134 } 135 135 136 // document 137 136 138 /** 139 * 140 * @group switch_to_blog 141 */ 142 function test_switch_blog_locale() { 143 // maybe need data provider to toggle all the individual flags 144 $this->assertTrue( is_main_site() ); 145 $this->assertEquals( 'en_US', get_locale() ); 146 $this->assertEquals( 'en_US', get_user_locale() ); 147 148 $blog_id = self::factory()->blog->create(); 149 // set locale to es_MX ; need to modify factory to allow passing that to constructor, b/c doing switch_to_blog and update_option() would kinda default the point? 150 151 // tes probably failing b/c not auto copying files over 152 153 switch_to_blog( $blog_id, null, array( 'locale' => false ) ); 154 155 $this->assertEquals( 'en_US', get_locale() ); 156 // test actually translating a string? 157 158 // handle plugin/theme textdomains 159 160 restore_current_blog(); 161 162 switch_to_blog( $blog_id, null, array( 'locale' => true ) ); 163 164 $this->assertEquals( 'es_MX', get_locale() ); 165 $this->assertEquals( 'es_MX', get_user_locale() ); 166 // test actually translating a string? 167 168 // handle plugin/theme textdomains 169 170 restore_current_blog(); 171 172 173 // test w/ user_locale on/off? 174 // test during installation? at least manually 175 // test plugin textdomain? 176 } 177 178 /** 137 179 * Test the cache keys and database tables setup through the creation of a site. 138 180 */ 139 181 function test_created_site_details() {