From a2757db52c185f8dc7a4f661ed3ceaec792e4eed Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Mar 2026 08:55:19 +0000 Subject: [PATCH 1/5] Initial plan From 2f098146367947e634583a606772cdaea74c695e Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Mar 2026 09:00:58 +0000 Subject: [PATCH 2/5] feat: improve flush command with clear all docs, fix double-call bug, add success messages Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/manage-cache.feature | 21 ++++++++++++++++++++ src/WP_Super_Cache_Command.php | 36 ++++++++++++++++++++++++++-------- 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/features/manage-cache.feature b/features/manage-cache.feature index 2c39462..91a168e 100644 --- a/features/manage-cache.feature +++ b/features/manage-cache.feature @@ -28,3 +28,24 @@ Feature: Generate cache """ Success: The WP Super Cache is enabled. """ + + When I run `wp super-cache flush` + Then STDOUT should contain: + """ + Success: Cache cleared. + """ + + When I run `wp post create --post_title='Test post' --post_status=publish --porcelain` + Then save STDOUT as {POST_ID} + + When I run `wp super-cache flush --post_id={POST_ID}` + Then STDOUT should contain: + """ + Success: Post cache cleared. + """ + + When I try `wp super-cache flush --post_id=invalid` + Then STDERR should contain: + """ + Error: This is not a valid post id. + """ diff --git a/src/WP_Super_Cache_Command.php b/src/WP_Super_Cache_Command.php index 15390f1..7146076 100644 --- a/src/WP_Super_Cache_Command.php +++ b/src/WP_Super_Cache_Command.php @@ -32,9 +32,29 @@ private function load() { } /** - * Clear something from the cache. + * Clears the cache, or a specific post's cache. * - * @synopsis [--post_id=] [--permalink=] + * ## OPTIONS + * + * [--post_id=] + * : Clear the cache for the post with this ID. + * + * [--permalink=] + * : Clear the cache for the post with this permalink. + * + * ## EXAMPLES + * + * # Clear all cached pages. + * $ wp super-cache flush + * Success: Cache cleared. + * + * # Clear the cache for a specific post by ID. + * $ wp super-cache flush --post_id=42 + * Success: Post cache cleared. + * + * # Clear the cache for a specific post by permalink. + * $ wp super-cache flush --permalink=https://example.com/my-post/ + * Success: Post cache cleared. * * @when after_wp_load */ @@ -44,21 +64,21 @@ public function flush( $args = array(), $assoc_args = array() ) { $this->load(); if ( isset( $assoc_args['post_id'] ) ) { - if ( is_numeric( $assoc_args['post_id'] ) ) { - wp_cache_post_change( $assoc_args['post_id'] ); - } else { + if ( ! is_numeric( $assoc_args['post_id'] ) ) { WP_CLI::error( 'This is not a valid post id.' ); } wp_cache_post_change( $assoc_args['post_id'] ); + WP_CLI::success( 'Post cache cleared.' ); } elseif ( isset( $assoc_args['permalink'] ) ) { $id = url_to_postid( $assoc_args['permalink'] ); - if ( is_numeric( $id ) ) { - wp_cache_post_change( $id ); - } else { + if ( ! is_numeric( $id ) ) { WP_CLI::error( 'There is no post with this permalink.' ); } + + wp_cache_post_change( $id ); + WP_CLI::success( 'Post cache cleared.' ); } else { wp_cache_clean_cache( $file_prefix, true ); WP_CLI::success( 'Cache cleared.' ); From 00e64cda2e9054c30ada0e7fc7b2f1d596dbf244 Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 11 Mar 2026 10:26:51 +0100 Subject: [PATCH 3/5] Add entity command for testing --- composer.json | 1 + 1 file changed, 1 insertion(+) diff --git a/composer.json b/composer.json index af60977..ea21213 100644 --- a/composer.json +++ b/composer.json @@ -21,6 +21,7 @@ "wp-cli/wp-cli": "^2" }, "require-dev": { + "wp-cli/entity-command": "^2.8", "wp-cli/extension-command": "^2", "wp-cli/wp-cli-tests": "^5" }, From f5373451bcd42d12f32c4d02cec89b69e3895460 Mon Sep 17 00:00:00 2001 From: "copilot-swe-agent[bot]" <198982749+Copilot@users.noreply.github.com> Date: Wed, 11 Mar 2026 09:37:00 +0000 Subject: [PATCH 4/5] fix: use absint() for post_id/permalink validation and add permalink Behat tests Co-authored-by: swissspidy <841956+swissspidy@users.noreply.github.com> --- features/manage-cache.feature | 15 +++++++++++++++ src/WP_Super_Cache_Command.php | 9 +++++---- 2 files changed, 20 insertions(+), 4 deletions(-) diff --git a/features/manage-cache.feature b/features/manage-cache.feature index 91a168e..ad3e49b 100644 --- a/features/manage-cache.feature +++ b/features/manage-cache.feature @@ -49,3 +49,18 @@ Feature: Generate cache """ Error: This is not a valid post id. """ + + When I run `wp post get {POST_ID} --field=link` + Then save STDOUT as {POST_PERMALINK} + + When I run `wp super-cache flush --permalink={POST_PERMALINK}` + Then STDOUT should contain: + """ + Success: Post cache cleared. + """ + + When I try `wp super-cache flush --permalink=https://example.com/no-such-post/` + Then STDERR should contain: + """ + Error: There is no post with this permalink. + """ diff --git a/src/WP_Super_Cache_Command.php b/src/WP_Super_Cache_Command.php index 7146076..0a3d98f 100644 --- a/src/WP_Super_Cache_Command.php +++ b/src/WP_Super_Cache_Command.php @@ -64,16 +64,17 @@ public function flush( $args = array(), $assoc_args = array() ) { $this->load(); if ( isset( $assoc_args['post_id'] ) ) { - if ( ! is_numeric( $assoc_args['post_id'] ) ) { + $post_id = absint( $assoc_args['post_id'] ); + if ( $post_id <= 0 ) { WP_CLI::error( 'This is not a valid post id.' ); } - wp_cache_post_change( $assoc_args['post_id'] ); + wp_cache_post_change( $post_id ); WP_CLI::success( 'Post cache cleared.' ); } elseif ( isset( $assoc_args['permalink'] ) ) { - $id = url_to_postid( $assoc_args['permalink'] ); + $id = absint( url_to_postid( $assoc_args['permalink'] ) ); - if ( ! is_numeric( $id ) ) { + if ( $id <= 0 ) { WP_CLI::error( 'There is no post with this permalink.' ); } From 48653d1382c41ded18ec71974392e47f80f5ba9e Mon Sep 17 00:00:00 2001 From: Pascal Birchler Date: Wed, 11 Mar 2026 10:44:02 +0100 Subject: [PATCH 5/5] Apply suggestion from @swissspidy --- features/manage-cache.feature | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/features/manage-cache.feature b/features/manage-cache.feature index ad3e49b..4c83627 100644 --- a/features/manage-cache.feature +++ b/features/manage-cache.feature @@ -50,7 +50,7 @@ Feature: Generate cache Error: This is not a valid post id. """ - When I run `wp post get {POST_ID} --field=link` + When I run `wp post get {POST_ID} --field=url` Then save STDOUT as {POST_PERMALINK} When I run `wp super-cache flush --permalink={POST_PERMALINK}`