PluginProbe
ShopBuilder – WooCommerce Builder For Elementor / 2.0.3
ShopBuilder – WooCommerce Builder For Elementor v2.0.3
3.4.2 3.4.1 3.4.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 2.2.0 2.2.1 2.2.2 All 63 releases
shopbuilder / app / Abstracts / Api.php

Api.php in ShopBuilder – WooCommerce Builder For Elementor 2.0.3, at app/Abstracts/Api.php

71 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace RadiusTheme\SB\Abstracts;
4
5 use WP_Error;
6 use WP_HTTP_Response;
7 use WP_REST_Response;
8
9 // Do not allow directly accessing this file.
10 if ( ! defined( 'ABSPATH' ) ) {
11 exit( 'This script cannot be accessed directly.' );
12 }
13
14 abstract class Api {
15 const API_PREFIX = 'rtsb';
16 protected $version = 'v1';
17
18 abstract public function config();
19
20 abstract public function init();
21
22 public function __construct() {
23 $this->config();
24 $this->init();
25 }
26
27 public function getNamespace() {
28 $version = empty( $this->version ) ? 'v1' : $this->version;
29
30 return self::API_PREFIX . '/' . $version;
31 }
32
33 /**
34 * @param $message
35 * @param array $data
36 *
37 * @return WP_Error|WP_HTTP_Response|WP_REST_Response
38 */
39 protected function sendResponse( $data = [], $message = '' ) {
40 $resData = [
41 'success' => true,
42 'data' => $data,
43 'message' => $message,
44 ];
45 $response = new WP_REST_Response( $resData );
46
47 return rest_ensure_response( $response );
48 }
49
50 /**
51 * @param string $error
52 * @param int $code
53 * @param array $errorData
54 *
55 * @return WP_Error|WP_HTTP_Response|WP_REST_Response
56 */
57 protected function sendError( $error, $errorData = [], $code = 200 ) {
58 $resData = [
59 'success' => false,
60 'message' => $error,
61 ];
62 if ( ! empty( $errorData ) ) {
63 $resData['data'] = $errorData;
64 }
65 $response = new WP_REST_Response( $resData );
66 $response->set_status( $code );
67
68 return rest_ensure_response( $response );
69 }
70
71 }