-
Notifications
You must be signed in to change notification settings - Fork 1
Description
Context
When activating WooCommerce, an error is triggered related to translation loading happening too early in the WordPress lifecycle. This seems to originate indirectly from a Jetpack dependency, but the error occurs immediately upon activation of the WooCommerce plugin. The installation is managed through a Laravel/WordPress integration layer (Pollora).
Error Message
Function _load_textdomain_just_in_time was called incorrectly.
Translation loading for the `woocommerce` 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 https://developer.wordpress.org/advanced-administration/debug/debug-wordpress/
(This message was added in version 6.7.0.)
Trace:
at public/cms/wp-includes/functions.php:6121
trigger_error( $message, $error_level );Suspected Cause
The error appears to be caused by this piece of code from the automattic/jetpack-connection package, which uses a translation function too early:
public static function cron_schedules( $schedules ) {
$schedules['monthly'] = array(
'interval' => 2635200,
'display' => __( 'Monthly', 'woocommerce' ),
);
$schedules['fifteendays'] = array(
'interval' => 1296000,
'display' => __( 'Every 15 Days', 'woocommerce' ),
);
return $schedules;
}The __() function triggers translation loading, but the woocommerce text domain hasn't been registered yet at that point—likely during the registration of the cron_schedules filter.
Additional Hypothesis
We use a custom Laravel/WordPress integration layer (Pollora) which bootstraps WordPress in a non-standard way. It's possible that this setup exposes the issue earlier than a traditional WordPress install would.
Questions
- Is this behavior already known in the context of Jetpack or WooCommerce?
- Is there a recommended approach to safely hook into
cron_scheduleswithout using translations too early? - Should calls to
__()be avoided in filters/actions that are run beforeinit? - Could this be mitigated by delaying the translation-dependent parts using an
add_action('init', ...)? - Could we do something on our side (in Pollora) to mitigate the issue, or is this something that should be fixed upstream?
Environment
- WordPress 6.7.x
- Latest stable WooCommerce
- Jetpack (via
automattic/jetpack-connection) - Laravel + WordPress (Pollora framework)
- Fresh WooCommerce plugin activation (if not, just run :
wp cron event delete jetpack_clean_noncesto reset the schedule declaration