| @@ -18,8 +18,9 @@ | ||
| 18 | 18 | namespace XSpeed\Modules\Minify; |
| 19 | 19 | |
| 20 | 20 | defined( 'ABSPATH' ) || exit; |
| 21 | 21 | |
| 22 | +use XSpeed\Cache; | |
| 22 | 23 | use XSpeed\Minifier as LegacyMinifier; |
| 23 | 24 | use XSpeed\Minify_Filters; |
| 24 | 25 | use XSpeed\Module; |
| 25 | 26 | use XSpeed\Settings_Manager; |
| @@ -348,14 +349,42 @@ | ||
| 348 | 349 | return; |
| 349 | 350 | } |
| 350 | 351 | |
| 351 | 352 | if ( 'purge' === $action ) { |
| 352 | - LegacyMinifier::purge_minified(); | |
| 353 | - \WP_CLI::success( 'Minify cache purged.' ); | |
| 353 | + // Deleting the files alone left every cached page linking names | |
| 354 | + // that were gone. The assets purge takes the pages with it and | |
| 355 | + // tells the edge. On a network, a bare `wp xspeed minify purge` | |
| 356 | + // is a network purge (min/ is shared by every blog); with --url | |
| 357 | + // it is that site's assets purge. | |
| 358 | + $network = is_multisite() && ! self::cli_url_given(); | |
| 359 | + $count = $network | |
| 360 | + ? Cache::purge_assets( 'cli', true ) | |
| 361 | + : Cache::purge_type( 'assets', 'cli' ); | |
| 362 | + \WP_CLI::success( | |
| 363 | + sprintf( | |
| 364 | + 'Minify cache purged; %d cached page(s) removed%s.', | |
| 365 | + $count, | |
| 366 | + $network ? ' across the network' : '' | |
| 367 | + ) | |
| 368 | + ); | |
| 354 | 369 | return; |
| 355 | 370 | } |
| 356 | 371 | |
| 357 | 372 | \WP_CLI::error( "Unknown action: $action" ); |
| 373 | + } | |
| 374 | + | |
| 375 | + /** | |
| 376 | + * Whether this command was pointed at one site with --url. | |
| 377 | + * | |
| 378 | + * Only a real WP-CLI run has global config to read. The MCP bridge runs | |
| 379 | + * the command inside a request for one site, which is the same thing as | |
| 380 | + * --url, so anything without WP-CLI's config reads as site-scoped. | |
| 381 | + */ | |
| 382 | + private static function cli_url_given(): bool { | |
| 383 | + if ( ! class_exists( '\\WP_CLI' ) || ! method_exists( '\\WP_CLI', 'get_config' ) ) { | |
| 384 | + return true; | |
| 385 | + } | |
| 386 | + return '' !== (string) \WP_CLI::get_config( 'url' ); | |
| 358 | 387 | } |
| 359 | 388 | |
| 360 | 389 | /** |
| 361 | 390 | * Minify has no master switch -- it is on when any of minify_html / |