Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Notice: Function _load_textdomain_just_in_time was called incorrectly #625

Open
oldrup opened this issue Oct 17, 2024 · 10 comments · May be fixed by #627
Open

Notice: Function _load_textdomain_just_in_time was called incorrectly #625

oldrup opened this issue Oct 17, 2024 · 10 comments · May be fixed by #627

Comments

@oldrup
Copy link

oldrup commented Oct 17, 2024

Describe the bug

_Notice: Function load_textdomain_just_in_time was called incorrectly. Translation loading for the antispam-bee 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 for more information. (This message was added in version 6.7.0.) in /home/mkjqekzy/public_html/wp-includes/functions.php on line 6099

To Reproduce
Steps to reproduce the behavior:

  1. Install WordPress beta tester plugin
  2. Update to WordPress 6.7 beta 3
  3. Enable WP_DEBUG
  4. Enable AntiSpam Bee

Expected behavior
It looks like a deprecation warning of some sort. Not that unexpected really ;)

System (please complete the following information):

  • WordPress 6.7 beta 3
  • Firefox browser
  • PHP 8.2.x

Additional context
Add any other context about the problem here.
image

@Zodiac1978
Copy link
Member

Thanks for the report @oldrup !

I hoped this was already fixed: #423

We will have a look why this happens again ...

@Zodiac1978
Copy link
Member

Maybe this is because we load the textdomain here in the "init" function:
https://github.com/pluginkollektiv/antispam-bee/blob/master/antispam_bee.php#L155

Which is on the "plugins_loaded" hook:
https://github.com/pluginkollektiv/antispam-bee/blob/master/antispam_bee.php#L2987-L2994

But the documentation is not clear about which hook is correct:
https://developer.wordpress.org/reference/functions/load_plugin_textdomain/

@oldrup
Copy link
Author

oldrup commented Oct 17, 2024

Well, keep in mind I encountered this warning with WordPress 6.7 beta 3. A lot might still change, and this can also be an issue with core, I just wanted to bring it to your attention. AntiSpam Bee still filters just fine, so no cheap viagra for me, I suppose 🙄

@2ndkauboy
Copy link
Member

This is probably related to this change: https://core.trac.wordpress.org/ticket/44937

We have to take another look at this.

@Zodiac1978
Copy link
Member

Yes, @luminuu was posting this ticket on X/Twitter too.

Looks like this could be the second call here:
https://github.com/pluginkollektiv/antispam-bee/blob/master/antispam_bee.php#L2556

This is called on the comment_post action hook, which could be the problematic trigger here.

@2ndkauboy
Copy link
Member

But that wouldn't trigger when navigating to the Dashboard, right?

I can debug this locally with XDebug and 6.7 beta 3 later.

@Zodiac1978
Copy link
Member

Zodiac1978 commented Oct 17, 2024

But that wouldn't trigger when navigating to the Dashboard, right?

If this is not the problem, we maybe should change plugins_loaded to init - as this is mentioned here:
https://developer.wordpress.org/plugins/internationalization/how-to-internationalize-your-plugin/#loading-text-domain

The docs for load_plugin_textdomain are not clear here, but the example clearly says init.

I can debug this locally with XDebug and 6.7 beta 3 later.

This would be great!

@Zodiac1978
Copy link
Member

Zodiac1978 commented Oct 17, 2024

@swissspidy was suggesting on X/Twitter to get rid of the load_plugin_textdomain completely. This would need WP 4.6, so we need to raise the version from 4.5 to 4.6:

https://make.wordpress.org/core/2016/07/06/i18n-improvements-in-4-6/

https://github.com/pluginkollektiv/antispam-bee/blob/master/readme.txt#L5

@swissspidy
Copy link
Contributor

Tip: Query Monitor is very helpful to see the stack trace of how such warnings are triggered.

For Antispam Bee, it looks as follows:

In WordPress 6.6 and below:

plugins_loaded -> Antispam_Bee::init() -> Antispam_Bee::load_plugin_lang() -> calls load_plugin_textdomain() and thus triggers translation loading.

In WordPress 6.7, load_plugin_textdomain() was changed slightly to defer translation loading until they are really needed, reducing the chance for getting those new doing_it_wrong warnings. However, for Antispam Bee, nothing really changes, just the order is slightly different.

In WordPress 6.7:

plugins_loaded -> Antispam_Bee::init() -> Antispam_Bee::add_reasons_to_defaults() -> calls esc_attr__() and thus triggers translation loading.

The easiest fix would be to call Antispam_Bee::init() on init instead of plugins_loaded. You will have to check whether that works for you and all tests still pass etc.

Alternatively, you could probably remove the self::add_reasons_to_defaults(); call to within the _init_internal_vars() method. Though add_reasons_to_defaults() mentions it's separate for some reason, so you will have to test that.

Either solution will resolve the new warnings though.

(And yes, if you bump your WP version requirement, you can totally remove the load_plugin_textdomain() call)

@2ndkauboy
Copy link
Member

@swissspidy thanks for the explanation! I was also able to reproduce this with Xdebug locally.

Can you please take a look at the PR? This should resolve it. At least, I don't see any notice locally anymore.

@pluginkollektiv pluginkollektiv deleted a comment Oct 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants
@swissspidy @Zodiac1978 @2ndkauboy @oldrup and others