@@ -32,9 +32,29 @@ private function load() {
3232 }
3333
3434 /**
35- * Clear something from the cache.
35+ * Clears the cache, or a specific post's cache.
3636 *
37- * @synopsis [--post_id=<post-id>] [--permalink=<permalink>]
37+ * ## OPTIONS
38+ *
39+ * [--post_id=<post-id>]
40+ * : Clear the cache for the post with this ID.
41+ *
42+ * [--permalink=<permalink>]
43+ * : Clear the cache for the post with this permalink.
44+ *
45+ * ## EXAMPLES
46+ *
47+ * # Clear all cached pages.
48+ * $ wp super-cache flush
49+ * Success: Cache cleared.
50+ *
51+ * # Clear the cache for a specific post by ID.
52+ * $ wp super-cache flush --post_id=42
53+ * Success: Post cache cleared.
54+ *
55+ * # Clear the cache for a specific post by permalink.
56+ * $ wp super-cache flush --permalink=https://example.com/my-post/
57+ * Success: Post cache cleared.
3858 *
3959 * @when after_wp_load
4060 */
@@ -44,21 +64,21 @@ public function flush( $args = array(), $assoc_args = array() ) {
4464 $ this ->load ();
4565
4666 if ( isset ( $ assoc_args ['post_id ' ] ) ) {
47- if ( is_numeric ( $ assoc_args ['post_id ' ] ) ) {
48- wp_cache_post_change ( $ assoc_args ['post_id ' ] );
49- } else {
67+ if ( ! is_numeric ( $ assoc_args ['post_id ' ] ) ) {
5068 WP_CLI ::error ( 'This is not a valid post id. ' );
5169 }
5270
5371 wp_cache_post_change ( $ assoc_args ['post_id ' ] );
72+ WP_CLI ::success ( 'Post cache cleared. ' );
5473 } elseif ( isset ( $ assoc_args ['permalink ' ] ) ) {
5574 $ id = url_to_postid ( $ assoc_args ['permalink ' ] );
5675
57- if ( is_numeric ( $ id ) ) {
58- wp_cache_post_change ( $ id );
59- } else {
76+ if ( ! is_numeric ( $ id ) ) {
6077 WP_CLI ::error ( 'There is no post with this permalink. ' );
6178 }
79+
80+ wp_cache_post_change ( $ id );
81+ WP_CLI ::success ( 'Post cache cleared. ' );
6282 } else {
6383 wp_cache_clean_cache ( $ file_prefix , true );
6484 WP_CLI ::success ( 'Cache cleared. ' );
0 commit comments