| 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 by administrators to request a refresh of the site. |
| 12 |
* |
| 13 |
* @return void |
| 14 |
*/ |
| 15 |
function request_refresh_site() { |
| 16 |
if ( ! is_user_authorized_to_request_refresh() ) { |
| 17 |
return_api_response( |
| 18 |
401, |
| 19 |
MESSAGE_ERROR_UNAUTHORIZED |
| 20 |
); |
| 21 |
} else { |
| 22 |
$site_version = get_new_version(); |
| 23 |
// Remove the old option. |
| 24 |
delete_option( 'force_refresh_current_site_version' ); |
| 25 |
// Add the new option. |
| 26 |
add_option( 'force_refresh_current_site_version', $site_version ); |
| 27 |
return_api_response( |
| 28 |
200, |
| 29 |
MESSAGE_SUCCESS_SITE, |
| 30 |
array( |
| 31 |
'new_site_version' => $site_version, |
| 32 |
) |
| 33 |
); |
| 34 |
} |
| 35 |
} |
| 36 |
|
| 37 |
// Register the action used by administrators to refresh the site. |
| 38 |
add_action( |
| 39 |
'wp_ajax_force_refresh_update_site_version', |
| 40 |
__NAMESPACE__ . '\\request_refresh_site', |
| 41 |
); |
| 42 |
|