PluginProbe
Force Refresh / 2.8.0
Force Refresh v2.8.0
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 / client / client.php

client.php in Force Refresh 2.8.0, at includes/api/client/client.php

67 lines 1.9 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 website visitors.
4 *
5 * @package ForceRefresh
6 */
7
8 /**
9 * Function to get the current version of the site.
10 *
11 * @return string The version of the site
12 */
13 function get_current_version_site() {
14 $current_site_version = get_option( 'force_refresh_current_site_version' );
15 return ! ! $current_site_version ? $current_site_version : '0';
16 }
17
18 /**
19 * Function to get the current version for a specific post.
20 *
21 * @param int $post_id The post ID to check.
22 *
23 * @return string The version of the provided post
24 */
25 function get_current_version_post( int $post_id ) {
26 $current_page_version = get_post_meta( $post_id, 'force_refresh_current_page_version', true );
27 return ! ! $current_page_version ? $current_page_version : '0';
28 }
29
30 /**
31 * Function used by ajax requests to get the current site version.
32 *
33 * @return void
34 */
35 function get_version() {
36 // Since this is a client-side request, we don't need to validate the nonce
37 // since there is no concept of a user session for end-users.
38 // phpcs:disable WordPress.Security.NonceVerification
39
40 // Get the post ID.
41 $post_id = isset( $_REQUEST['postId'] )
42 ? sanitize_text_field( wp_unslash( $_REQUEST['postId'] ) )
43 : null;
44 return_api_response(
45 200,
46 'The current site version has been successfully retrieved.',
47 array(
48 'currentVersionSite' => get_current_version_site(),
49 'currentVersionPage' => get_current_version_post( $post_id ),
50 )
51 );
52
53 // phpcs:enable WordPress.Security.NonceVerification
54 }
55
56 // The call used for users requesting the current site version from non-admins.
57 add_action(
58 'wp_ajax_nopriv_force_refresh_get_version',
59 __NAMESPACE__ . '\\get_version'
60 );
61
62 // The call used for users requesting the current site version from admins.
63 add_action(
64 'wp_ajax_force_refresh_get_version',
65 __NAMESPACE__ . '\\get_version'
66 );
67