PluginProbe
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution / 1.1.0
Solid Performance – Your No-Code Caching, Performance, & Page Speed Solution v1.1.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 1.1.0, at src/Performance/API/Routes/Page_Cache/Clear.php

106 lines 2.1 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 WP_Error;
15 use WP_REST_Request;
16 use WP_REST_Response;
17 use WP_REST_Server;
18
19 if ( ! defined( 'ABSPATH' ) ) {
20 exit;
21 }
22
23 /**
24 * The class that handles the clear cache route.
25 *
26 * @since 0.1.0
27 *
28 * @package SolidWP|Performance
29 */
30 class Clear extends Base_Route {
31
32 /**
33 * @var Page_Cache
34 */
35 private Page_Cache $page_cache;
36
37 /**
38 * @param Page_Cache $page_cache The page cache object.
39 */
40 public function __construct( Page_Cache $page_cache ) {
41 $this->page_cache = $page_cache;
42 }
43
44 /**
45 * {@inheritdoc}
46 */
47 public function get_path(): string {
48 return '/page/clear';
49 }
50
51 /**
52 * {@inheritdoc}
53 */
54 public function get_methods() {
55 return WP_REST_Server::CREATABLE;
56 }
57
58 /**
59 * {@inheritdoc}
60 */
61 public function callback( WP_REST_Request $request ) {
62 $result = $this->page_cache->clear();
63
64 if ( ! $result ) {
65 return new WP_Error(
66 'solid_performance_page_cache_clear_error',
67 'Page cache could not be cleared',
68 );
69 }
70
71 return new WP_REST_Response(
72 [
73 'code' => 'solid_performance_page_cache_cleared',
74 'message' => 'Page cache cleared successfully',
75 ]
76 );
77 }
78
79 /**
80 * {@inheritdoc}
81 */
82 public function schema_callback(): array {
83 return [
84 '$schema' => 'http://json-schema.org/draft-04/schema#',
85 'title' => 'setting',
86 'type' => 'object',
87 'properties' => [
88 'code' => [
89 'description' => esc_html__( 'The identification code of the action.', 'solid-performance' ),
90 'type' => 'string',
91 'enum' => [
92 'solid_performance_page_cache_cleared',
93 'solid_performance_page_cache_clear_error',
94 ],
95 'readonly' => true,
96 ],
97 'message' => [
98 'description' => esc_html__( 'The formatted message of the action change.', 'solid-performance' ),
99 'type' => 'string',
100 'readonly' => true,
101 ],
102 ],
103 ];
104 }
105 }
106