bobbingwide / oik-bwtrace

debug trace for WordPress
https://www.oik-plugins.com/oik-plugins/oik-bwtrace-debug-trace-for-wordpress/
GNU General Public License v2.0
6 stars 1 forks source link

Don't perform translations too early #120

Open bobbingwide opened 5 days ago

bobbingwide commented 5 days ago

When testing with WordPress 6.7-beta3 I started getting doing it wrong messages from _load_textdomain_just_in_time

Notice: Function _load_textdomain_just_in_time was called incorrectly. 
Translation loading for the oik-bwtrace domain was triggered too early. 
This is usually an indicator for some code in the plugin or theme running too early. 
Translations should be loaded at the init action or later. Please see [Debugging in WordPress](https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/) for more information. 
(This message was added in version 6.7.0.) 
in C:\apache\htdocs\bwcom\wp-includes\functions.php on line 6099

I analysed the problem here https://github.com/bobbingwide/bobbingwide/issues/122#issuecomment-2428741144 And subsequently wrote a new comment to the WordPress TRAC here https://core.trac.wordpress.org/ticket/44937#comment:54

In this particular instance the fix is to avoid translations until after whatever hook it is after which it's safe to perform translations.

bobbingwide commented 3 days ago

I spent some time trying to understand whether or not the doing it wrong message could be improved to help the user pinpoint the actual cause of the problem. I'd not experienced the infinite loop that was the reason for the message in the first place. During my investigation I wondered whether or not there would be any benefit in tracing the current value that might be being used for the locale. It's not just a case of reporting the value of the global $locale, since this isn't updated by determine_locale(). If oik-bwtrace would want to know this result it would have to hook into the determine_locale filter and save the value of the $determined_locale. The trace record would probably need to show both the global $locale and the most recent $determined_locale.

Should I add this logic in a future version of trace?