[wp-trac] [WordPress Trac] #62564: Wrong warning about _load_textdomain_just_in_time used incorrectly if $theme->__toString() is called in plugin initialization

WordPress Trac noreply at wordpress.org
Mon Nov 25 13:38:30 UTC 2024


#62564: Wrong warning about _load_textdomain_just_in_time used incorrectly if
$theme->__toString() is called in plugin initialization
--------------------------+-------------------------
 Reporter:  DaveFX        |       Owner:  (none)
     Type:  defect (bug)  |      Status:  closed
 Priority:  normal        |   Milestone:
Component:  I18N          |     Version:  6.7
 Severity:  normal        |  Resolution:  worksforme
 Keywords:                |     Focuses:
--------------------------+-------------------------
Changes (by swissspidy):

 * status:  new => closed
 * resolution:   => worksforme
 * component:  General => I18N
 * milestone:  Awaiting Review =>


Comment:

 > One of my installed plugins has these lines in its initialization
 function:

 How is this function defined and when is it called? Please share the full
 code.

 This warning is only triggered if you trigger a translation call too
 early, for example if you are not waiting until `init` or so.

 You should wait until `after_setup_theme` to call `wp_get_theme()`. If you
 do that, then you would not get such a warning.

 > I honestly think this is an issue from WordPress Core, as this _
 _toString() call to get the theme name shouldn't ever generate this
 warning.

 Why not? The `WP_Theme::__toString()` docblock explicitly says the string
 will be translated. And if you trigger a translation too early, then you
 should get a warning.
 Changing the `__toString()` method would be a back compat break.

 If you want the untranslated theme name, which for your code example would
 be desired anyway, use `$current_theme->get( 'Name' )` or simply
 `get_stylesheet()`

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


More information about the wp-trac mailing list