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 / On.php

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

112 lines 2.2 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 On 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/on';
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->on();
63
64 if ( ! $result ) {
65 return new WP_Error(
66 'solid_performance_page_cache_not_enabled',
67 'Page cache could not be enabled',
68 );
69 }
70
71 return new WP_REST_Response(
72 [
73 'enabled' => true,
74 'code' => 'solid_performance_page_cache_enabled',
75 'message' => 'Page cache enabled successfully',
76 ]
77 );
78 }
79
80 /**
81 * {@inheritdoc}
82 */
83 public function schema_callback(): array {
84 return [
85 '$schema' => 'http://json-schema.org/draft-04/schema#',
86 'title' => 'setting',
87 'type' => 'object',
88 'properties' => [
89 'enabled' => [
90 'description' => esc_html__( 'The current state of page caching.', 'solid-performance' ),
91 'type' => 'boolean',
92 'readonly' => true,
93 ],
94 'code' => [
95 'description' => esc_html__( 'The identification code of the setting.', 'solid-performance' ),
96 'type' => 'string',
97 'enum' => [
98 'solid_performance_page_cache_not_enabled',
99 'solid_performance_page_cache_enabled',
100 ],
101 'readonly' => true,
102 ],
103 'message' => [
104 'description' => esc_html__( 'The formatted message of the setting change.', 'solid-performance' ),
105 'type' => 'string',
106 'readonly' => true,
107 ],
108 ],
109 ];
110 }
111 }
112