Commit 1b728de9757 for woocommerce
commit 1b728de975706069ab353ec10597d31e7b4229d4
Author: James Kemp <me@jckemp.com>
Date: Tue Dec 1 22:23:03 2026 +0000
Fix text domain notice when cron schedules load before init (#71327)
* Fix text domain notice when cron schedules load before init
* Add changefile(s) from automation for the following project(s): woocommerce
* Translate cron schedule labels only after after_setup_theme or once the text domain is loaded
---------
Co-authored-by: woocommercebot <woocommercebot@users.noreply.github.com>
diff --git a/plugins/woocommerce/changelog/71327-fix-71293-load-textdomain-just-in-time-notice b/plugins/woocommerce/changelog/71327-fix-71293-load-textdomain-just-in-time-notice
new file mode 100644
index 00000000000..9839e1bbfa4
--- /dev/null
+++ b/plugins/woocommerce/changelog/71327-fix-71293-load-textdomain-just-in-time-notice
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Fix a warning about translations loading too early that could appear after activating WooCommerce and break page redirects.
diff --git a/plugins/woocommerce/includes/class-wc-install.php b/plugins/woocommerce/includes/class-wc-install.php
index 8d03f60c77c..d2d54a2ff53 100644
--- a/plugins/woocommerce/includes/class-wc-install.php
+++ b/plugins/woocommerce/includes/class-wc-install.php
@@ -1128,13 +1128,16 @@ class WC_Install {
* @return array
*/
public static function cron_schedules( $schedules ) {
+ // Translating before `after_setup_theme` would load the text domain too early (WP 6.7+ notice), so fall back to English labels unless that hook has run (or is running) or the text domain is already loaded.
+ $translate = did_action( 'after_setup_theme' ) || doing_action( 'after_setup_theme' ) || is_textdomain_loaded( 'woocommerce' );
+
$schedules['monthly'] = array(
'interval' => MONTH_IN_SECONDS,
- 'display' => __( 'Monthly', 'woocommerce' ),
+ 'display' => $translate ? __( 'Monthly', 'woocommerce' ) : 'Monthly',
);
$schedules['fifteendays'] = array(
'interval' => 15 * DAY_IN_SECONDS,
- 'display' => __( 'Every 15 Days', 'woocommerce' ),
+ 'display' => $translate ? __( 'Every 15 Days', 'woocommerce' ) : 'Every 15 Days',
);
return $schedules;
}
diff --git a/plugins/woocommerce/tests/php/includes/class-wc-install-test.php b/plugins/woocommerce/tests/php/includes/class-wc-install-test.php
index fb589f58ba4..03f43ee88b9 100644
--- a/plugins/woocommerce/tests/php/includes/class-wc-install-test.php
+++ b/plugins/woocommerce/tests/php/includes/class-wc-install-test.php
@@ -405,6 +405,65 @@ class WC_Install_Test extends \WC_Unit_Test_Case {
}
}
+ /**
+ * @testdox Cron schedule labels are not translated before after_setup_theme and init, but are translated afterwards.
+ */
+ public function test_cron_schedules_are_not_translated_before_init(): void {
+ global $wp_actions, $l10n;
+
+ $translate = fn( $translation ) => 'translated:' . $translation;
+ add_filter( 'gettext', $translate );
+
+ $original_init_count = $wp_actions['init'] ?? null;
+ $original_setup_count = $wp_actions['after_setup_theme'] ?? null;
+ $original_l10n = $l10n['woocommerce'] ?? null;
+ unset( $wp_actions['init'], $wp_actions['after_setup_theme'], $l10n['woocommerce'] );
+
+ try {
+ $early = WC_Install::cron_schedules( array() );
+
+ // After `after_setup_theme` but before `init`, translations are safe to load.
+ $wp_actions['after_setup_theme'] = 1; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- Simulate the hook having fired.
+
+ $setup = WC_Install::cron_schedules( array() );
+ unset( $wp_actions['after_setup_theme'] );
+
+ // Before both hooks, but with the text domain already loaded, translations are also safe.
+ $l10n['woocommerce'] = new Translations(); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- Simulate a loaded text domain.
+
+ $loaded = WC_Install::cron_schedules( array() );
+ } finally {
+ if ( null !== $original_init_count ) {
+ $wp_actions['init'] = $original_init_count; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- Restore the init action count after simulating a pre-init call.
+ }
+ if ( null !== $original_setup_count ) {
+ $wp_actions['after_setup_theme'] = $original_setup_count; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- Restore the action count.
+ }
+ if ( null !== $original_l10n ) {
+ $l10n['woocommerce'] = $original_l10n; // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited -- Restore the loaded text domain.
+ } else {
+ unset( $l10n['woocommerce'] );
+ }
+ }
+
+ $late = WC_Install::cron_schedules( array() );
+ remove_filter( 'gettext', $translate );
+
+ $this->assertSame( 'translated:Monthly', $setup['monthly']['display'] );
+ $this->assertSame( 'translated:Every 15 Days', $setup['fifteendays']['display'] );
+
+ $this->assertSame( 'translated:Monthly', $loaded['monthly']['display'] );
+ $this->assertSame( 'translated:Every 15 Days', $loaded['fifteendays']['display'] );
+
+ $this->assertSame( 'Monthly', $early['monthly']['display'] );
+ $this->assertSame( 'Every 15 Days', $early['fifteendays']['display'] );
+ $this->assertSame( MONTH_IN_SECONDS, $early['monthly']['interval'] );
+ $this->assertSame( 15 * DAY_IN_SECONDS, $early['fifteendays']['interval'] );
+
+ $this->assertSame( 'translated:Monthly', $late['monthly']['display'] );
+ $this->assertSame( 'translated:Every 15 Days', $late['fifteendays']['display'] );
+ }
+
/**
* @testdox Stores already on 11.3 schedule the MPN schema migration when upgrading.
*/