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