After updating to WordPress 6.7, I’m receiving the following PHP notice on my website. How can I resolve this issue?
Notice: Function _load_textdomain_just_in_time was called incorrectly. Translation loading for the blahblah 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 /wp-includes/functions.php on line 6114
ACCEPTED]
Translation loading for the blahblah domain.
Check your textdomain registration code and make sure the function is set to init hook or later. By textdomain registration code I mean the
load_textdomain
[1],
load_plugin_textdomain
[2], or
load_theme_textdomain
[3] functions.
For example the following code is wrong and should get fixed.
add_action('plugins_loaded', function()
{
load_plugin_textdomain('your-textdomain', false, '/path/to/your/plugin/languages/');
});
The following code is the correct one:
add_action('init', function()
{
load_plugin_textdomain('your-textdomain', false, '/path/to/your/plugin/languages/');
});
If you are using the
get_plugin_data
[4] function before the WordPress init hook, you must pass false as the third parameter or adjust your code logic to ensure it runs after the init hook.
For more information you can check the https://make.wordpress.org/core/2024/10/21/i18n-improvements-6-7/ URL.
[1] https://developer.wordpress.org/reference/functions/load_textdomain/I found a solution that helped me trace the function that was generating an error. Here is the method I used.
The basic idea is to temporarily modify the WordPress core file responsible for loading text domains to log a full function backtrace whenever your specific text domain is called. This will show you exactly what part of your theme or plugin is responsible.
This should only be done for temporary debugging on a development or staging environment. Remember to remove the code after you are done.
Open the file wp-includes/l10n.php.
Find the function _load_textdomain_just_in_time (it's around line 1350 in recent WordPress versions).
Add the following code at the beginning of the function or anywhere before the _doing_it_wrong() function call. Make sure to add your own textdomain "[textdomain]" to the text domain you are debugging.
if ($domain == "[texdomain]") {
// Start output buffering to capture the backtrace string
ob_start();
// The DEBUG_BACKTRACE_IGNORE_ARGS option prevents dumping
// potentially large argument values, keeping the log concise.
debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
// Get the captured backtrace content and clean the buffer
$trace = ob_get_clean();
// Format the final log message
$log_message = "ERROR: Early textdomain call for '" . $domain . "'\n";
$log_message .= "Stack Trace:\n" . $trace . "\n";
$log_message .= "--------------------------------------------------\n";
// Write the message to the server's error log.
// The location of this log file depends on your server's PHP configuration.
error_log($log_message); }
After uploading that code, I refreshed my page. The stack trace in my PHP error log pointed me to the exact string that was generating the error.
The problem was that the line below was being loaded in the theme customizer, which was happening way too early. As a temporary fix to stop the error, I removed the translation function:
//'footer_text' => __('All rights reserved.', '[textdomain]' ),
'footer_text' => 'All rights reserved.',
I manage a lot of websites. Basically, after Wordpres 6.7 update, a few websites which had 'WP_DEBUG' as true, started to show errors about _load_textdomain_just_in_time.
It is happening with a lot of plugins.
define('WP_DEBUG', false); - Benson
Lots of plugins are seeing this error NOT caused by incorrect text domain loading, but by other WordPress functions.
My plugin was using 'get_plugin_data' and getting was this error. I am still seeing it for other WP functions.
I replaced 'get_plugin_data' with
$plugin_data = get_file_data(ABSPATH . 'wp-content/plugins/bbpress/bbpress.php', array('Version' => 'Version'), false);
as a workaround.
But major plugins such as woocommerce (8 million installations)and really simple security (4 million installations) are seeing issues, and I gather it has been raised for a WP fix, rather than forcing plugin authors to work round it.
To fix this issue in your plugin use the following code:
add_action('init', function(){
$mo = 'YOURTEXTDOMAIN-'. determine_locale() . '.mo';
$path = plugin_dir_path(__FILE__) . 'languages/' .$mo ;
load_textdomain( 'YOURTEXTDOMAIN', $path );
});
;
Please note the path should point to the full path of the file.
So you may need to modify it if your .mo file located in a different directory.
The warning is basically saying that a WordPress translation function, e.g. __() or _e() was called way too early. The warning was non-existent prior version 6.7, that is why a lot of plugins and themes triggered it.
If you are a website owner, update all your themes and plugins. Chances are that the developers have already fixed the issue. If you are plugin or theme author or maintaining a custom codebase, you need to make sure the translation functions do not run before the init or after_setup_theme hooks.
For further reading, I have written a detailed guide on how to fix it: How to Fix Function _load_textdomain_just_in_time was called incorrectly [1]
[1] https://nasiothemes.com/how-to-fix-function-_load_textdomain_just_in_time-was-called-incorrectly/What worked for me in similar situation:
error should disappear
if (! str_contains($message, '_load_textdomain_just_in_time') ) {trigger_error($message, $error_level);}but this is hacking core (oo-err). I'd like to use the hookadd_filter( 'wp_trigger_error_run','suppress_text_domain_error',999, 2 ); function suppress_text_domain_error( $message, $error_level) {...}but this doesn't work. - Chris Pinkset_error_handler(function ($errno, $errstr, $errfile, $errline) { if (strpos($errstr, '_load_textdomain_just_in_time') !== false) { return true; // Suppress this specific error. } return false; // Allow other errors to be logged. }, E_USER_NOTICE | E_NOTICE);- lancemonotoneadd_action( 'doing_it_wrong_run', static function ( $function_name ) { if ( '_load_textdomain_just_in_time' === $function_name ) { debug_print_backtrace(); } } );Add this code in the active theme functions.php - To identify from where it's triggering. - mujuonly