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