| 1 |
<?php |
| 2 |
|
| 3 |
namespace DeliciousBrains\SpinupWp\Cli; |
| 4 |
|
| 5 |
use WP_CLI; |
| 6 |
|
| 7 |
/** |
| 8 |
* Perform SpinupWP cache operations. |
| 9 |
* |
| 10 |
* ## EXAMPLES |
| 11 |
* |
| 12 |
* # Purge the entire SpinupWP page cache |
| 13 |
* $ wp spinupwp purge-site |
| 14 |
*/ |
| 15 |
class CacheCommands { |
| 16 |
|
| 17 |
/** |
| 18 |
* Purge the entire SpinupWP page cache. |
| 19 |
* |
| 20 |
* ## EXAMPLES |
| 21 |
* |
| 22 |
* wp spinupwp purge-site |
| 23 |
* |
| 24 |
* @subcommand purge-site |
| 25 |
*/ |
| 26 |
public function purge_site() { |
| 27 |
if ( spinupwp()->cache->purge_page_cache() ) { |
| 28 |
WP_CLI::success( __( 'The page cache was purged.', 'spinupwp' ) ); |
| 29 |
} else { |
| 30 |
WP_CLI::error( __( 'The page cache could not be purged.', 'spinupwp' ) ); |
| 31 |
} |
| 32 |
} |
| 33 |
|
| 34 |
/** |
| 35 |
* Purge a single post from the SpinupWP page cache. |
| 36 |
* |
| 37 |
* ## OPTIONS |
| 38 |
* |
| 39 |
* <post_id> |
| 40 |
* : The ID of the post to purge. |
| 41 |
* |
| 42 |
* ## EXAMPLES |
| 43 |
* |
| 44 |
* wp spinupwp purge-post 123 |
| 45 |
* |
| 46 |
* @subcommand purge-post |
| 47 |
*/ |
| 48 |
public function purge_post( $args ) { |
| 49 |
$post = get_post( $args[0] ); |
| 50 |
|
| 51 |
if ( ! $post ) { |
| 52 |
WP_CLI::error( __( 'Post not found.', 'spinupwp' ) ); |
| 53 |
|
| 54 |
return; |
| 55 |
} |
| 56 |
|
| 57 |
if ( spinupwp()->cache->purge_post( $post ) ) { |
| 58 |
WP_CLI::success( __( 'Post purged from the page cache.', 'spinupwp' ) ); |
| 59 |
} else { |
| 60 |
WP_CLI::error( __( 'Post could not be purged from the page cache.', 'spinupwp' ) ); |
| 61 |
} |
| 62 |
} |
| 63 |
|
| 64 |
/** |
| 65 |
* Purge a single URL from the SpinupWP page cache. |
| 66 |
* |
| 67 |
* ## OPTIONS |
| 68 |
* |
| 69 |
* <url> |
| 70 |
* : The URL to purge. |
| 71 |
* |
| 72 |
* ## EXAMPLES |
| 73 |
* |
| 74 |
* wp spinupwp purge-url https://example.com |
| 75 |
* |
| 76 |
* @subcommand purge-url |
| 77 |
*/ |
| 78 |
public function purge_url( $args ) { |
| 79 |
if ( spinupwp()->cache->purge_url( $args[0] ) ) { |
| 80 |
WP_CLI::success( __( 'URL purged from the page cache.', 'spinupwp' ) ); |
| 81 |
} else { |
| 82 |
WP_CLI::error( __( 'URL could not be purged from the page cache.', 'spinupwp' ) ); |
| 83 |
} |
| 84 |
} |
| 85 |
} |