PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 3.4.7
JetFormBuilder — Dynamic Blocks Form Builder v3.4.7
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 / rest-api / endpoints / get-form-fields.php
jetformbuilder / modules / rest-api / endpoints Last commit date
get-form-fields.php 2 years ago install-migrations-endpoint.php 2 years ago
get-form-fields.php
88 lines
1 <?php
2
3
4 namespace JFB_Modules\Rest_Api\Endpoints;
5
6 use Jet_Form_Builder\Blocks\Block_Helper;
7 use Jet_Form_Builder\Exceptions\Repository_Exception;
8 use Jet_Form_Builder\Exceptions\Silence_Exception;
9 use Jet_Form_Builder\Form_Manager;
10 use Jet_Form_Builder\Request\Exceptions\Plain_Value_Exception;
11 use JFB_Components\Rest_Api\Rest_Api_Endpoint_Base;
12 use JFB_Modules\Block_Parsers\Field_Data_Parser;
13
14 // If this file is called directly, abort.
15 if ( ! defined( 'WPINC' ) ) {
16 die;
17 }
18
19 class Get_Form_Fields extends Rest_Api_Endpoint_Base {
20
21 public static function get_rest_base() {
22 return '(?P<id>[\d]+)/fields';
23 }
24
25 public static function get_methods() {
26 return \WP_REST_Server::READABLE;
27 }
28
29 public function get_common_args(): array {
30 return array(
31 'id' => array(
32 'type' => 'integer',
33 'required' => true,
34 ),
35 );
36 }
37
38 public function check_permission(): bool {
39 return current_user_can( 'edit_jet_fb_forms' );
40 }
41
42 public function run_callback( \WP_REST_Request $request ) {
43 $form_id = $request->get_param( 'id' );
44 $form = get_post( $form_id );
45
46 if ( absint( $form->post_author ) !== get_current_user_id()
47 && ! current_user_can( 'edit_post', $form->ID )
48 ) {
49 return new \WP_REST_Response(
50 array(
51 'message' => __( 'Not allowed', 'jet-form-builder' ),
52 ),
53 403
54 );
55 }
56
57 jet_fb_context()->set_parsers(
58 Block_Helper::get_blocks_by_post( $form )
59 );
60
61 foreach ( jet_fb_context()->iterate_parsers() as $name => $parser ) {
62 if ( $parser->is_secure() ) {
63 continue;
64 }
65 $fields[] = array(
66 'value' => $name,
67 'label' => $parser->get_label(),
68 'type' => $parser->get_type(),
69 );
70 }
71
72 if ( empty( $fields ) ) {
73 return new \WP_REST_Response(
74 array(
75 'message' => __( 'Not founded fields', 'jet-form-builder' ),
76 ),
77 204
78 );
79 }
80
81 return new \WP_REST_Response(
82 array(
83 'fields' => $fields,
84 )
85 );
86 }
87 }
88