PluginProbe ʕ •ᴥ•ʔ
JetFormBuilder — Dynamic Blocks Form Builder / 1.5.2
JetFormBuilder — Dynamic Blocks Form Builder v1.5.2
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 / post-type.php
jetformbuilder / includes Last commit date
actions 4 years ago addons 4 years ago admin 4 years ago blocks 4 years ago classes 4 years ago compatibility 4 years ago dev-mode 4 years ago exceptions 4 years ago form-actions 4 years ago form-messages 4 years ago form-patterns 4 years ago form-response 4 years ago gateways 4 years ago generators 4 years ago integrations 4 years ago presets 4 years ago request 4 years ago shortcodes 4 years ago widgets 4 years ago autoloader.php 4 years ago file-upload.php 4 years ago form-break.php 4 years ago form-handler.php 4 years ago form-manager.php 4 years ago live-form.php 4 years ago plugin.php 4 years ago post-type.php 4 years ago
post-type.php
373 lines
1 <?php
2
3 namespace Jet_Form_Builder;
4
5 use Jet_Form_Builder\Classes\Get_Icon_Trait;
6 use Jet_Form_Builder\Classes\Messages_Helper_Trait;
7 use Jet_Form_Builder\Compatibility\Jet_Style_Manager;
8 use Jet_Form_Builder\Shortcodes\Manager;
9
10 // If this file is called directly, abort.
11
12 if ( ! defined( 'WPINC' ) ) {
13 die;
14 }
15
16 /**
17 * Post_Type class
18 */
19 class Post_Type {
20
21 use Messages_Helper_Trait;
22 use Get_Icon_Trait;
23
24 public $allow_gateways;
25
26 /**
27 * Used to define the editor
28 *
29 * @var boolean
30 */
31 public $is_form_editor;
32
33 public $screen;
34
35 /**
36 * Constructor for the class
37 */
38 public function __construct() {
39 add_action( 'init', array( $this, 'register_post_type' ) );
40 add_action( 'current_screen', array( $this, 'set_current_screen' ) );
41
42 add_filter( "manage_{$this->slug()}_posts_columns", array( $this, 'filter_columns' ) );
43 add_action( "manage_{$this->slug()}_posts_custom_column", array( $this, 'add_admin_column_content' ), 10, 2 );
44 }
45
46 public function filter_columns( $columns ) {
47 $after = array( 'date' => $columns['date'] );
48 unset( $columns['date'] );
49
50 $columns['jfb_shortcode'] = __( 'Shortcode', 'jet-form-builder' );
51
52 return array_merge( $columns, $after );
53 }
54
55 public function add_admin_column_content( $column, $form_id ) {
56 if ( 'jfb_shortcode' !== $column ) {
57 return;
58 }
59 $arguments = json_decode( get_post_meta( $form_id, '_jf_args', true ), true );
60 $arguments = array_diff( $arguments, $this->get_default_args() );
61 $arguments = array_merge( array( 'form_id' => $form_id ), $this->get_default_args_on_render(), $arguments );
62
63 printf(
64 '<input readonly type="text" onclick="this.select()" value="%s" style="%s"/>',
65 esc_attr( Manager::get_shortcode( 'jet_fb_form', $arguments ) ),
66 'width: 100%'
67 );
68 }
69
70
71
72 /**
73 * Returns current post type slug
74 *
75 * @return string [type] [description]
76 */
77 public function slug() {
78 return 'jet-form-builder';
79 }
80
81
82 public function set_current_screen() {
83 $this->screen = get_current_screen();
84
85 if ( ! $this->screen->action ) {
86 // phpcs:ignore WordPress.Security.NonceVerification.Recommended
87 $this->screen->action = ! empty( $_GET['action'] ) ? sanitize_key( $_GET['action'] ) : '';
88 }
89
90 $is_editor_page = in_array( $this->screen->action, array( 'add', 'edit' ), true );
91
92 if ( $this->slug() === $this->screen->id && $is_editor_page ) {
93 $this->is_form_editor = true;
94
95 } elseif ( $this->slug() !== $this->screen->id && $is_editor_page ) {
96 $this->is_form_editor = false;
97 }
98 }
99
100 public function is_form_list_page() {
101 return ( "edit-{$this->slug()}" === $this->screen->id );
102 }
103
104 /**
105 * Register templates post type
106 *
107 * @return void
108 */
109 public function register_post_type() {
110
111 $args = array(
112 'labels' => array(
113 'name' => __( 'Forms', 'jet-form-builder' ),
114 'all_items' => __( 'Forms', 'jet-form-builder' ),
115 'add_new' => __( 'Add New', 'jet-form-builder' ),
116 'add_new_item' => __( 'Add New Form', 'jet-form-builder' ),
117 'edit_item' => __( 'Edit Form', 'jet-form-builder' ),
118 'new_item' => __( 'New Form', 'jet-form-builder' ),
119 'view_item' => __( 'View Form', 'jet-form-builder' ),
120 'search_items' => __( 'Search Form', 'jet-form-builder' ),
121 'not_found' => __( 'No Forms Found', 'jet-form-builder' ),
122 'not_found_in_trash' => __( 'No Forms Found In Trash', 'jet-form-builder' ),
123 'singular_name' => __( 'JetForm', 'jet-form-builder' ),
124 'menu_name' => __( 'JetFormBuilder', 'jet-form-builder' ),
125 ),
126 'public' => true,
127 'show_ui' => true,
128 'show_in_admin_bar' => true,
129 'show_in_menu' => true,
130 'show_in_nav_menus' => false,
131 'show_in_rest' => true,
132 'publicly_queryable' => false,
133 'exclude_from_search' => true,
134 'has_archive' => false,
135 'query_var' => false,
136 'can_export' => true,
137 'rewrite' => false,
138 'capability_type' => 'post',
139 'menu_icon' => $this->get_post_type_icon(),
140 'menu_position' => 120,
141 'supports' => array( 'title', 'editor', 'custom-fields' ),
142 );
143
144 $post_type = register_post_type(
145 $this->slug(),
146 // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
147 apply_filters( 'jet-form-builder/post-type/args', $args )
148 );
149
150 $this->set_default_messages();
151
152 $meta = array(
153 '_jf_args' => array(
154 'type' => 'string',
155 'default' => wp_json_encode( $this->get_default_args() ),
156 ),
157 '_jf_recaptcha' => array(
158 'type' => 'string',
159 'default' => '{}',
160 ),
161
162 '_jf_actions' => array(
163 'type' => 'string',
164 'default' => '[]',
165 ),
166 '_jf_messages' => array(
167 'type' => 'string',
168 'default' => $this->get_default_messages_values_json(),
169 ),
170 '_jf_preset' => array(
171 'type' => 'string',
172 'default' => '{}',
173 ),
174 );
175
176 if ( Plugin::instance()->allow_gateways ) {
177 $meta['_jf_gateways'] = array(
178 'type' => 'string',
179 'default' => '{}',
180 );
181 }
182
183 foreach ( $meta as $key => $args ) {
184
185 $args = array_merge(
186 $args,
187 array(
188 'show_in_rest' => true,
189 'single' => true,
190 'auth_callback' => function ( $res, $key, $post_id, $user_id, $cap ) {
191 return user_can( $user_id, 'edit_post', $post_id );
192 },
193 )
194 );
195
196 register_post_meta( $this->slug(), $key, $args );
197
198 }
199
200 }
201
202 private function get_post_type_icon() {
203 $path = $this->get_icon_path( 'post-type.php' );
204
205 return include_once $path;
206 }
207
208 public function get_form_meta( $meta_key, $form_id ) {
209 return json_decode(
210 get_post_meta(
211 $form_id,
212 $meta_key,
213 true
214 ),
215 true
216 );
217 }
218
219 /**
220 * Returns form meta arguments:
221 * fields_layout, submit_type, captcha and required_mark
222 * in assoc array
223 *
224 * @param $form_id
225 *
226 * @return array
227 */
228 public function get_args( $form_id ) {
229 return $this->get_form_meta( '_jf_args', $form_id );
230 }
231
232 /**
233 * Returns form messages
234 *
235 * @param $form_id
236 *
237 * @return array
238 */
239 public function get_messages( $form_id ) {
240 $messages = $this->get_form_meta( '_jf_messages', $form_id );
241
242 if ( empty( $messages ) ) {
243 return $this->messages;
244 }
245
246 return $messages;
247 }
248
249 /**
250 * Returns form actions
251 *
252 * @param $form_id
253 *
254 * @return array
255 */
256 public function get_actions( $form_id ) {
257 return $this->get_form_meta( '_jf_actions', $form_id );
258 }
259
260 /**
261 * Returns form actions
262 *
263 * @param $form_id
264 *
265 * @return array
266 */
267 public function get_preset( $form_id ) {
268 return $this->get_form_meta( '_jf_preset', $form_id );
269 }
270
271 /**
272 * Returns captcha settings
273 *
274 * @param $form_id
275 *
276 * @return array
277 */
278 public function get_recaptcha( $form_id ) {
279 return $this->get_form_meta( '_jf_recaptcha', $form_id );
280 }
281
282 public function maybe_get_jet_sm_ready_styles( $form_id ) {
283 if ( Jet_Style_Manager::is_activated() ) {
284 return get_post_meta( $form_id, '_jet_sm_ready_style', true );
285 }
286
287 return '';
288 }
289
290
291 /**
292 * Returns form gateways
293 *
294 * @param $form_id
295 *
296 * @return array
297 */
298 public function get_gateways( $form_id ) {
299 return $this->get_form_meta( '_jf_gateways', $form_id );
300 }
301
302
303 public function get_default_args() {
304 return array(
305 'submit_type' => '',
306 'required_mark' => '',
307 'fields_layout' => '',
308 'enable_progress' => null,
309 'fields_label_tag' => ''
310 );
311 }
312
313 public function get_default_args_on_render() {
314 return array(
315 'submit_type' => 'reload',
316 'required_mark' => '*',
317 'fields_layout' => 'column',
318 'enable_progress' => false,
319 'fields_label_tag' => 'div'
320 );
321 }
322
323 public function set_default_messages() {
324 $this->messages = apply_filters(
325 // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
326 'jet-form-builder/message-types',
327 array(
328 'success' => array(
329 'label' => __( 'Form successfully submitted.', 'jet-form-builder' ),
330 'value' => 'Form successfully submitted.',
331 ),
332 'failed' => array(
333 'label' => __( 'Submit failed.', 'jet-form-builder' ),
334 'value' => 'There was an error trying to submit form. Please try again later.',
335 ),
336 'validation_failed' => array(
337 'label' => __( 'Validation error', 'jet-form-builder' ),
338 'value' => 'One or more fields have an error. Please check and try again.',
339 ),
340 'captcha_failed' => array(
341 'label' => __( 'Captcha validation failed', 'jet-form-builder' ),
342 'value' => __( 'Captcha validation failed', 'jet-form-builder' ),
343 ),
344 'invalid_email' => array(
345 'label' => __( 'Entered an invalid email', 'jet-form-builder' ),
346 'value' => 'The e-mail address entered is invalid.',
347 ),
348 'empty_field' => array(
349 'label' => __( 'Required field is empty', 'jet-form-builder' ),
350 'value' => 'The field is required.',
351 ),
352 'internal_error' => array(
353 'label' => __( 'Internal server error', 'jet-form-builder' ),
354 'value' => 'Internal server error. Please try again later.',
355 ),
356 'upload_max_files' => array(
357 'label' => __( 'Media Specific: Max files limit', 'jet-form-builder' ),
358 'value' => 'Maximum upload files limit is reached.',
359 ),
360 'upload_max_size' => array(
361 'label' => __( 'Media Specific: Max size reached', 'jet-form-builder' ),
362 'value' => 'Upload max size exceeded.',
363 ),
364 'upload_mime_types' => array(
365 'label' => __( 'Media Specific: File type error', 'jet-form-builder' ),
366 'value' => 'File type is not allowed.',
367 ),
368 )
369 );
370 }
371
372 }
373