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-page.php

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

83 lines 2.4 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 page.
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\Options_Storage_Service;
13 use JordanLeven\Plugins\ForceRefresh\Services\Versions_Storage_Service;
14
15 /**
16 * Main class controller.
17 */
18 class Api_Handler_Admin_Refresh_Page extends Api_Handler_Admin implements Api_Handler_Admin_Interface {
19
20 /**
21 * The path for this endpoint.
22 *
23 * @var string
24 */
25 const ENDPOINT_PATH = '/page-version';
26
27 /**
28 * The version for this endpoint.
29 *
30 * @var int
31 */
32 const ENDPOINT_VERSION = 1;
33
34 /**
35 * Method for registering the endpoints for this class.
36 *
37 * @return void
38 */
39 public function register_routes(): void {
40 self::register_rest_endpoint(
41 self::ENDPOINT_PATH,
42 self::ENDPOINT_VERSION,
43 array(
44 'methods' => \WP_REST_Server::EDITABLE,
45 'callback' => array( $this, 'refresh_page' ),
46 'permission_callback' => array( $this, 'user_is_able_to_admin_force_refresh' ),
47 ),
48 );
49 }
50
51 /**
52 * Method for refreshing the page version.
53 *
54 * @param \WP_REST_Request $request The request object.
55 *
56 * @return void
57 */
58 public function refresh_page( \WP_REST_Request $request ): void {
59 $page_id = $request->get_param( 'postId' ) ?? null;
60 $page_version = Versions_Storage_Service::get_new_version();
61
62 Versions_Storage_Service::set_page_version( $page_id, $site_version );
63
64 $this->return_api_response(
65 201,
66 'You\'ve successfully requested all browsers to refresh this page.',
67 array(
68 'new_page_version' => $page_version,
69 'refresh_interval' => Options_Storage_Service::get_refresh_interval(),
70 )
71 );
72 }
73
74 /**
75 * Method for getting the endpoint for this service.
76 *
77 * @return string The service endpoint.
78 */
79 public static function get_rest_endpoint(): string {
80 return self::get_formatted_rest_endpoint( self::ENDPOINT_PATH, self::ENDPOINT_VERSION );
81 }
82 }
83