\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 void */ public function get_version( \WP_REST_Request $request ): void { $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 ); } $this->return_api_response( 200, '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 { $current_page_version = get_post_meta( $post_id, 'force_refresh_current_page_version', true ); return (bool) $current_page_version ? $current_page_version : '0'; } /** * 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 ); } }