| 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 |
|