PluginProbe
Force Refresh / trunk
Force Refresh vtrunk
3.2.0 3.1.2 3.1.1 3.1.0 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.2.0 2.0.0 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.10.0 2.10.1 2.10.2 2.11.0 2.11.1 2.12.0 2.12.1 All 53 releases
force-refresh / includes / api / classes / class-api-handler-admin-debugging.php

class-api-handler-admin-debugging.php in Force Refresh trunk, at includes/api/classes/class-api-handler-admin-debugging.php

77 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 * Our API calls responsible for handling requests from admins requesting a refresh for the site.
4 *
5 * @package ForceRefresh
6 */
7
8 namespace JordanLeven\Plugins\ForceRefresh\Api;
9
10 use JordanLeven\Plugins\ForceRefresh\Api\Api_Handler_Admin;
11 use JordanLeven\Plugins\ForceRefresh\Api\Interfaces\Api_Handler_Admin_Interface;
12 use JordanLeven\Plugins\ForceRefresh\Services\Debug_Storage_Service;
13
14 /**
15 * Main class controller.
16 */
17 class Api_Handler_Admin_Debugging extends Api_Handler_Admin implements Api_Handler_Admin_Interface {
18
19 /**
20 * The path for this endpoint.
21 *
22 * @var string
23 */
24 const ENDPOINT_PATH = '/debugging';
25
26 /**
27 * The version for this endpoint.
28 *
29 * @var int
30 */
31 const ENDPOINT_VERSION = 1;
32
33 /**
34 * Method for registering the endpoints for this class.
35 *
36 * @return void
37 */
38 public function register_routes(): void {
39 self::register_rest_endpoint(
40 self::ENDPOINT_PATH,
41 self::ENDPOINT_VERSION,
42 array(
43 'methods' => \WP_REST_Server::EDITABLE,
44 'callback' => array( $this, 'save_options' ),
45 'permission_callback' => $this->get_admin_permission_callback(),
46 ),
47 );
48 }
49
50 /**
51 * Method for saving options
52 *
53 * @param \WP_REST_Request $request The WP ReST request.
54 *
55 * @return \WP_REST_Response
56 */
57 public function save_options( \WP_REST_Request $request ): \WP_REST_Response {
58 $debug_mode = $request->get_param( 'debug' ) === true ?? null;
59
60 Debug_Storage_Service::set_debug_mode( $debug_mode );
61
62 return $this->return_api_response(
63 \WP_Http::CREATED,
64 'You\'ve successfully updated debug mode.'
65 );
66 }
67
68 /**
69 * Method for getting the endpoint for this service.
70 *
71 * @return string The service endpoint.
72 */
73 public static function get_rest_endpoint(): string {
74 return self::get_formatted_rest_endpoint( self::ENDPOINT_PATH, self::ENDPOINT_VERSION );
75 }
76 }
77