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