Skip to content

Commit

Permalink
Merge pull request #191 from kiranpotphode/184-list-of-files
Browse files Browse the repository at this point in the history
Add list of files to report of 'wp doctor check cache-flush' command
  • Loading branch information
ernilambar authored Jul 18, 2024
2 parents 8382897 + aeee5ea commit 0a7eb00
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 9 deletions.
19 changes: 16 additions & 3 deletions features/check-cache-flush.feature
Original file line number Diff line number Diff line change
Expand Up @@ -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. |
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
"""
16 changes: 10 additions & 6 deletions inc/checks/class-cache-flush.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand All @@ -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 ) ) {
Expand All @@ -35,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.' );
$this->set_message( 'Use of wp_cache_flush() detected in ' . implode( ', ', $relative_paths ) );
}
}

0 comments on commit 0a7eb00

Please sign in to comment.