Make WordPress Core

Opened 2 months ago

Closed 2 months ago

Last modified 8 weeks ago

#62154 closed defect (bug) (duplicate)

Latest beta Warnings Function load_plugin_textdomain was called incorrectly.

Reported by: neo2k23's profile neo2k23 Owned by:
Milestone: Priority: normal
Severity: normal Version: 6.7
Component: I18N Keywords:
Focuses: Cc:

Description

I installed the latest beta trunk release and i get i don't know how many warnings in my admin area

Please provide details on how to fix them. It seems that almost every plugin creates a issue.

Notice: Function load_plugin_textdomain was called incorrectly. Attempted to load translations for the rtl-tester domain too early. Translations should be loaded after the after_setup_theme action has fired, to ensure that the current user is already set up. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/docs/public/wp-includes/functions.php on line 6099

Notice: Function load_plugin_textdomain was called incorrectly. Attempted to load translations for the temporary-login-without-password domain too early. Translations should be loaded after the after_setup_theme action has fired, to ensure that the current user is already set up. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/docs/public/wp-includes/functions.php on line 6099

Notice: Function load_plugin_textdomain was called incorrectly. Attempted to load translations for the wp-sweep domain too early. Translations should be loaded after the after_setup_theme action has fired, to ensure that the current user is already set up. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/docs/public/wp-includes/functions.php on line 6099

Notice: Function load_plugin_textdomain was called incorrectly. Attempted to load translations for the elementor-pro domain too early. Translations should be loaded after the after_setup_theme action has fired, to ensure that the current user is already set up. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/docs/public/wp-includes/functions.php on line 6099

Notice: Function load_plugin_textdomain was called incorrectly. Attempted to load translations for the reveal-ids-for-wp-admin-25 domain too early. Translations should be loaded after the after_setup_theme action has fired, to ensure that the current user is already set up. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/docs/public/wp-includes/functions.php on line 6099

Notice: Function load_plugin_textdomain was called incorrectly. Attempted to load translations for the revslider domain too early. Translations should be loaded after the after_setup_theme action has fired, to ensure that the current user is already set up. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/docs/public/wp-includes/functions.php on line 6099

Notice: Function load_plugin_textdomain was called incorrectly. Attempted to load translations for the revsliderhelp domain too early. Translations should be loaded after the after_setup_theme action has fired, to ensure that the current user is already set up. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/docs/public/wp-includes/functions.php on line 6099

Notice: Function load_plugin_textdomain was called incorrectly. Attempted to load translations for the temporary-login-without-password domain too early. Translations should be loaded after the after_setup_theme action has fired, to ensure that the current user is already set up. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/docs/public/wp-includes/functions.php on line 6099

Notice: Function load_plugin_textdomain was called incorrectly. Attempted to load translations for the woocommerce-beta-tester domain too early. Translations should be loaded after the after_setup_theme action has fired, to ensure that the current user is already set up. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/docs/public/wp-includes/functions.php on line 6099

Notice: Function load_plugin_textdomain was called incorrectly. Attempted to load translations for the esg-fonts-addon domain too early. Translations should be loaded after the after_setup_theme action has fired, to ensure that the current user is already set up. Please see Debugging in WordPress for more information. (This message was added in version 6.7.0.) in /var/docs/public/wp-includes/functions.php on line 6099

Warning: Cannot modify header information - headers already sent by (output started at /var/docs/public/wp-includes/functions.php:6099) in /var/docs/public/wp-admin/includes/misc.php on line 1438

Change History (16)

#1 @mukesh27
2 months ago

  • Component changed from General to I18N
  • Milestone Awaiting Review deleted
  • Resolution set to duplicate
  • Status changed from new to closed

Duplicate of #62144.

Per @swissspidy comment.

A dev-note (blog post) will be published in time so that plugin developers can take appropriate action.

#2 follow-up: @swissspidy
2 months ago

Please provide details on how to fix them. It seems that almost every plugin creates a issue.

In most cases it means the plugin can simply remove any load_plugin_textdomain() calls they have in their plugin. WordPress will automatically load the translation for them.

There can be more complex cases though, which the dev-note will cover.

#3 @swissspidy
2 months ago

Duplicate of #44937.

#4 in reply to: ↑ 2 @room34
2 months ago

Replying to swissspidy:

Please provide details on how to fix them. It seems that almost every plugin creates a issue.

In most cases it means the plugin can simply remove any load_plugin_textdomain() calls they have in their plugin. WordPress will automatically load the translation for them.

There can be more complex cases though, which the dev-note will cover.

Does WordPress automatically load the translations prior to 6.7, or is that a new feature? If it's new, then we'd still need to keep the code in the plugin for earlier WordPress versions, and add a version check to determine whether or not to run the function.

Also, I'm not sure what the reason is, but my plugins are generating the notice twice. That is to say, they were generating the notice twice when I was calling load_plugin_textdomain() on the plugins_loaded hook. When I move it to the after_setup_theme hook, I continue to get the notice once.

#5 @swissspidy
2 months ago

