| 1 |
<?php |
| 2 |
|
| 3 |
// The call used for users requesting the current site version from non-admins |
| 4 |
add_action( 'wp_ajax_nopriv_force_refresh_get_version', __NAMESPACE__ . "\\ajax_request_get_version"); |
| 5 |
|
| 6 |
// The call used for users requesting the current site version from admins |
| 7 |
add_action( 'wp_ajax_force_refresh_get_version', __NAMESPACE__ . "\\ajax_request_get_version"); |
| 8 |
|
| 9 |
/** |
| 10 |
* The function used by ajax requests to get the current site version. |
| 11 |
* |
| 12 |
* @return void |
| 13 |
* |
| 14 |
* @version 1.0 Introducted in version 1.0 |
| 15 |
*/ |
| 16 |
function ajax_request_get_version(){ |
| 17 |
// Get the data |
| 18 |
$data = $_REQUEST; |
| 19 |
// Declare our return |
| 20 |
$return_array = array(); |
| 21 |
// Whether or not the call was successful |
| 22 |
$success = true; |
| 23 |
// The HTTP status code |
| 24 |
$status_code = 200; |
| 25 |
// The status text |
| 26 |
$status_text = "The current site version has been successfully retrieved."; |
| 27 |
// Get the post ID |
| 28 |
$post_id = isset( $_REQUEST['post_id'] ) ? $_REQUEST['post_id'] : null; |
| 29 |
// The return data |
| 30 |
$return_data = array(); |
| 31 |
// Get the current site version |
| 32 |
$current_site_version = get_option("force_refresh_current_site_version"); |
| 33 |
// Get the current site version |
| 34 |
$current_page_version = get_post_meta( $post_id, 'force_refresh_current_page_version', true); |
| 35 |
// If no current site version exists, then the site version will default to version 0. This should be a string and not an integer |
| 36 |
if ( !$current_site_version ){ |
| 37 |
$current_site_version = "0"; |
| 38 |
} |
| 39 |
if ( !$current_page_version ){ |
| 40 |
$current_page_version = "0"; |
| 41 |
} |
| 42 |
$return_data['current_site_version'] = $current_site_version; |
| 43 |
$return_data['current_page_version'] = $current_page_version; |
| 44 |
// Set the HTTP code |
| 45 |
status_header($status_code); |
| 46 |
// Return the success |
| 47 |
$return_array['success'] = $success; |
| 48 |
// Return the status code |
| 49 |
$return_array['status_code'] = $status_code; |
| 50 |
// Return the status text |
| 51 |
$return_array['status_text'] = $status_text; |
| 52 |
// Return the return data |
| 53 |
$return_array['return_data'] = $return_data; |
| 54 |
print json_encode($return_array); |
| 55 |
wp_die(); |
| 56 |
} |
| 57 |
|
| 58 |
?> |