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 / admin / inc.refresh-page.php

inc.refresh-page.php in Force Refresh 2.8.0, at includes/api/admin/inc.refresh-page.php

69 lines 2.0 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 admins requesting a refresh for the site.
4 *
5 * @package ForceRefresh
6 */
7
8 namespace JordanLeven\Plugins\ForceRefresh;
9
10 /**
11 * Function used to get the post ID of the post that is requesting a refresh.
12 *
13 * @return mixed The post ID of the requested post or null
14 */
15 function get_refresh_request_post_id() {
16 // This function returns the post id after the nonce has already been validated.
17 // phpcs:disable WordPress.Security.NonceVerification
18 $post_id = isset( $_REQUEST['post_id'] )
19 ? sanitize_text_field( wp_unslash( $_REQUEST['post_id'] ) )
20 : null;
21 // phpcs:enable WordPress.Security.NonceVerification
22 return $post_id;
23 };
24
25 /**
26 * Function used by administrators to request a refresh of a specific page.
27 *
28 * @return void
29 */
30 function request_refresh_page() {
31 if ( ! is_user_authorized_to_request_refresh() ) {
32 return_api_response(
33 401,
34 MESSAGE_ERROR_UNAUTHORIZED
35 );
36 } else {
37 $page_version = get_new_version();
38 // Get the page id.
39 $page_id = get_refresh_request_post_id();
40 // Remove the old.
41 delete_post_meta( $page_id, 'force_refresh_current_page_version' );
42 // Add the new.
43 update_post_meta(
44 $page_id,
45 'force_refresh_current_page_version',
46 $page_version,
47 null,
48 'no'
49 );
50 return_api_response(
51 200,
52 MESSAGE_SUCCESS_PAGE,
53 array(
54 'new_page_version' => $page_version,
55 'refresh_interval' => (int) get_option(
56 WP_FORCE_REFRESH_OPTION_REFRESH_INTERVAL_IN_SECONDS,
57 WP_FORCE_REFRESH_OPTION_REFRESH_INTERVAL_IN_SECONDS_DEFAULT
58 ),
59 )
60 );
61 }
62 }
63
64 // Register the action used by administrators to refresh a specific page.
65 add_action(
66 'wp_ajax_force_refresh_update_page_version',
67 __NAMESPACE__ . '\\request_refresh_page'
68 );
69