PluginProbe
Force Refresh / 2.7.0
Force Refresh v2.7.0
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 2.12.1 All 53 releases
force-refresh / includes / api / admin / admin.php

admin.php in Force Refresh 2.7.0, at includes/api/admin/admin.php

65 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 admins requesting a refresh for the site.
4 *
5 * @package ForceRefresh
6 */
7
8 namespace JordanLeven\Plugins\ForceRefresh;
9
10 define(
11 'MESSAGE_SUCCESS_SITE',
12 'You\'ve successfully requested all browsers to refresh.'
13 );
14
15 define(
16 'MESSAGE_SUCCESS_PAGE',
17 'You\'ve successfully requested all browsers to refresh this page.'
18 );
19
20 define(
21 'MESSAGE_ERROR_UNAUTHORIZED',
22 'I\'m sorry, but you are not authorized to request refreshes.'
23 );
24
25 /**
26 * Function to check the nonce provided in the call.
27 *
28 * @return boolean True if the provided nonce is valid.
29 */
30 function is_admin_nonce_valid() {
31 return check_admin_referer( WP_FORCE_REFRESH_ACTION, 'nonce' );
32 }
33
34 /**
35 * Function to retrieve a hash that can be used as the version. This function will
36 * deliver a unique ID that can be used to identify a unique version of a site, page,
37 * or post.
38 *
39 * @return string The unique version ID
40 */
41 function get_new_version() {
42 $time = current_time( 'mysql' );
43 $site_version_hash = wp_hash( $time );
44 // Get the first eight characters (the chance of having a duplicate hash from
45 // the first 8 characters is low).
46 $site_version = substr( $site_version_hash, 0, 8 );
47 return $site_version;
48 }
49
50 /**
51 * Function to check whether or not a WordPress user is authorized to request a
52 * refresh. This function will check both if a user's nonce is valid and whether
53 * the user role has the proper permissions.
54 *
55 * @return boolean True if the user is authorized to request a refresh
56 */
57 function is_user_authorized_to_request_refresh() {
58 return is_admin_nonce_valid() && user_can_request_force_refresh();
59 }
60
61 require_once __DIR__ . '/inc.refresh-page.php';
62 require_once __DIR__ . '/inc.refresh-site.php';
63 require_once __DIR__ . '/inc.save-debug.php';
64 require_once __DIR__ . '/inc.save-options.php';
65