From bc8abf3f2ac9d6428cd2aad67d26dfa263b5f515 Mon Sep 17 00:00:00 2001 From: Kiran Potphode Date: Wed, 19 Jun 2024 14:46:31 +0530 Subject: [PATCH 1/5] feat: add list of files to report of wp_cache_flush function usage --- inc/checks/class-cache-flush.php | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/inc/checks/class-cache-flush.php b/inc/checks/class-cache-flush.php index da2769b..415917f 100644 --- a/inc/checks/class-cache-flush.php +++ b/inc/checks/class-cache-flush.php @@ -23,10 +23,6 @@ public function run() { foreach ( $iterator as $file ) { $this->check_file( $file ); - if ( ! empty( $this->_matches ) ) { - // we are currently interested whether there's a use of wp_cache_flush() or not. - break; - } } if ( empty( $this->_matches ) ) { @@ -36,6 +32,6 @@ public function run() { } $this->set_status( 'warning' ); - $this->set_message( 'Use of wp_cache_flush() detected.' ); + $this->set_message( 'Use of wp_cache_flush() detected in ' . implode( ', ', $this->_matches ) ); } } From 23c5f69b73337ff06dfa22eddc4bb05828c1be4e Mon Sep 17 00:00:00 2001 From: Kiran Potphode Date: Wed, 19 Jun 2024 15:27:42 +0530 Subject: [PATCH 2/5] fix: phpcs issues --- inc/checks/class-cache-flush.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/inc/checks/class-cache-flush.php b/inc/checks/class-cache-flush.php index 415917f..7ed9be7 100644 --- a/inc/checks/class-cache-flush.php +++ b/inc/checks/class-cache-flush.php @@ -32,6 +32,6 @@ public function run() { } $this->set_status( 'warning' ); - $this->set_message( 'Use of wp_cache_flush() detected in ' . implode( ', ', $this->_matches ) ); + $this->set_message( 'Use of wp_cache_flush() detected in ' . implode( ', ', $this->_matches ) ); } } From 3136eed1fa8c0176416d6791ebba33e83014513a Mon Sep 17 00:00:00 2001 From: Kiran Potphode Date: Fri, 12 Jul 2024 19:50:03 +0530 Subject: [PATCH 3/5] chore: show relative paths in output --- inc/checks/class-cache-flush.php | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/inc/checks/class-cache-flush.php b/inc/checks/class-cache-flush.php index 7ed9be7..fba0ab7 100644 --- a/inc/checks/class-cache-flush.php +++ b/inc/checks/class-cache-flush.php @@ -31,7 +31,15 @@ public function run() { return; } + // Show relative paths in output. + $relative_paths = array_map( + function ( $file ) use ( $wp_content_dir ) { + return str_replace( $wp_content_dir . '/', '', $file ); + }, + $this->_matches + ); + $this->set_status( 'warning' ); - $this->set_message( 'Use of wp_cache_flush() detected in ' . implode( ', ', $this->_matches ) ); + $this->set_message( 'Use of wp_cache_flush() detected in ' . implode( ', ', $relative_paths ) ); } } From a3c9382755adc98e08d6611810643f413d74a2b9 Mon Sep 17 00:00:00 2001 From: Kiran Potphode Date: Mon, 15 Jul 2024 14:43:50 +0530 Subject: [PATCH 4/5] fix: updated behat tests --- features/check-cache-flush.feature | 2 +- inc/checks/class-cache-flush.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/features/check-cache-flush.feature b/features/check-cache-flush.feature index dde9586..2f4eb00 100644 --- a/features/check-cache-flush.feature +++ b/features/check-cache-flush.feature @@ -11,4 +11,4 @@ Feature: Check if wp_cache_flush() function is used inside wp-content directory When I run `wp doctor check cache-flush` Then STDOUT should be a table containing rows: | name | status | message | - | cache-flush | warning | Use of wp_cache_flush() detected. | + | cache-flush | warning | Use of wp_cache_flush() detected in mu-plugins/plugin.php | diff --git a/inc/checks/class-cache-flush.php b/inc/checks/class-cache-flush.php index fba0ab7..396609c 100644 --- a/inc/checks/class-cache-flush.php +++ b/inc/checks/class-cache-flush.php @@ -7,7 +7,7 @@ use RecursiveIteratorIterator; /** - * Detects any use of the `wp_cache_flush()` function. + * Detects and reports the path of files for occurrences of the `wp_cache_flush()` function. */ class Cache_Flush extends File_Contents { From aeee5eaed1649931cd9c7beba8d12091ac9a7e79 Mon Sep 17 00:00:00 2001 From: Kiran Potphode Date: Wed, 17 Jul 2024 16:42:16 +0530 Subject: [PATCH 5/5] fix: update behat test --- features/check-cache-flush.feature | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/features/check-cache-flush.feature b/features/check-cache-flush.feature index 2f4eb00..a8652ab 100644 --- a/features/check-cache-flush.feature +++ b/features/check-cache-flush.feature @@ -9,6 +9,19 @@ Feature: Check if wp_cache_flush() function is used inside wp-content directory """ When I run `wp doctor check cache-flush` - Then STDOUT should be a table containing rows: - | name | status | message | - | cache-flush | warning | Use of wp_cache_flush() detected in mu-plugins/plugin.php | + Then STDOUT should contain: + """ + cache-flush + """ + And STDOUT should contain: + """ + warning + """ + And STDOUT should contain: + """ + Use of wp_cache_flush() detected + """ + And STDOUT should contain: + """ + mu-plugins/plugin.php + """