| 1 |
<?php |
| 2 |
|
| 3 |
namespace Calotes\Component; |
| 4 |
|
| 5 |
class Response { |
| 6 |
/** |
| 7 |
* We will need to have a standard of returning data, frontend will base on the return for handling behavior |
| 8 |
* Behaviors: |
| 9 |
* - message: Show a floating notice using this param as content |
| 10 |
* - redirect: Redirect to the URL |
| 11 |
* - interval: As second, if this is set, then we will reload the page in period of time, if we have this with redirect, |
| 12 |
* then, redirect to the URL after period of time |
| 13 |
* Data: |
| 14 |
* - data: Contains the data that return to frontend, can be empty |
| 15 |
* |
| 16 |
* Response constructor. |
| 17 |
* |
| 18 |
* @param $is_success |
| 19 |
* @param $data |
| 20 |
* |
| 21 |
* @throws \Exception |
| 22 |
*/ |
| 23 |
public function __construct( $is_success, $data ) { |
| 24 |
return $is_success ? wp_send_json_success( $data ) : wp_send_json_error( $data ); |
| 25 |
} |
| 26 |
} |