76 lines
2.0 KiB
PHP
76 lines
2.0 KiB
PHP
<?php
|
|
/**
|
|
* Our API calls responsible for handling requests from admins requesting a refresh for the site.
|
|
*
|
|
* @package ForceRefresh
|
|
*/
|
|
|
|
namespace JordanLeven\Plugins\ForceRefresh\Api;
|
|
|
|
use JordanLeven\Plugins\ForceRefresh\Api\Api_Handler_Admin;
|
|
use JordanLeven\Plugins\ForceRefresh\Api\Interfaces\Api_Handler_Admin_Interface;
|
|
use JordanLeven\Plugins\ForceRefresh\Services\Refresh_Service;
|
|
|
|
/**
|
|
* Main class controller.
|
|
*/
|
|
class Api_Handler_Admin_Refresh_Site extends Api_Handler_Admin implements Api_Handler_Admin_Interface {
|
|
|
|
/**
|
|
* The path for this endpoint.
|
|
*
|
|
* @var string
|
|
*/
|
|
const ENDPOINT_PATH = '/site-version';
|
|
|
|
/**
|
|
* The version for this endpoint.
|
|
*
|
|
* @var int
|
|
*/
|
|
const ENDPOINT_VERSION = 1;
|
|
|
|
/**
|
|
* Method for registering the endpoints for this class.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function register_routes(): void {
|
|
self::register_rest_endpoint(
|
|
self::ENDPOINT_PATH,
|
|
self::ENDPOINT_VERSION,
|
|
array(
|
|
'methods' => \WP_REST_Server::CREATABLE,
|
|
'callback' => array( $this, 'refresh_site' ),
|
|
'permission_callback' => $this->get_admin_permission_callback(),
|
|
),
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Method for refreshing the site version.
|
|
*
|
|
* @return \WP_REST_Response
|
|
*/
|
|
public function refresh_site(): \WP_REST_Response {
|
|
$site_version = Refresh_Service::update_version_site();
|
|
|
|
return $this->return_api_response(
|
|
\WP_Http::CREATED,
|
|
'You\'ve successfully requested all browsers to refresh',
|
|
array(
|
|
'new_site_version' => $site_version,
|
|
)
|
|
);
|
|
}
|
|
|
|
/**
|
|
* Method for getting the endpoint for this service.
|
|
*
|
|
* @return string The service endpoint.
|
|
*/
|
|
public static function get_rest_endpoint(): string {
|
|
return self::get_formatted_rest_endpoint( self::ENDPOINT_PATH, self::ENDPOINT_VERSION );
|
|
}
|
|
}
|