PluginProbe
Force Refresh / 2.9.1
Force Refresh v2.9.1
3.2.1 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 All 54 releases
force-refresh / includes / api / classes / class-api-handler-admin-refresh-site.php

class-api-handler-admin-refresh-site.php in Force Refresh 2.9.1, at includes/api/classes/class-api-handler-admin-refresh-site.php

78 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\Versions_Storage_Service;
13
14 /**
15 * Main class controller.
16 */
17 class Api_Handler_Admin_Refresh_Site 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 = '/site-version';
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, 'refresh_site' ),
45 'permission_callback' => array( $this, 'user_is_able_to_admin_force_refresh' ),
46 ),
47 );
48 }
49
50 /**
51 * Method for refreshing the site version.
52 *
53 * @return void
54 */
55 public function refresh_site(): void {
56 $site_version = Versions_Storage_Service::get_new_version();
57
58 Versions_Storage_Service::set_site_version( $site_version );
59
60 $this->return_api_response(
61 201,
62 'You\'ve successfully requested all browsers to refresh',
63 array(
64 'new_site_version' => $site_version,
65 )
66 );
67 }
68
69 /**
70 * Method for getting the endpoint for this service.
71 *
72 * @return string The service endpoint.
73 */
74 public static function get_rest_endpoint(): string {
75 return self::get_formatted_rest_endpoint( self::ENDPOINT_PATH, self::ENDPOINT_VERSION );
76 }
77 }
78