[wp-trac] [WordPress Trac] #44844: switch_to_locale does not handle plugins/themes properly in multisite

WordPress Trac noreply at wordpress.org
Tue Aug 28 06:35:57 UTC 2018


#44844: switch_to_locale does not handle plugins/themes properly in multisite
--------------------------+------------------------------
 Reporter:  pcfreak30     |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  I18N          |     Version:  4.9.8
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------

Comment (by pcfreak30):

 After further troubleshooting I have made this test script as the original
 test code posted was flawed.

 {{{#!php
 <?php
 require_once( dirname( __FILE__ ) . '/wp-load.php' );

 function test_unload_textdomain( $domain ) {
         if ( isset( $GLOBALS['l10n'][ $domain ] ) ) {
                 unset( $GLOBALS['l10n'][ $domain ] );
                 unset( $GLOBALS['l10n_unloaded'][ $domain ] );

         }
 }

 function one_time_false() {
         remove_filter( 'locale',  'one_time_false' );

         return false;
 }

 add_action( 'unload_textdomain', 'test_unload_textdomain' );
 add_filter( 'locale', 'one_time_false' );
 switch_to_blog( 3 );
 switch_to_locale( 'fi' );
 $GLOBALS['wp_rewrite']->init();
 do_action( 'init');
 var_dump( __( 'some label', 'my-domain' ), get_term_link( 123 ) );
 }}}

 It covers the following what I consider bugs.

 * Does not switch the locale
 * Does not rebuild all post types/taxonomies
 * Does not re-init wp_rewrite to have the right settings for the current
 subsite

 My use case has been in Multisite different subsites may have had
 different rewrite settings and some post type slugs were translated. This
 has made up a combination of very hard edge cases to track down.

 As of now it seems without this you can only make background requests to
 each subsite or force cron to only process items that have a blog id of
 what the current blog is.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/44844#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list