Skip to content

Commit d0af1ee

Browse files
Give a warning when flushing cache on multisite with --url=<url> (#86)
* When flushing cache on a multisite give a warning. Cache flushes on all sites, not just the current url. * Updated the --url warning. * Remove comma from the message --------- Co-authored-by: Daniel Bachhuber <[email protected]>
1 parent 80aa8e1 commit d0af1ee

File tree

2 files changed

+20
-1
lines changed

2 files changed

+20
-1
lines changed

features/cache.feature

+15
Original file line numberDiff line numberDiff line change
@@ -132,3 +132,18 @@ Feature: Managed the WordPress object cache
132132
"""
133133
Error: Could not replace object 'bar' in group 'foo'. Does it not exist?
134134
"""
135+
136+
Scenario: Flushing cache on a multisite installation
137+
Given a WP multisite installation
138+
139+
When I try `wp cache flush`
140+
Then STDERR should not contain:
141+
"""
142+
Warning: Ignoring the --url=<url> argument because flushing the cache affects all sites on a multisite installation.
143+
"""
144+
145+
When I try `wp cache flush --url=example.com`
146+
Then STDERR should contain:
147+
"""
148+
Warning: Ignoring the --url=<url> argument because flushing the cache affects all sites on a multisite installation.
149+
"""

src/Cache_Command.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,12 @@ public function delete( $args, $assoc_args ) {
155155
* Success: The cache was flushed.
156156
*/
157157
public function flush( $args, $assoc_args ) {
158-
$value = wp_cache_flush();
159158

159+
if ( WP_CLI::has_config( 'url' ) && ! empty( WP_CLI::get_config()['url'] ) && is_multisite() ) {
160+
WP_CLI::warning( 'Ignoring the --url=<url> argument because flushing the cache affects all sites on a multisite installation.' );
161+
}
162+
163+
$value = wp_cache_flush();
160164
if ( false === $value ) {
161165
WP_CLI::error( 'The object cache could not be flushed.' );
162166
}

0 commit comments

Comments
 (0)