33/**
44 * Manages the WP Super Cache plugin
55 */
6- class WPSuperCache_Command extends WP_CLI_Command {
6+ class WP_Super_Cache_Command extends WP_CLI_Command {
77
88 /**
99 * Clear something from the cache.
@@ -13,25 +13,24 @@ class WPSuperCache_Command extends WP_CLI_Command {
1313 function flush ( $ args = array (), $ assoc_args = array () ) {
1414 require_once ( WPCACHEHOME . '/wp-cache-phase1.php ' );
1515 global $ WPSC_HTTP_HOST ;
16- $ home_url = parse_url ( home_url () );
16+ $ home_url = parse_url ( home_url () );
1717 $ WPSC_HTTP_HOST = $ home_url ['host ' ];
1818
19- if ( isset ($ assoc_args ['post_id ' ]) ) {
19+ if ( isset ( $ assoc_args ['post_id ' ] ) ) {
2020 if ( is_numeric ( $ assoc_args ['post_id ' ] ) ) {
2121 wp_cache_post_change ( $ assoc_args ['post_id ' ] );
2222 } else {
23- WP_CLI ::error ('This is not a valid post id. ' );
23+ WP_CLI ::error ( 'This is not a valid post id. ' );
2424 }
2525
2626 wp_cache_post_change ( $ assoc_args ['post_id ' ] );
27- }
28- elseif ( isset ( $ assoc_args ['permalink ' ] ) ) {
27+ } elseif ( isset ( $ assoc_args ['permalink ' ] ) ) {
2928 $ id = url_to_postid ( $ assoc_args ['permalink ' ] );
3029
3130 if ( is_numeric ( $ id ) ) {
3231 wp_cache_post_change ( $ id );
3332 } else {
34- WP_CLI ::error ('There is no post with this permalink. ' );
33+ WP_CLI ::error ( 'There is no post with this permalink. ' );
3534 }
3635 } else {
3736 wp_cache_clean_cache ( $ file_prefix , true );
@@ -47,23 +46,23 @@ function status( $args = array(), $assoc_args = array() ) {
4746
4847 $ cache_stats = get_option ( 'supercache_stats ' );
4948
50- if ( !empty ( $ cache_stats ) ) {
49+ if ( ! empty ( $ cache_stats ) ) {
5150 if ( $ cache_stats ['generated ' ] > time () - 3600 * 24 ) {
52- WP_CLI ::line ( 'Cache status: ' . ($ super_cache_enabled ? '%gOn%n ' : '%rOff%n ' ) );
53- WP_CLI ::line ( 'Cache content on ' . date ('r ' , $ cache_stats ['generated ' ] ) . ': ' );
51+ WP_CLI ::line ( 'Cache status: ' . ( $ super_cache_enabled ? '%gOn%n ' : '%rOff%n ' ) );
52+ WP_CLI ::line ( 'Cache content on ' . date ( 'r ' , $ cache_stats ['generated ' ] ) . ': ' );
5453 WP_CLI ::line ();
5554 WP_CLI ::line ( ' WordPress cache: ' );
56- WP_CLI ::line ( ' Cached: ' . $ cache_stats [ 'wpcache ' ][ 'cached ' ] );
57- WP_CLI ::line ( ' Expired: ' . $ cache_stats [ 'wpcache ' ][ 'expired ' ] );
55+ WP_CLI ::line ( ' Cached: ' . $ cache_stats ['wpcache ' ][ 'cached ' ] );
56+ WP_CLI ::line ( ' Expired: ' . $ cache_stats ['wpcache ' ][ 'expired ' ] );
5857 WP_CLI ::line ();
5958 WP_CLI ::line ( ' WP Super Cache: ' );
60- WP_CLI ::line ( ' Cached: ' . $ cache_stats [ 'supercache ' ][ 'cached ' ] );
61- WP_CLI ::line ( ' Expired: ' . $ cache_stats [ 'supercache ' ][ 'expired ' ] );
59+ WP_CLI ::line ( ' Cached: ' . $ cache_stats ['supercache ' ][ 'cached ' ] );
60+ WP_CLI ::line ( ' Expired: ' . $ cache_stats ['supercache ' ][ 'expired ' ] );
6261 } else {
63- WP_CLI ::error ('The WP Super Cache stats are too old to work with (older than 24 hours). ' );
62+ WP_CLI ::error ( 'The WP Super Cache stats are too old to work with (older than 24 hours). ' );
6463 }
6564 } else {
66- WP_CLI ::error ('No WP Super Cache stats found. ' );
65+ WP_CLI ::error ( 'No WP Super Cache stats found. ' );
6766 }
6867 }
6968
@@ -75,10 +74,10 @@ function enable( $args = array(), $assoc_args = array() ) {
7574
7675 wp_super_cache_enable ();
7776
78- if ( $ super_cache_enabled ) {
77+ if ( $ super_cache_enabled ) {
7978 WP_CLI ::success ( 'The WP Super Cache is enabled. ' );
8079 } else {
81- WP_CLI ::error ('The WP Super Cache is not enabled, check its settings page for more info. ' );
80+ WP_CLI ::error ( 'The WP Super Cache is not enabled, check its settings page for more info. ' );
8281 }
8382 }
8483
@@ -90,10 +89,10 @@ function disable( $args = array(), $assoc_args = array() ) {
9089
9190 wp_super_cache_disable ();
9291
93- if (! $ super_cache_enabled ) {
92+ if ( ! $ super_cache_enabled ) {
9493 WP_CLI ::success ( 'The WP Super Cache is disabled. ' );
9594 } else {
96- WP_CLI ::error ('The WP Super Cache is still enabled, check its settings page for more info. ' );
95+ WP_CLI ::error ( 'The WP Super Cache is still enabled, check its settings page for more info. ' );
9796 }
9897 }
9998
@@ -110,7 +109,7 @@ function preload( $args = array(), $assoc_args = array() ) {
110109 $ pending_cancel = get_option ( 'preload_cache_stop ' );
111110
112111 // Bail early if caching or preloading is disabled
113- if ( ! $ super_cache_enabled ) {
112+ if ( ! $ super_cache_enabled ) {
114113 WP_CLI ::error ( 'The WP Super Cache is not enabled. ' );
115114 }
116115
@@ -158,7 +157,7 @@ function preload( $args = array(), $assoc_args = array() ) {
158157 */
159158 protected function preload_status ( $ preload_counter , $ pending_cancel ) {
160159 if ( is_array ( $ preload_counter ) && $ preload_counter ['c ' ] > 0 ) {
161- WP_CLI ::line ( sprintf ( 'Currently caching from post %d to %d. ' , $ preload_counter [ 'c ' ] - 100 , $ preload_counter [ 'c ' ] ) );
160+ WP_CLI ::line ( sprintf ( 'Currently caching from post %d to %d. ' , $ preload_counter ['c ' ] - 100 , $ preload_counter ['c ' ] ) );
162161
163162 if ( $ pending_cancel ) {
164163 WP_CLI ::warning ( 'Pending preload cancel. It may take up to a minute for it to cancel completely. ' );
@@ -168,11 +167,3 @@ protected function preload_status( $preload_counter, $pending_cancel ) {
168167 }
169168 }
170169}
171-
172- WP_CLI ::add_command ( 'super-cache ' , 'WPSuperCache_Command ' , array (
173- 'before_invoke ' => function (){
174- if ( ! function_exists ( 'wp_super_cache_enable ' ) ) {
175- WP_CLI ::error ( 'WP Super Cache needs to be enabled to use its WP-CLI commands. ' );
176- }
177- }
178- ) );
0 commit comments