#62564 closed defect (bug) (worksforme)
Wrong warning about _load_textdomain_just_in_time used incorrectly if $theme->__toString()
| Reported by: | DaveFX | Owned by: | |
|---|---|---|---|
| Priority: | normal | Milestone: | |
| Component: | I18N | Version: | 6.7 |
| Severity: | normal | Keywords: | |
| Cc: | Focuses: |
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
@
21 months ago
- Component General → I18N
- Milestone Awaiting Review
- Resolution → worksforme
- Status new → closed
#2
@
21 months ago
- Component I18N → Users
- Keywords needs-testing reporter-feedback added
- Severity normal → critical
- Summary Wrong warning about _load_textdomain_just_in_time used incorrectly if $theme->__toString() is called in plugin initialization → Invalid username
- Version 6.7 → 6.7.1
#3
@
21 months ago
- Component Users → I18N
- Keywords needs-testing reporter-feedback removed
- Severity critical → normal
- Summary Invalid username → Wrong warning about _load_textdomain_just_in_time used incorrectly if $theme->__toString()
- Version 6.7.1 → 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.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)
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
initor so.You should wait until
after_setup_themeto 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()