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

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

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