Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
CRAP | |
0.00% |
0 / 1 |
| Clear_Page_Cache | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
20 | |
0.00% |
0 / 1 |
| handle | |
0.00% |
0 / 11 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace Automattic\Jetpack_Boost\Modules\Optimizations\Page_Cache\Data_Sync_Actions; |
| 4 | |
| 5 | use Automattic\Jetpack\WP_JS_Data_Sync\Contracts\Data_Sync_Action; |
| 6 | use Automattic\Jetpack_Boost\Modules\Optimizations\Page_Cache\Pre_WordPress\Boost_Cache; |
| 7 | |
| 8 | /** |
| 9 | * Page Cache: Clear page cache |
| 10 | */ |
| 11 | class Clear_Page_Cache implements Data_Sync_Action { |
| 12 | |
| 13 | /** |
| 14 | * Handles the action logic. |
| 15 | * |
| 16 | * @param mixed $_data JSON Data passed to the action. |
| 17 | * @param \WP_REST_Request $_request The request object. |
| 18 | */ |
| 19 | public function handle( $_data, $_request ) { |
| 20 | $cache = new Boost_Cache(); |
| 21 | $delete = $cache->delete_recursive( home_url() ); |
| 22 | |
| 23 | if ( $delete === null || is_wp_error( $delete ) ) { |
| 24 | return array( |
| 25 | 'message' => __( 'Cache already cleared.', 'jetpack-boost' ), |
| 26 | ); |
| 27 | } |
| 28 | |
| 29 | if ( $delete ) { |
| 30 | return array( |
| 31 | 'message' => __( 'Cache cleared.', 'jetpack-boost' ), |
| 32 | ); |
| 33 | } |
| 34 | |
| 35 | return new \WP_Error( 'unable-to-clear-cache', __( 'Unable to clear cache.', 'jetpack-boost' ) ); |
| 36 | } |
| 37 | } |