class-wpml-ajax-response.php
865 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
<?php
class WPML_Ajax_Response {
private $success;
private $response_data;
public function __construct( $success, $response_data ) {
$this->success = $success;
$this->response_data = $response_data;
}
public function send_json() {
if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) {
if ( $this->success ) {
wp_send_json_success( $this->response_data );
} else {
wp_send_json_error( $this->response_data );
}
} else {
throw new WPML_Not_Doing_Ajax_On_Send_Exception( $this );
}
}
public function is_success() {
return $this->success;
}
public function get_response() {
return $this->response_data;
}
}
class WPML_Not_Doing_Ajax_On_Send_Exception extends Exception {
public $response;
public function __construct( $response ) {
parent::__construct( 'Not doing AJAX' );
$this->response = $response;
}
};