\WP_REST_Server::READABLE, 'callback' => array( $this, 'get_version' ), 'permission_callback' => '__return_true', ), ); } /** * Method used by ajax requests to get the current site version. * * @param \WP_REST_Request $request The ReST Request object. * * @return \WP_REST_Response */ public function get_version( \WP_REST_Request $request ): \WP_REST_Response { $post_id = $request->get_param( 'postId' ) ?? null; $response = array( 'currentVersionSite' => $this->get_current_version_site(), ); if ( $post_id ) { $response['currentVersionPage'] = $this->get_current_version_post( $post_id ); } return $this->return_api_response( \WP_Http::OK, 'The current site version has been successfully retrieved.', $response, ); } /** * Method to get the current version of the site. * * @return string The version of the site */ private function get_current_version_site(): string { $current_site_version = get_option( 'force_refresh_current_site_version' ); return (bool) $current_site_version ? $current_site_version : '0'; } /** * Method to get the current version for a specific post. * * @param int $post_id The post ID to check. * * @return string The version of the provided post */ private static function get_current_version_post( int $post_id ): string { return Versions_Storage_Service::get_page_version( $post_id ); } /** * 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 ); } }