PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.2.3
JetFormBuilder — Dynamic Blocks Form Builder v3.2.3
3.6.3.1 3.6.3 3.6.2.2 3.6.2.1 3.6.2 3.6.1.1 3.6.1 3.6.0.1 trunk 1.0.0 1.0.1 1.0.2 1.0.3 1.1.0 1.1.1 1.1.2 1.1.3 1.1.4 1.1.5 1.1.6 1.1.7 1.2.0 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.3.0 1.3.1 1.3.2 1.3.3 1.4.0 1.4.1 1.4.2 1.4.3 1.5.0 1.5.1 1.5.2 1.5.3 1.5.4 1.5.5 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.1.0 2.1.1 2.1.10 2.1.11 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.1.7 2.1.8 2.1.9 3.0.0 3.0.0.1 3.0.0.2 3.0.0.3 3.0.1 3.0.1.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.0.8 3.0.9 3.1.0 3.1.0.1 3.1.1 3.1.2 3.1.3 3.1.4 3.1.5 3.1.6 3.1.7 3.1.8 3.1.9 3.2.0 3.2.1 3.2.2 3.2.3 3.3.0 3.3.1 3.3.2 3.3.3 3.3.3.1 3.3.4 3.3.4.1 3.3.4.2 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.4.5.1 3.4.5.2 3.4.6 3.4.7 3.4.7.1 3.5.0 3.5.1 3.5.1.1 3.5.1.2 3.5.2 3.5.2.1 3.5.3 3.5.4 3.5.5 3.5.6 3.5.6.1 3.5.6.2 3.5.6.3 3.6.0
jetformbuilder / modules / active-campaign / rest-api / editor-fetch-endpoint.php
jetformbuilder / modules / active-campaign / rest-api Last commit date
editor-fetch-endpoint.php 2 years ago rest-controller.php 2 years ago
editor-fetch-endpoint.php
103 lines
1 <?php
2
3
4 namespace JFB_Modules\Active_Campaign\Rest_Api;
5
6 use Jet_Form_Builder\Exceptions\Gateway_Exception;
7 use JFB_Modules\Active_Campaign\Api\Retrieve_Custom_Fields_Action;
8 use JFB_Modules\Active_Campaign\Api\Retrieve_Lists_Action;
9 use JFB_Components\Rest_Api\Rest_Api_Endpoint_Base;
10
11 // If this file is called directly, abort.
12 if ( ! defined( 'WPINC' ) ) {
13 die;
14 }
15
16 class Editor_Fetch_Endpoint extends Rest_Api_Endpoint_Base {
17
18 public static function get_rest_base() {
19 return 'activecampaign/editor';
20 }
21
22 public static function get_methods() {
23 return \WP_REST_Server::READABLE;
24 }
25
26 public function check_permission(): bool {
27 return current_user_can( 'manage_options' );
28 }
29
30 public function run_callback( \WP_REST_Request $request ) {
31 $token = $request->get_header( 'API-TOKEN' );
32 $url = $request->get_header( 'API-URL' );
33
34 try {
35 /** @var Retrieve_Custom_Fields_Action $fields */
36 $fields = ( new Retrieve_Custom_Fields_Action() )
37 ->set_base( $url )
38 ->set_token( $token )
39 ->request()
40 ->check_response_code()
41 ->response_body_as_array();
42
43 } catch ( Gateway_Exception $exception ) {
44 return new \WP_REST_Response(
45 array(
46 'action' => Retrieve_Custom_Fields_Action::class,
47 'message' => $exception->getMessage(),
48 'data' => $exception->get_additional(),
49 ),
50 400
51 );
52 }
53
54 try {
55 /** @var Retrieve_Lists_Action $lists */
56 $lists = ( new Retrieve_Lists_Action() )
57 ->set_base( $url )
58 ->set_token( $token )
59 ->request()
60 ->check_response_code()
61 ->response_body_as_array();
62
63 } catch ( Gateway_Exception $exception ) {
64 return new \WP_REST_Response(
65 array(
66 'action' => Retrieve_Lists_Action::class,
67 'message' => $exception->getMessage(),
68 'data' => $exception->get_additional(),
69 ),
70 400
71 );
72 }
73
74 return new \WP_REST_Response(
75 array(
76 'fields' => array_merge(
77 array(
78 array(
79 'value' => 'email',
80 'label' => __( 'Email', 'jet-form-builder' ),
81 'required' => true,
82 ),
83 array(
84 'value' => 'firstName',
85 'label' => __( 'First Name', 'jet-form-builder' ),
86 ),
87 array(
88 'value' => 'lastName',
89 'label' => __( 'Last Name', 'jet-form-builder' ),
90 ),
91 array(
92 'value' => 'phone',
93 'label' => __( 'Phone', 'jet-form-builder' ),
94 ),
95 ),
96 $fields->to_array()
97 ),
98 'lists' => $lists->to_array(),
99 )
100 );
101 }
102 }
103