PluginProbe
HubSpot All-In-One Marketing – Forms, Popups, Live Chat / 11.3.75
HubSpot All-In-One Marketing – Forms, Popups, Live Chat v11.3.75
11.3.75 11.3.73 11.3.71 11.3.70 11.3.69 11.3.64 11.3.65 11.3.62 11.3.61 11.3.56 11.3.58 11.0.31 11.0.52 11.0.54 11.0.56 11.0.58 11.0.7 11.1.10 11.1.11 11.1.13 11.1.14 11.1.15 11.1.2 11.1.20 11.1.21 All 73 releases
leadin / public / utils / class-requestutils.php

class-requestutils.php in HubSpot All-In-One Marketing – Forms, Popups, Live Chat 11.3.75, at public/utils/class-requestutils.php

57 lines 1.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace Leadin\utils;
4
5 /**
6 * Static class containing methods used on ajax requests handling.
7 */
8 class RequestUtils {
9 /**
10 * Send JSON response.
11 *
12 * @param Mixed $body response to send as JSON.
13 * @param Number $code http code to return.
14 */
15 private static function send( $body, $code ) {
16 wp_send_json( $body, intval( $code ) );
17 }
18
19 /**
20 * Send JSON response with 200 code.
21 *
22 * @param Mixed $body response to send as JSON.
23 */
24 public static function send_json( $body = array() ) {
25 self::send( $body, 200 );
26 }
27
28 /**
29 * Send error response with message
30 *
31 * @param String $error Message to be sent on te JSON.
32 * @param Number $code Error code to be sent in the error. Default 400.
33 */
34 public static function send_error_message( $error, $code = 400 ) {
35 self::send(
36 array(
37 'error' => $error,
38 ),
39 intval( $code )
40 );
41 }
42
43 /**
44 * Send JSON response with a message key.
45 *
46 * @param String $message Message to be sent on te JSON.
47 */
48 public static function send_message( $message ) {
49 self::send(
50 array(
51 'message' => $message,
52 ),
53 200
54 );
55 }
56 }
57