From c074c5580b8d5950601f4a0b9a1d35de16ff9a3a Mon Sep 17 00:00:00 2001 From: Tom Cafferkey Date: Wed, 4 Sep 2024 14:23:20 +0100 Subject: [PATCH] PTK: Check if theres a scheduled action before logging warning. (#51143) * Check if there is a scheduled action before logging warning --- .../changelog/fix-register-ptk-patterns-warning-log | 4 ++++ plugins/woocommerce/src/Blocks/BlockPatterns.php | 11 ++++++++--- 2 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 plugins/woocommerce/changelog/fix-register-ptk-patterns-warning-log diff --git a/plugins/woocommerce/changelog/fix-register-ptk-patterns-warning-log b/plugins/woocommerce/changelog/fix-register-ptk-patterns-warning-log new file mode 100644 index 00000000000..0f236c0c0fe --- /dev/null +++ b/plugins/woocommerce/changelog/fix-register-ptk-patterns-warning-log @@ -0,0 +1,4 @@ +Significance: patch +Type: fix + +Only log PTK error if no action has been scheduled diff --git a/plugins/woocommerce/src/Blocks/BlockPatterns.php b/plugins/woocommerce/src/Blocks/BlockPatterns.php index 362fdae0446..70b7f137db9 100644 --- a/plugins/woocommerce/src/Blocks/BlockPatterns.php +++ b/plugins/woocommerce/src/Blocks/BlockPatterns.php @@ -141,9 +141,14 @@ class BlockPatterns { $patterns = $this->ptk_patterns_store->get_patterns(); if ( empty( $patterns ) ) { - wc_get_logger()->warning( - __( 'Empty patterns received from the PTK Pattern Store', 'woocommerce' ), - ); + // By only logging when patterns are empty and no fetch is scheduled, + // we ensure that warnings are only generated in genuinely problematic situations, + // such as when the pattern fetching mechanism has failed entirely. + if ( ! as_has_scheduled_action( 'fetch_patterns' ) ) { + wc_get_logger()->warning( + __( 'Empty patterns received from the PTK Pattern Store', 'woocommerce' ), + ); + } return; }