[wp-trac] [WordPress Trac] #44937: Add _doing_it_wrong to load_plugin_textdomain
WordPress Trac
noreply at wordpress.org
Thu Sep 13 09:13:21 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:
-----------------------------+------------------------------
Comment (by garrett-eclipse):
Thanks @swissspidy I appreciate the `2nd-opinion`
Replying to [comment:1 swissspidy]:
> This happens after `plugins_loaded`, so the first time you can be sure
that everything is set up is in the `init` hook.
Just to confirm this specific case the load_*_textdomain should be called
in the `init` hook. [[BR]]
So the Codex example should update from `plugins_loaded` to `init` -
https://codex.wordpress.org/Function_Reference/load_plugin_textdomain#Examples
And would the recommended hooks for themes be valid? -
https://codex.wordpress.org/Function_Reference/load_theme_textdomain
Replying to [comment:1 swissspidy]:
> 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 :-)
Exposing this would be very helpful to theme/plugin developers where core
functions are reliant on other actions.
Aside from localization anomalies, I'm sure others can add to the list of
calling core functions too early in their plugin, theme, code.
I do see a use of the _doing_it_wrong function throughout core but wonder
if it needs to become more of a convention.
Maybe an addition to the handbook on coding core functions to take into
account reliance on actions. [[BR]]
https://make.wordpress.org/core/handbook/best-practices/coding-
standards/php/
These warnings are helpful to developers especially when adopting new
(maybe just to them) functions that are reliable on action hooks. It flags
edge case issues such as i18n that developers may not catch and if action
reliance ever changes due to new features such as user locales the warning
can be updated which devs can catch in beta/RC.
A good example in core of _doing_it_wrong in context of actions hooks can
be found in `_wp_scripts_maybe_doing_it_wrong`;[[BR]]
https://github.com/WordPress/WordPress/blob/56c162fbc9867f923862f64f1b4570d885f1ff03
/wp-includes/functions.wp-scripts.php#L36-L52
--
Ticket URL: <https://core.trac.wordpress.org/ticket/44937#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list