PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 2.1.8
JetFormBuilder — Dynamic Blocks Form Builder v2.1.8
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 / includes / integrations / active-campaign / rest-api / editor-fetch-endpoint.php
jetformbuilder / includes / integrations / active-campaign / rest-api Last commit date
editor-fetch-endpoint.php 3 years ago rest-controller.php 3 years ago
editor-fetch-endpoint.php
98 lines
1 <?php
2
3
4 namespace Jet_Form_Builder\Integrations\Active_Campaign\Rest_Api;
5
6
7 use Jet_Form_Builder\Exceptions\Gateway_Exception;
8 use Jet_Form_Builder\Integrations\Active_Campaign\Api\Retrieve_Custom_Fields_Action;
9 use Jet_Form_Builder\Integrations\Active_Campaign\Api\Retrieve_Lists_Action;
10 use Jet_Form_Builder\Rest_Api\Rest_Api_Endpoint_Base;
11
12 class Editor_Fetch_Endpoint extends Rest_Api_Endpoint_Base {
13
14 public static function get_rest_base() {
15 return 'activecampaign/editor';
16 }
17
18 public static function get_methods() {
19 return \WP_REST_Server::READABLE;
20 }
21
22 public function check_permission(): bool {
23 return current_user_can( 'manage_options' );
24 }
25
26 public function run_callback( \WP_REST_Request $request ) {
27 $token = $request->get_header( 'API-TOKEN' );
28 $url = $request->get_header( 'API-URL' );
29
30 try {
31 /** @var Retrieve_Custom_Fields_Action $fields */
32 $fields = ( new Retrieve_Custom_Fields_Action() )
33 ->set_base( $url )
34 ->set_token( $token )
35 ->request()
36 ->check_response_code()
37 ->response_body_as_array();
38
39 } catch ( Gateway_Exception $exception ) {
40 return new \WP_REST_Response(
41 array(
42 'action' => Retrieve_Custom_Fields_Action::class,
43 'message' => $exception->getMessage(),
44 'data' => $exception->get_additional()
45 ),
46 400
47 );
48 }
49
50 try {
51 /** @var Retrieve_Lists_Action $lists */
52 $lists = ( new Retrieve_Lists_Action() )
53 ->set_base( $url )
54 ->set_token( $token )
55 ->request()
56 ->check_response_code()
57 ->response_body_as_array();
58
59 } catch ( Gateway_Exception $exception ) {
60 return new \WP_REST_Response(
61 array(
62 'action' => Retrieve_Lists_Action::class,
63 'message' => $exception->getMessage(),
64 'data' => $exception->get_additional()
65 ),
66 400
67 );
68 }
69
70 return new \WP_REST_Response(
71 array(
72 'fields' => array_merge(
73 array(
74 array(
75 'value' => 'email',
76 'label' => __( 'Email', 'jet-form-builder' ),
77 'required' => true,
78 ),
79 array(
80 'value' => 'firstName',
81 'label' => __( 'First Name', 'jet-form-builder' ),
82 ),
83 array(
84 'value' => 'lastName',
85 'label' => __( 'Last Name', 'jet-form-builder' ),
86 ),
87 array(
88 'value' => 'phone',
89 'label' => __( 'Phone', 'jet-form-builder' ),
90 ),
91 ),
92 $fields->to_array()
93 ),
94 'lists' => $lists->to_array(),
95 )
96 );
97 }
98 }