-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwp-cli-flush-cache.php
More file actions
52 lines (43 loc) · 1.18 KB
/
wp-cli-flush-cache.php
File metadata and controls
52 lines (43 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
<?php
/**
* Plugin Name: WP CLI Flush Cache
* Plugin URI: https://github.com/ocean90/wp-cli-user-flush-cache
* Description: Using wp cli, flush the cache of a user or a site.
* Version: 1.0.0
* Author: Dominik Schilling
* Author URI: https://dominikschilling.de
* License: GPL v2.0+
*/
if ( ! class_exists( 'WP_CLI' ) ) {
return;
}
/**
* Clears the cache of a user.
*
* ## OPTIONS
*
* <user>
* : User ID, user email, or user login.
*/
function ds_wpcli_flush_cache_for_user( $args, $assoc_args ) {
$fetcher = new WP_CLI\Fetchers\User();
$user = $fetcher->get_check( $args[0] );
clean_user_cache( $user );
WP_CLI::success( "Cache flushed for user '$user->user_login'." );
}
WP_CLI::add_command( 'user flush-cache', 'ds_wpcli_flush_cache_for_user' );
/**
* Clears the cache of a site.
*
* ## OPTIONS
*
* <id>
* : ID of a site.
*/
function ds_wpcli_flush_cache_for_site( $args, $assoc_args ) {
$fetcher = new \WP_CLI\Fetchers\Site();
$site = $fetcher->get_check( $args[0] );
clean_blog_cache( $site );
WP_CLI::success( "Cache flushed for site '$site->domain$site->path'." );
}
WP_CLI::add_command( 'site flush-cache', 'ds_wpcli_flush_cache_for_site' );