Commit 9341598939 for woocommerce
commit 93415989394c65c170c8f180e6528c39da6d0883
Author: Néstor Soriano <konamiman@konamiman.com>
Date: Wed Jan 7 09:11:33 2026 +0100
Remove usage of feature_is_enabled in ProductVersionStringInvalidator::init (#62665)
* Check feature option instead of feature_is_enabled in ProductVersionStringInvalidator
This is to avoid "Translation loading for the woocommerce domain was
triggered too early" warnings caused by the "init" method of the class
being invoked before the "init" action.
diff --git a/plugins/woocommerce/changelog/pr-62665 b/plugins/woocommerce/changelog/pr-62665
new file mode 100644
index 0000000000..87f1eda192
--- /dev/null
+++ b/plugins/woocommerce/changelog/pr-62665
@@ -0,0 +1,4 @@
+Significance: patch
+Type: fix
+
+Remove usage of feature_is_enabled in ProductVersionStringInvalidator::init
diff --git a/plugins/woocommerce/src/Internal/Caches/ProductVersionStringInvalidator.php b/plugins/woocommerce/src/Internal/Caches/ProductVersionStringInvalidator.php
index 75bd23d9ff..159b3af7b3 100644
--- a/plugins/woocommerce/src/Internal/Caches/ProductVersionStringInvalidator.php
+++ b/plugins/woocommerce/src/Internal/Caches/ProductVersionStringInvalidator.php
@@ -27,16 +27,17 @@ class ProductVersionStringInvalidator {
* - The REST API caching feature is enabled
* - The backend caching setting is active
*
- * @param FeaturesController $features_controller The features controller.
- *
* @return void
*
* @since 10.5.0
*
* @internal
*/
- final public function init( FeaturesController $features_controller ): void {
- if ( ! $features_controller->feature_is_enabled( 'rest_api_caching' ) ) {
+ final public function init(): void {
+ // We can't use FeaturesController::feature_is_enabled at this point
+ // (before the 'init' action is triggered) because that would cause
+ // "Translation loading for the woocommerce domain was triggered too early" warnings.
+ if ( 'yes' !== get_option( 'woocommerce_feature_rest_api_caching_enabled' ) ) {
return;
}
diff --git a/plugins/woocommerce/tests/php/src/Internal/Caches/ProductVersionStringInvalidatorTest.php b/plugins/woocommerce/tests/php/src/Internal/Caches/ProductVersionStringInvalidatorTest.php
index 9fbfd48e74..a5ee7a7178 100644
--- a/plugins/woocommerce/tests/php/src/Internal/Caches/ProductVersionStringInvalidatorTest.php
+++ b/plugins/woocommerce/tests/php/src/Internal/Caches/ProductVersionStringInvalidatorTest.php
@@ -44,6 +44,7 @@ class ProductVersionStringInvalidatorTest extends \WC_Unit_Test_Case {
* Tear down test.
*/
public function tearDown(): void {
+ delete_option( 'woocommerce_feature_rest_api_caching_enabled' );
delete_option( 'woocommerce_rest_api_enable_backend_caching' );
parent::tearDown();
}
@@ -55,10 +56,8 @@ class ProductVersionStringInvalidatorTest extends \WC_Unit_Test_Case {
*/
private function get_invalidator_with_hooks_enabled(): ProductVersionStringInvalidator {
$features_controller = $this->createMock( FeaturesController::class );
- $features_controller->method( 'feature_is_enabled' )
- ->with( 'rest_api_caching' )
- ->willReturn( true );
+ update_option( 'woocommerce_feature_rest_api_caching_enabled', 'yes' );
update_option( 'woocommerce_rest_api_enable_backend_caching', 'yes' );
$invalidator = new ProductVersionStringInvalidator();
@@ -100,10 +99,8 @@ class ProductVersionStringInvalidatorTest extends \WC_Unit_Test_Case {
*/
public function test_hooks_not_registered_when_feature_disabled() {
$features_controller = $this->createMock( FeaturesController::class );
- $features_controller->method( 'feature_is_enabled' )
- ->with( 'rest_api_caching' )
- ->willReturn( false );
+ update_option( 'woocommerce_feature_rest_api_caching_enabled', 'no' );
update_option( 'woocommerce_rest_api_enable_backend_caching', 'yes' );
$invalidator = new ProductVersionStringInvalidator();
@@ -119,10 +116,8 @@ class ProductVersionStringInvalidatorTest extends \WC_Unit_Test_Case {
*/
public function test_hooks_not_registered_when_backend_caching_disabled() {
$features_controller = $this->createMock( FeaturesController::class );
- $features_controller->method( 'feature_is_enabled' )
- ->with( 'rest_api_caching' )
- ->willReturn( true );
+ update_option( 'woocommerce_feature_rest_api_caching_enabled', 'yes' );
update_option( 'woocommerce_rest_api_enable_backend_caching', 'no' );
$invalidator = new ProductVersionStringInvalidator();
@@ -138,10 +133,8 @@ class ProductVersionStringInvalidatorTest extends \WC_Unit_Test_Case {
*/
public function test_hooks_not_registered_when_backend_caching_not_set() {
$features_controller = $this->createMock( FeaturesController::class );
- $features_controller->method( 'feature_is_enabled' )
- ->with( 'rest_api_caching' )
- ->willReturn( true );
+ update_option( 'woocommerce_feature_rest_api_caching_enabled', 'yes' );
delete_option( 'woocommerce_rest_api_enable_backend_caching' );
$invalidator = new ProductVersionStringInvalidator();