[wp-trac] [WordPress Trac] #44937: Add _doing_it_wrong to load_plugin_textdomain

WordPress Trac noreply at wordpress.org
Wed Oct 2 10:08:26 UTC 2024


#44937: Add _doing_it_wrong to load_plugin_textdomain
--------------------------------------+-------------------------
 Reporter:  garrett-eclipse           |       Owner:  swissspidy
     Type:  enhancement               |      Status:  closed
 Priority:  normal                    |   Milestone:  6.7
Component:  I18N                      |     Version:  4.7
 Severity:  normal                    |  Resolution:  fixed
 Keywords:  has-patch needs-dev-note  |     Focuses:
--------------------------------------+-------------------------

Comment (by swissspidy):

 That's not quite possible. It's a bit complicated.

 If a plugin loads translations too early, a code path as follows will be
 executed:

 `load_plugin_textdomain` (or `_load_textdomain_just_in_time` ) ->
 `load_textdomain` -> `determine_locale` -> `get_user_locale` ->
 `wp_get_current_user` -> `wp_set_current_user`

 That means it causes the current user to be set up too early.

 So in most cases the correct user is actually loaded and the locale is
 known. However, other plugins (which could hook into `set_current_user` or
 change translation paths) might not have been loaded yet.

 I see how mentioning `after_setup_theme` is confusing to users though.
 Maybe it should mention `init` instead?

 ----

 I am actually now thinking of a more radical approach:

 (Soft) deprecate `load_plugin_textdomain()` and `load_theme_textdomain()`
 and rely solely on the just-in-time loading and `WP_Textdomain_Registry`.

 This would avoid any `_doing_it_wrong` messages for plugins still using
 `load_plugin_textdomain()`, which seems to be the most common case and
 affects even very big plugins. So it would drastically reduce the noise.

 It would still trigger a `_doing_it_wrong` message if accidentally causing
 the just-in-time loading too early.

 I just opened https://github.com/WordPress/wordpress-develop/pull/7480 to
 discuss this idea.

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/44937#comment:30>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list