# force-refresh/2.12.0/includes/api/classes/class-api-handler-admin-refresh-site.php

Force Refresh, version 2.12.0. 78 lines.

- Page: https://pluginprobe.com/plugins/force-refresh/2.12.0/code/includes/api/classes/class-api-handler-admin-refresh-site.php
- Raw: https://pluginprobe.com/plugins/force-refresh/2.12.0/raw/includes/api/classes/class-api-handler-admin-refresh-site.php
- Modified: 2023-11-10T16:53:14+00:00

Line numbers below start at 1. Link to a line or a range by appending a fragment to the
page URL, for example `https://pluginprobe.com/plugins/force-refresh/2.12.0/code/includes/api/classes/class-api-handler-admin-refresh-site.php#L10-L20`.

```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\Versions_Storage_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::EDITABLE,
                'callback'            => array( $this, 'refresh_site' ),
                'permission_callback' => array( $this, 'user_is_able_to_admin_force_refresh' ),
            ),
        );
    }

    /**
     * Method for refreshing the site version.
     *
     * @return void
     */
    public function refresh_site(): void {
        $site_version = Versions_Storage_Service::get_new_version();

        Versions_Storage_Service::set_site_version( $site_version );

        $this->return_api_response(
            201,
            '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 );
    }
}

```
