| 1 |
<?php |
| 2 |
/** |
| 3 |
* Our API calls responsible for handling requests from website visitors. |
| 4 |
* |
| 5 |
* @package ForceRefresh |
| 6 |
* @subpackage ApiCalls |
| 7 |
*/ |
| 8 |
|
| 9 |
/** |
| 10 |
* Custom intervals must be at least 30 seconds. |
| 11 |
*/ |
| 12 |
define( 'REFRESH_INTERVAL_CUSTOM_MINIMUM_IN_SECONDS', 30 ); |
| 13 |
|
| 14 |
/** |
| 15 |
* Custom intervals must be, at max, four hours. |
| 16 |
*/ |
| 17 |
define( 'REFRESH_INTERVAL_CUSTOM_MAXIMUM_IN_SECONDS', 4 * 3600 ); |
| 18 |
|
| 19 |
/** |
| 20 |
* Function to reply to the client with a response. |
| 21 |
* |
| 22 |
* @param int $status_code The standardized HTTP status code. |
| 23 |
* @param string $message The plaintext message displayed to the user |
| 24 |
* that explains the status. |
| 25 |
* @param array $data An array of data to sent as the response. |
| 26 |
* |
| 27 |
* @return void |
| 28 |
*/ |
| 29 |
function return_api_response( int $status_code, string $message, $data = array() ) { |
| 30 |
status_header( $status_code ); |
| 31 |
print wp_json_encode( |
| 32 |
array( |
| 33 |
'status_code' => $status_code, |
| 34 |
'status_text' => $message, |
| 35 |
'success' => 200 === $status_code, |
| 36 |
'data' => $data, |
| 37 |
) |
| 38 |
); |
| 39 |
wp_die(); |
| 40 |
} |
| 41 |
|
| 42 |
// All ajax calls from admins. |
| 43 |
require_once __DIR__ . '/admin/admin.php'; |
| 44 |
// All ajax calls from clients. |
| 45 |
require_once __DIR__ . '/client/client.php'; |
| 46 |
|