#62564 closed defect (bug) (worksforme)
Wrong warning about _load_textdomain_just_in_time used incorrectly if $theme->__toString()
Reported by: |
|
Owned by: | |
---|---|---|---|
Milestone: | Priority: | normal | |
Severity: | normal | Version: | 6.7 |
Component: | I18N | Keywords: | |
Focuses: | Cc: |
Description
One of my installed plugins has these lines in its initialization function:
<?php $current_theme = wp_get_theme(); if ('Flatsome' == $current_theme) { // Do something } else { // Do a different thing }
The issue here is that the implicit \_\_toString() call in the theme class ultimately calls
translate("My Child Theme Name","my-theme-name")
which generates a wrong warning about _load_textdomain_just_in_time used incorrectly, saying that the culprit is the theme code, when the backtraces shows this is not the case.
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.
Change History (4)
#1
@
7 months ago
- Component changed from General to I18N
- Milestone Awaiting Review deleted
- Resolution set to worksforme
- Status changed from new to closed
#2
@
7 months ago
- Component changed from I18N to Users
- Keywords needs-testing reporter-feedback added
- Severity changed from normal to critical
- Summary changed from Wrong warning about _load_textdomain_just_in_time used incorrectly if $theme->__toString() is called in plugin initialization to Invalid username
- Version changed from 6.7 to 6.7.1
#3
@
7 months ago
- Component changed from Users to I18N
- Keywords needs-testing reporter-feedback removed
- Severity changed from critical to normal
- Summary changed from Invalid username to Wrong warning about _load_textdomain_just_in_time used incorrectly if $theme->__toString()
- Version changed from 6.7.1 to 6.7
@rinkalpagdar maybe it was done by accident, please don't hijack a ticket like that :)
Note: See
TracTickets for help on using
tickets.
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 callwp_get_theme()
. If you do that, then you would not get such a 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 simplyget_stylesheet()