PluginProbe
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution / 2.0.0
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution v2.0.0
2.0.1 trunk 1.0.0 1.1.0 1.2.0 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.5.0 1.6.0 1.6.1 1.7.0 1.7.1 1.8.0 1.9.0 2.0.0
solid-performance / src / Performance / API / Routes / Page_Cache / Clear.php

Clear.php in Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution 2.0.0, at src/Performance/API/Routes/Page_Cache/Clear.php

121 lines 2.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * The route for clearing the page cache.
4 *
5 * @since 0.1.0
6 *
7 * @package SolidWP\Performance
8 */
9
10 namespace SolidWP\Performance\API\Routes\Page_Cache;
11
12 use SolidWP\Performance\API\Base_Route;
13 use SolidWP\Performance\Page_Cache;
14 use SolidWP\Performance\Preload\Preload_Scheduler;
15 use WP_Error;
16 use WP_REST_Request;
17 use WP_REST_Response;
18 use WP_REST_Server;
19
20 if ( ! defined( 'ABSPATH' ) ) {
21 exit;
22 }
23
24 /**
25 * The class that handles the clear cache route.
26 *
27 * @since 0.1.0
28 *
29 * @package SolidWP|Performance
30 */
31 class Clear extends Base_Route {
32
33 /**
34 * @var Page_Cache
35 */
36 private Page_Cache $page_cache;
37
38 /**
39 * @var Preload_Scheduler
40 */
41 private Preload_Scheduler $preloader;
42
43 /**
44 * @param Page_Cache $page_cache The page cache object.
45 * @param Preload_Scheduler $preloader The preloader.
46 */
47 public function __construct( Page_Cache $page_cache, Preload_Scheduler $preloader ) {
48 $this->page_cache = $page_cache;
49 $this->preloader = $preloader;
50 }
51
52 /**
53 * {@inheritdoc}
54 */
55 public function get_path(): string {
56 return '/page/clear';
57 }
58
59 /**
60 * {@inheritdoc}
61 */
62 public function get_methods() {
63 return WP_REST_Server::CREATABLE;
64 }
65
66 /**
67 * {@inheritdoc}
68 */
69 public function callback( WP_REST_Request $request ) {
70 if ( $this->preloader->is_running() ) {
71 return new WP_Error(
72 'solid_performance_page_cache_clear_error',
73 __( 'The site is currently preloading. Cancel preloading or try again later.', 'solid-performance' ),
74 );
75 }
76
77 $result = $this->page_cache->clear();
78
79 if ( ! $result ) {
80 return new WP_Error(
81 'solid_performance_page_cache_clear_error',
82 __( 'Page cache could not be cleared', 'solid-performance' ),
83 );
84 }
85
86 return new WP_REST_Response(
87 [
88 'code' => 'solid_performance_page_cache_cleared',
89 'message' => __( 'Page cache cleared successfully', 'solid-performance' ),
90 ]
91 );
92 }
93
94 /**
95 * {@inheritdoc}
96 */
97 public function schema_callback(): array {
98 return [
99 '$schema' => 'http://json-schema.org/draft-04/schema#',
100 'title' => 'setting',
101 'type' => 'object',
102 'properties' => [
103 'code' => [
104 'description' => esc_html__( 'The identification code of the action.', 'solid-performance' ),
105 'type' => 'string',
106 'enum' => [
107 'solid_performance_page_cache_cleared',
108 'solid_performance_page_cache_clear_error',
109 ],
110 'readonly' => true,
111 ],
112 'message' => [
113 'description' => esc_html__( 'The formatted message of the action change.', 'solid-performance' ),
114 'type' => 'string',
115 'readonly' => true,
116 ],
117 ],
118 ];
119 }
120 }
121