There are two different notices, one for an early manual call, and another one if the automated call happens too early. In Beta 2 the former one will go away.

Does WordPress automatically load the translations prior to 6.7, or is that a new feature?

This has been a feature since WordPress 4.6

#6 @room34
2 months ago

Maybe what I'm dealing with here is slightly different.

I'm testing my plugins with 6.7-beta1, and I'm getting these warnings only on a Multisite installation. I get them even after I remove the function call from my plugin entirely, so it's not the plugin that's causing the error… it seems to be Multisite itself.

Regardless of that, what you're saying is that since WordPress 4.6 there has been no need for plugins to call this function in order for their translations to load, is that correct? If so, I'll go ahead and remove the code, since I don't support that far back anyway.

Last edited 2 months ago by room34 (previous) (diff)

#7 @swissspidy
2 months ago

Again, the warning can still happen even if you remove the function call, because some of your code triggers the automatic translation loading too early.

I recommend waiting for Beta 2 & watching out for the dev-note post for updates. Then you can leave a comment on the post or the original ticket if sonething is still not quite right.

And yes, most probably you can remove that function call. Only if you load translations from a custom location, i.e. if your plugin is not hosted on WordPress.org, you might still need it. I recommend trying it yourself and reading https://make.wordpress.org/core/2016/07/06/i18n-improvements-in-4-6/

#8 follow-up: @room34
2 months ago

I poked around a bit further and determined that the call that is generating the notice is at line 151 in wp-admin/includes/plugin.php in the _get_plugin_data_markup_translate() function.

The above private function is called by the public function get_plugin_data() which I do use in my plugins, fairly early. I see that function has a parameter to bypass translation, so that seems to be my fix. Sharing here in case any other plugin developers are experiencing the same!

#9 @swissspidy
2 months ago

This will already be covered by the dev-note, so please look out for it. It will be published soon!

#10 @neo2k23
2 months ago

@swissspidy

with all due respect you want us to test beta builds and report issues. Testing with debug mode on in the latest beta is impossible due to all these notifications which wrecking up the admin area.

I would like to get a interim solution to suppress only these messages so i can continue to test the latest wp builds.

thank you

#11 @swissspidy
2 months ago

There are hooks to disable such notices during development, see https://developer.wordpress.org/reference/functions/_doing_it_wrong/

#12 @neo2k23
2 months ago

@swissspidy

This is not very helpfull, instead of just providing the line of code one needs to add your are sending everybody who lands here to the function to figure it out themselves.

"This will already be covered by the dev-note, so please look out for it. It will be published soon!"

#13 @swissspidy
2 months ago

Apologies if you don‘t find that helpful. I am on vacatiom and don’t have the capacity to write detailed code snippets on my phone. The filter accepts a boolean, so it should be trivial to figure out how to use it based on the docs.
You can also update to the katest nightly build using the WordPress Beta Tester plugin, turn off WP_DEBUG, or turn off any plugins. So there are really a lot of options to take.

#14 @neo2k23
2 months ago

That would require something like this.

<?php
                function theme_hide_doing_it_wrong_notice($trigger, $function, $message, $version) { 
                        if($function == 'load_plugin_textdomain') return false;

                        return $trigger; 
                }

                add_filter( "doing_it_wrong_trigger_error", "theme_hide_doing_it_wrong_notice", 10, 4 );

#15 in reply to: ↑ 8 @room34
2 months ago

Here's another unexpected twist. I'm just trying to add translation support to another of my plugins. I use Poedit for this, as is recommended in the documentation: https://developer.wordpress.org/plugins/internationalization/localization/#poedit

Poedit would not generate the .pot file, saying the plugin was not translation-ready. An error in the Poedit log file indicated that load_plugin_textdomain() was missing, among a couple of other things. I temporarily added the function call to the plugin, and Poedit was then able to create the file.

I did confirm that Poedit seems to be able to work with the plugin fine after creating the .pot file even with load_plugin_textdomain() removed; it just needs to be in the plugin during the initial file creation. Still, this is likely why a lot of plugins call that function even if they technically don't need to, and I'm sure many of plugin developers also use Poedit.

From what I've seen here, this likely won't be an issue if plugins don't call the function too early, but it does complicate the suggestion that plugins don't need to call the function at all.

UPDATE: Well, I feel a bit silly about this. I realized shortly after I posted this that there's another option… if the comments at the top of the main plugin file include Domain Path: then load_plugin_textdomain() is not needed for Poedit to generate the file. Still… since a lot of plugins (not just mine) are generating the error, it's worth mentioning.

Last edited 2 months ago by room34 (previous) (diff)

#16 @room34
8 weeks ago

Another issue: [ACF Blocks](https://www.advancedcustomfields.com/resources/blocks/) won't load translations unless load_plugin_textdomain() is explicitly called on the plugins_loaded action. I've tried it on after_setup_theme and init, and the translations don't load.

Of course, ACF Blocks don't seem to work right with 6.7-beta2 anyway, so there are other issues going on. But I've found this issue with the translations also affects 6.6.2.

Note: See TracTickets for help on using tickets.