[wp-trac] [WordPress Trac] #44937: Add _doing_it_wrong to load_plugin_textdomain
WordPress Trac
noreply at wordpress.org
Thu Sep 13 07:19:26 UTC 2018
#44937: Add _doing_it_wrong to load_plugin_textdomain
-----------------------------+------------------------------
Reporter: garrett-eclipse | Owner: (none)
Type: enhancement | Status: new
Priority: normal | Milestone: Awaiting Review
Component: I18N | Version: 4.7
Severity: normal | Resolution:
Keywords: 2nd-opinion | Focuses:
-----------------------------+------------------------------
Changes (by swissspidy):
* keywords: => 2nd-opinion
* focuses: coding-standards =>
Comment:
> I'm unsure the root of the issue but I assume the plugin loads prior to
the user so their locale isn't available when the MO object is loaded into
the $l10n global.
That's the reason, yes.
Plugins are loaded early in `wp-settings.php`, way before the default
translations are loaded and the current user is set up.
See https://github.com/WordPress/wordpress-
develop/blob/e29d895ffd7388fcb6c73c1c5f6057204096dc03/src/wp-
settings.php#L307 and https://github.com/WordPress/wordpress-
develop/blob/e29d895ffd7388fcb6c73c1c5f6057204096dc03/src/wp-
settings.php#L404-L450
This happens after `plugins_loaded`, so the first time you can be sure
that everything is set up is in the `init` hook.
IMO it's a rule of thumb that you shouldn't run any code directly without
hooking into some action. This scenario with `load_*_textdomain()` (which
I know people run into from time to time) is just one example. And it's a
known one. After all the blog post you linked to is over 8 years old :-)
--
Ticket URL: <https://core.trac.wordpress.org/ticket/44937#comment:1>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list