PluginProbe
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 1.0.7
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v1.0.7
2.12.6 2.12.5 2.12.4 2.12.3 2.12.2 2.12.1 2.12.0 2.11.1 2.11.0 2.10.1 2.10.0 2.9.1 2.9.0 2.8.2 2.8.1 2.7.0 2.7.1 2.8.0 trunk 0.0.10 0.0.11 0.0.12 0.0.13 0.0.2 0.0.3 All 96 releases
sureforms / inc / post-types.php
post-types.php
837 lines 24.3 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Post Types Class file.
4 *
5 * @package sureforms.
6 * @since 0.0.1
7 */
8
9 namespace SRFM\Inc;
10
11 use SRFM\Inc\Database\Tables\Entries;
12 use SRFM\Inc\Traits\Get_Instance;
13 use WP_Admin_Bar;
14
15 if ( ! defined( 'ABSPATH' ) ) {
16 exit; // Exit if accessed directly.
17 }
18
19 /**
20 * Post Types Main Class.
21 *
22 * @since 0.0.1
23 */
24 class Post_Types {
25 use Get_Instance;
26
27 /**
28 * Constructor
29 *
30 * @since 0.0.1
31 */
32 public function __construct() {
33 $this->restrict_unwanted_insertions();
34 add_action( 'init', [ $this, 'register_post_types' ] );
35 add_action( 'init', [ $this, 'register_post_metas' ] );
36 add_filter( 'manage_sureforms_form_posts_columns', [ $this, 'custom_form_columns' ] );
37 add_action( 'manage_sureforms_form_posts_custom_column', [ $this, 'custom_form_column_data' ], 10, 2 );
38 add_shortcode( 'sureforms', [ $this, 'forms_shortcode' ] );
39 add_action( 'manage_posts_extra_tablenav', [ $this, 'maybe_render_blank_form_state' ] );
40 add_action( 'in_admin_header', [ $this, 'embed_page_header' ] );
41 add_filter( 'post_row_actions', [ $this, 'modify_entries_list_row_actions' ], 10, 2 );
42 add_filter( 'bulk_actions-edit-sureforms_form', [ $this, 'register_modify_bulk_actions' ], 99 );
43 add_action( 'admin_notices', [ $this, 'import_form_popup' ] );
44 add_action( 'admin_bar_menu', [ $this, 'remove_admin_bar_menu_item' ], 80, 1 );
45 add_action( 'template_redirect', [ $this, 'srfm_instant_form_redirect' ] );
46 }
47
48 /**
49 * Add SureForms menu.
50 *
51 * @param string $title Parent slug.
52 * @param string $subtitle Parent slug.
53 * @param string $image Parent slug.
54 * @param string $button_text Parent slug.
55 * @param string $button_url Parent slug.
56 * @param string $after_button After button content.
57 * @return void
58 * @since 0.0.1
59 */
60 public function get_blank_page_markup( $title, $subtitle, $image, $button_text = '', $button_url = '', $after_button = '' ) {
61 echo '<div class="sureform-add-new-form">';
62
63 echo '<p class="sureform-blank-page-title">' . esc_html( $title ) . '</p>';
64
65 echo '<p class="sureform-blank-page-subtitle">' . esc_html( $subtitle ) . '</p>';
66
67 echo '<img src="' . esc_url( SRFM_URL . '/images/' . $image . '.svg' ) . '">';
68
69 if ( ! empty( $button_text ) && ! empty( $button_url ) ) {
70 echo '<div class="sureforms-add-new-form-container"><a class="sf-add-new-form-button" href="' . esc_url( $button_url ) . '"><div class="button-secondary">' . esc_html( $button_text ) . '</div></a>' . wp_kses_post( $after_button ) . '</div>';
71 }
72 echo '</div>';
73 }
74
75 /**
76 * Render blank state for add new form screen.
77 *
78 * @param string $post_type Post type.
79 * @return void
80 * @since 0.0.1
81 */
82 public function sureforms_render_blank_state( $post_type ) {
83
84 if ( SRFM_FORMS_POST_TYPE === $post_type ) {
85 $page_name = 'add-new-form';
86 $new_form_url = admin_url( 'admin.php?page=' . $page_name );
87 $import_button = '<button class="button button-secondary srfm-import-btn">' . __( 'Import Form', 'sureforms' ) . '</button>';
88
89 $this->get_blank_page_markup(
90 esc_html__( 'Let’s build your first form', 'sureforms' ),
91 esc_html__(
92 'Craft beautiful and functional forms in minutes',
93 'sureforms'
94 ),
95 'add-new-form',
96 esc_html__( 'Add New Form', 'sureforms' ),
97 $new_form_url,
98 $import_button
99 );
100 }
101
102 if ( SRFM_ENTRIES === $post_type ) {
103
104 $this->get_blank_page_markup(
105 esc_html__( 'No records found', 'sureforms' ),
106 esc_html__(
107 'This is where your form entries will appear',
108 'sureforms'
109 ),
110 'blank-entries'
111 );
112 }
113 }
114
115 /**
116 * Registers the forms and submissions post types.
117 *
118 * @return void
119 * @since 0.0.1
120 */
121 public function register_post_types() {
122 $form_labels = [
123 'name' => _x( 'Forms', 'post type general name', 'sureforms' ),
124 'singular_name' => _x( 'Form', 'post type singular name', 'sureforms' ),
125 'menu_name' => _x( 'Forms', 'admin menu', 'sureforms' ),
126 'add_new' => _x( 'Add New', 'form', 'sureforms' ),
127 'add_new_item' => __( 'Add New Form', 'sureforms' ),
128 'new_item' => __( 'New Form', 'sureforms' ),
129 'edit_item' => __( 'Edit Form', 'sureforms' ),
130 'view_item' => __( 'View Form', 'sureforms' ),
131 'view_items' => __( 'View Forms', 'sureforms' ),
132 'all_items' => __( 'Forms', 'sureforms' ),
133 'search_items' => __( 'Search Forms', 'sureforms' ),
134 'parent_item_colon' => __( 'Parent Forms:', 'sureforms' ),
135 'not_found' => __( 'No forms found.', 'sureforms' ),
136 'not_found_in_trash' => __( 'No forms found in Trash.', 'sureforms' ),
137 'item_published' => __( 'Form published.', 'sureforms' ),
138 'item_updated' => __( 'Form updated.', 'sureforms' ),
139 ];
140 register_post_type(
141 SRFM_FORMS_POST_TYPE,
142 [
143 'labels' => $form_labels,
144 'rewrite' => [ 'slug' => 'form' ],
145 'public' => true,
146 'show_in_rest' => true,
147 'has_archive' => false,
148 'show_ui' => true,
149 'supports' => [ 'title', 'author', 'editor', 'custom-fields' ],
150 'show_in_menu' => 'sureforms_menu',
151 'show_in_nav_menus' => true,
152 ]
153 );
154 // will be used later.
155 // register_post_status(
156 // 'unread',
157 // array(
158 // 'label' => _x( 'Unread', 'sureforms', 'sureforms' ),
159 // 'public' => true,
160 // 'exclude_from_search' => false,
161 // 'show_in_admin_all_list' => true,
162 // 'show_in_admin_status_list' => true,
163 // Translators: %s is the number of unread items.
164 // 'label_count' => _n_noop( 'Unread (%s)', 'Unread (%s)', 'sureforms' ),
165 // )
166 // );.
167 }
168
169 /**
170 * Remove add new form menu item.
171 *
172 * @param WP_Admin_Bar $wp_admin_bar WP_Admin_Bar instance.
173 *
174 * @return void
175 * @since 0.0.1
176 */
177 public function remove_admin_bar_menu_item( $wp_admin_bar ) {
178 $wp_admin_bar->remove_node( 'new-sureforms_form' );
179 }
180
181 /**
182 * Modify list row actions.
183 *
184 * @param array<mixed> $actions An array of row action links.
185 * @param \WP_Post $post The current WP_Post object.
186 *
187 * @return array<mixed> $actions Modified row action links.
188 * @since 0.0.1
189 */
190 public function modify_entries_list_row_actions( $actions, $post ) {
191 if ( 'sureforms_form' === $post->post_type ) {
192 $actions['export'] = '<a href="#" onclick="exportForm(' . $post->ID . ')">' . __( 'Export', 'sureforms' ) . '</a>';
193 }
194
195 return $actions;
196 }
197
198 /**
199 * Modify list bulk actions.
200 *
201 * @param array<mixed> $bulk_actions An array of bulk action links.
202 * @since 0.0.1
203 * @return array<mixed> $bulk_actions Modified action links.
204 */
205 public function register_modify_bulk_actions( $bulk_actions ) {
206
207 $white_listed_actions = [
208 'edit',
209 'trash',
210 'delete',
211 'untrash',
212 ];
213
214 // remove all actions except white listed actions.
215 $bulk_actions = array_intersect_key( $bulk_actions, array_flip( $white_listed_actions ) );
216
217 // Add export action only if edit and trash actions are present in bulk actions.
218 if ( isset( $bulk_actions['edit'] ) && isset( $bulk_actions['trash'] ) ) {
219 $bulk_actions['export'] = __( 'Export', 'sureforms' );
220 }
221
222 return $bulk_actions;
223 }
224
225 /**
226 * Show blank slate styles.
227 *
228 * @return void
229 * @since 0.0.1
230 */
231 public function get_blank_state_styles() {
232 echo '<style type="text/css">.sf-add-new-form-button:focus { box-shadow:none !important; outline:none !important; } #posts-filter .wp-list-table, #posts-filter .tablenav.top, .tablenav.bottom .actions, .wrap .subsubsub { display: none; } #posts-filter .tablenav.bottom { height: auto; } .sureform-add-new-form{ display: flex; flex-direction: column; gap: 8px; justify-content: center; align-items: center; padding: 24px 0 24px 0; } .sureform-blank-page-title { color: var(--dashboard-heading); font-family: Inter; font-size: 22px; font-style: normal; font-weight: 600; line-height: 28px; margin: 0; } .sureform-blank-page-subtitle { color: var(--dashboard-text); margin: 0; font-family: Inter; font-size: 14px; font-style: normal; font-weight: 400; line-height: 16px; }</style>';
233 }
234
235 /**
236 * Show blank slate.
237 *
238 * @param string $which String which tablenav is being shown.
239 * @return void
240 * @since 0.0.1
241 */
242 public function maybe_render_blank_form_state( $which ) {
243 $screen = get_current_screen();
244 $post_type = $screen ? $screen->post_type : '';
245
246 if ( SRFM_FORMS_POST_TYPE === $post_type && 'bottom' === $which ) {
247
248 $counts = (array) wp_count_posts( SRFM_FORMS_POST_TYPE );
249 unset( $counts['auto-draft'] );
250 $count = array_sum( $counts );
251
252 if ( 0 < $count ) {
253 return;
254 }
255
256 $this->sureforms_render_blank_state( $post_type );
257
258 $this->get_blank_state_styles();
259
260 }
261 }
262
263 /**
264 * Set up a div for the header to render into it.
265 *
266 * @return void
267 * @since 0.0.1
268 */
269 public static function embed_page_header() {
270 $screen = get_current_screen();
271 $screen_id = $screen ? $screen->id : '';
272
273 if ( 'edit-' . SRFM_FORMS_POST_TYPE === $screen_id || 'sureforms_page_' . SRFM_ENTRIES === $screen_id ) {
274 ?>
275 <style>
276 .srfm-page-header {
277 min-height: 65px;
278 @media screen and ( max-width: 600px ) {
279 padding-top: 46px;
280 }
281 }
282 </style>
283 <div id="srfm-page-header" class="srfm-page-header">
284 <div class="srfm-page-pre-nav-content"></div>
285 </div>
286 <?php
287 }
288 }
289
290 /**
291 * Registers the sureforms metas.
292 *
293 * @return void
294 * @since 0.0.1
295 */
296 public function register_post_metas() {
297 $check_icon = 'data:image/svg+xml;base64,' . base64_encode( strval( file_get_contents( plugin_dir_path( SRFM_FILE ) . 'images/check-icon.svg' ) ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
298
299 $metas = apply_filters(
300 'srfm_register_post_meta',
301 [
302 // General tab metas.
303 '_srfm_use_label_as_placeholder' => 'boolean',
304 '_srfm_submit_button_text' => 'string',
305 '_srfm_is_inline_button' => 'boolean',
306 // Submit Button.
307 '_srfm_submit_width_backend' => 'string',
308 '_srfm_button_border_radius' => 'integer',
309 '_srfm_submit_alignment' => 'string',
310 '_srfm_submit_alignment_backend' => 'string',
311 '_srfm_submit_width' => 'string',
312 '_srfm_inherit_theme_button' => 'boolean',
313 // Additional Classes.
314 '_srfm_additional_classes' => 'string',
315
316 // Advanced tab metas.
317 // Success Message.
318 '_srfm_submit_type' => 'string',
319 // Security.
320 '_srfm_captcha_security_type' => 'string',
321 '_srfm_form_recaptcha' => 'string',
322 ]
323 );
324
325 // Form Custom CSS meta.
326 register_post_meta(
327 'sureforms_form',
328 '_srfm_form_custom_css',
329 [
330 'show_in_rest' => true,
331 'type' => 'string',
332 'single' => true,
333 'auth_callback' => static function() {
334 return current_user_can( 'edit_posts' );
335 },
336 'sanitize_callback' => static function( $meta_value ) {
337 return wp_kses_post( $meta_value );
338 },
339 ]
340 );
341
342 foreach ( $metas as $meta => $type ) {
343 register_meta(
344 'post',
345 $meta,
346 [
347 'object_subtype' => SRFM_FORMS_POST_TYPE,
348 'show_in_rest' => true,
349 'single' => true,
350 'type' => $type,
351 'sanitize_callback' => 'sanitize_text_field',
352 'auth_callback' => static function() {
353 return current_user_can( 'edit_posts' );
354 },
355 ]
356 );
357 }
358
359 // Registers meta to handle values associated with form styling.
360 register_post_meta(
361 SRFM_FORMS_POST_TYPE,
362 '_srfm_instant_form_settings',
363 [
364 'single' => true,
365 'type' => 'object',
366 'auth_callback' => '__return_true',
367 'show_in_rest' => [
368 'schema' => [
369 'type' => 'object',
370 'properties' => [
371 'site_logo' => [
372 'type' => 'string',
373 ],
374 'site_logo_id' => [
375 'type' => 'integer',
376 ],
377 // Form page banner settings.
378 'cover_type' => [
379 'type' => 'string',
380 ],
381 'cover_color' => [
382 'type' => 'string',
383 ],
384 'cover_image' => [
385 'type' => 'string',
386 ],
387 'cover_image_id' => [
388 'type' => 'integer',
389 ],
390 // Form page background settings.
391 'bg_type' => [
392 'type' => 'string',
393 ],
394 'bg_color' => [
395 'type' => 'string',
396 ],
397 'bg_image' => [
398 'type' => 'string',
399 ],
400 'bg_image_id' => [
401 'type' => 'integer',
402 ],
403 'enable_instant_form' => [
404 'type' => 'boolean',
405 ],
406 'form_container_width' => [
407 'type' => 'integer',
408 ],
409 'single_page_form_title' => [
410 'type' => 'boolean',
411 ],
412 'use_banner_as_page_background' => [
413 'type' => 'boolean',
414 ],
415 ],
416 ],
417 ],
418 'default' => [
419 'bg_type' => 'color',
420 'bg_color' => '#ffffff',
421 'bg_image' => '',
422 'site_logo' => '',
423 'cover_type' => 'color',
424 'cover_color' => '#0C78FB',
425 'cover_image' => '',
426 'enable_instant_form' => false,
427 'form_container_width' => 620,
428 'single_page_form_title' => true,
429 'use_banner_as_page_background' => false,
430 ],
431 ]
432 );
433
434 register_post_meta(
435 SRFM_FORMS_POST_TYPE,
436 '_srfm_forms_styling',
437 [
438 'single' => true,
439 'type' => 'object',
440 'auth_callback' => '__return_true',
441 'show_in_rest' => [
442 'schema' => [
443 'type' => 'object',
444 'properties' => [
445 'primary_color' => [
446 'type' => 'string',
447 ],
448 'text_color' => [
449 'type' => 'string',
450 ],
451 'text_color_on_primary' => [
452 'type' => 'string',
453 ],
454 'field_spacing' => [
455 'type' => 'string',
456 ],
457 'submit_button_alignment' => [
458 'type' => 'string',
459 ],
460 ],
461 ],
462 ],
463 'default' => [
464 'primary_color' => '#0C78FB',
465 'text_color' => '#1E1E1E',
466 'text_color_on_primary' => '#FFFFFF',
467 'field_spacing' => 'medium',
468 'submit_button_alignment' => 'left',
469 ],
470 ]
471 );
472
473 // Email notification Metas.
474 register_post_meta(
475 'sureforms_form',
476 '_srfm_email_notification',
477 [
478 'single' => true,
479 'type' => 'array',
480 'auth_callback' => '__return_true',
481 'show_in_rest' => [
482 'schema' => [
483 'type' => 'array',
484 'items' => [
485 'type' => 'object',
486 'properties' => [
487 'id' => [
488 'type' => 'integer',
489 ],
490 'status' => [
491 'type' => 'boolean',
492 ],
493 'is_raw_format' => [
494 'type' => 'boolean',
495 ],
496 'name' => [
497 'type' => 'string',
498 ],
499 'email_to' => [
500 'type' => 'string',
501 ],
502 'email_reply_to' => [
503 'type' => 'string',
504 ],
505 'email_cc' => [
506 'type' => 'string',
507 ],
508 'email_bcc' => [
509 'type' => 'string',
510 ],
511 'subject' => [
512 'type' => 'string',
513 ],
514 'email_body' => [
515 'type' => 'string',
516 ],
517 ],
518 ],
519 ],
520 ],
521 'default' => [
522 [
523 'id' => 1,
524 'status' => true,
525 'is_raw_format' => false,
526 'name' => __( 'Admin Notification Email', 'sureforms' ),
527 'email_to' => '{admin_email}',
528 'email_reply_to' => '{admin_email}',
529 'email_cc' => '{admin_email}',
530 'email_bcc' => '{admin_email}',
531 'subject' => sprintf( /* translators: %s: Form title smart tag */ __( 'New Form Submission - %s', 'sureforms' ), '{form_title}' ),
532 'email_body' => '{all_data}',
533 ],
534 ],
535 ]
536 );
537
538 // Compliance Settings metas.
539 register_post_meta(
540 'sureforms_form',
541 '_srfm_compliance',
542 [
543 'single' => true,
544 'type' => 'array',
545 'auth_callback' => '__return_true',
546 'show_in_rest' => [
547 'schema' => [
548 'type' => 'array',
549 'items' => [
550 'type' => 'object',
551 'properties' => [
552 'id' => [
553 'type' => 'string',
554 ],
555 'gdpr' => [
556 'type' => 'boolean',
557 ],
558 'do_not_store_entries' => [
559 'type' => 'boolean',
560 ],
561 'auto_delete_entries' => [
562 'type' => 'boolean',
563 ],
564 'auto_delete_days' => [
565 'type' => 'string',
566 ],
567 ],
568 ],
569 ],
570 ],
571 'default' => [
572 [
573 'id' => 'gdpr',
574 'gdpr' => false,
575 'do_not_store_entries' => false,
576 'auto_delete_entries' => false,
577 'auto_delete_days' => '',
578 ],
579 ],
580 ]
581 );
582
583 // form confirmation.
584 register_post_meta(
585 'sureforms_form',
586 '_srfm_form_confirmation',
587 [
588 'single' => true,
589 'type' => 'array',
590 'auth_callback' => '__return_true',
591 'show_in_rest' => [
592 'schema' => [
593 'type' => 'array',
594 'items' => [
595 'type' => 'object',
596 'properties' => [
597 'id' => [
598 'type' => 'integer',
599 ],
600 'confirmation_type' => [
601 'type' => 'string',
602 ],
603 'page_url' => [
604 'type' => 'string',
605 ],
606 'custom_url' => [
607 'type' => 'string',
608 ],
609 'message' => [
610 'type' => 'string',
611 ],
612 'submission_action' => [
613 'type' => 'string',
614 ],
615 'enable_query_params' => [
616 'type' => 'boolean',
617 ],
618 'query_params' => [
619 'type' => 'array',
620 ],
621 ],
622 ],
623 ],
624 ],
625 'default' => [
626 [
627 'id' => 1,
628 'confirmation_type' => 'same page',
629 'page_url' => '',
630 'custom_url' => '',
631 'message' => '<p style="text-align: center;"><img src="' . esc_attr( $check_icon ) . '" alt="" aria-hidden="true"></img></p><h2 style="text-align: center;">Thank you</h2><p style="text-align: center;">We have received your email. You\'ll hear from us as soon as possible.</p><p style="text-align: center;">Please be sure to whitelist our {admin_email} email address to ensure our replies reach your inbox safely.</p>',
632 'submission_action' => 'hide form',
633 ],
634 ],
635 ]
636 );
637
638 // conditional logic.
639 do_action( 'srfm_register_conditional_logic_post_meta' );
640 /**
641 * Hook for registering additional Post Meta
642 */
643 do_action( 'srfm_register_additional_post_meta' );
644 }
645
646 /**
647 * Custom Shortcode.
648 *
649 * @param array<mixed> $atts Attributes.
650 * @return string|false. $content Post Content.
651 * @since 0.0.1
652 */
653 public function forms_shortcode( array $atts ) {
654 $atts = shortcode_atts(
655 [
656 'id' => '',
657 'show_title' => true,
658 ],
659 $atts
660 );
661
662 $id = intval( $atts['id'] );
663 $post = get_post( $id );
664
665 if ( ! empty( $id ) && $post ) {
666 return Generate_Form_Markup::get_form_markup( $id, ! filter_var( $atts['show_title'], FILTER_VALIDATE_BOOLEAN ), '', 'post', true );
667 }
668
669 return '';
670 }
671
672 /**
673 * Add custom column header.
674 *
675 * @param array<mixed> $columns Attributes.
676 * @return array<mixed> $columns Post Content.
677 * @since 0.0.1
678 */
679 public function custom_form_columns( $columns ) {
680 return [
681 'cb' => $columns['cb'],
682 'title' => $columns['title'],
683 'sureforms' => __( 'Shortcode', 'sureforms' ),
684 'entries' => __( 'Entries', 'sureforms' ),
685 'author' => $columns['author'],
686 'date' => $columns['date'],
687 ];
688 }
689
690 /**
691 * Populate custom column with data.
692 *
693 * @param string $column Attributes.
694 * @param int $post_id Attributes.
695 * @return void
696 * @since 0.0.1
697 */
698 public function custom_form_column_data( $column, $post_id ) {
699 if ( 'sureforms' === $column ) {
700 ob_start();
701 ?>
702 <div class="srfm-shortcode-container">
703 <input id="srfm-shortcode-input-<?php echo esc_attr( Helper::get_string_value( $post_id ) ); ?>" class="srfm-shortcode-input" type="text" readonly value="[sureforms id='<?php echo esc_attr( Helper::get_string_value( $post_id ) ); ?>']" />
704 <button type="button" class="components-button components-clipboard-button has-icon srfm-shortcode" onclick="handleFormShortcode(this)">
705 <span id="srfm-copy-icon" class="dashicon dashicons dashicons-admin-page"></span>
706 </button>
707 </div>
708 <?php
709 ob_end_flush();
710 }
711 if ( 'entries' === $column ) {
712 // Entries URL to redirect user based on the form ID.
713 $entries_url = wp_nonce_url(
714 add_query_arg(
715 [
716 'form_filter' => $post_id,
717 ],
718 admin_url( 'admin.php?page=sureforms_entries' )
719 ),
720 'srfm_entries_action'
721 );
722
723 // Get the entry count for the form.
724 $entries_count = Entries::get_total_entries_by_status( 'all', $post_id );
725
726 ob_start();
727 ?>
728 <p class="srfm-entries-number"><a href="<?php echo esc_url( $entries_url ); ?>"><?php echo esc_html( Helper::get_string_value( $entries_count ) ); ?></a></p>
729 <?php
730 ob_end_flush();
731 }
732 }
733
734 /**
735 * Show the import form popup
736 *
737 * @since 0.0.1
738 * @return void
739 */
740 public function import_form_popup() {
741 $screen = get_current_screen();
742 $id = $screen ? $screen->id : '';
743 if ( 'edit-sureforms_form' === $id ) {
744 ?>
745 <div class="srfm-import-plugin-wrap">
746 <div class="srfm-import-wrap">
747 <p class="srfm-import-help"><?php echo esc_html__( 'Please choose the SureForms export file (.json) that you wish to import.', 'sureforms' ); ?></p>
748 <form method="post" enctype="multipart/form-data" class="srfm-import-form">
749 <input type="file" id="srfm-import-file" onchange="handleFileChange(event)" name="import form" accept=".json">
750 <input type="submit" name="import-form-submit" id="import-form-submit" class="srfm-import-button" value="<?php esc_attr_e( 'Import Now', 'sureforms' ); ?>" disabled>
751 </form>
752 <p id="srfm-import-error"><?php echo esc_html__( 'There is some error in json file, please export the SureForms Forms again.', 'sureforms' ); ?></p>
753 </div>
754 </div>
755 <?php
756 }
757 }
758
759 /**
760 * Redirect to home page if instant form is not enabled.
761 *
762 * @since 0.0.1
763 * @return void
764 */
765 public function srfm_instant_form_redirect() {
766
767 $form_id = Helper::get_integer_value( get_the_ID() );
768
769 $instant_form_settings = Helper::get_array_value( Helper::get_post_meta( $form_id, '_srfm_instant_form_settings' ) );
770 $enable_instant_form = ! empty( $instant_form_settings['enable_instant_form'] ) ? boolval( $instant_form_settings['enable_instant_form'] ) : false;
771
772 if ( $enable_instant_form ) {
773 return;
774 }
775
776 $form_preview = '';
777
778 $form_preview_attr = isset( $_GET['preview'] ) ? sanitize_text_field( wp_unslash( $_GET['preview'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Nonce verification is not needed here.
779
780 if ( $form_preview_attr ) {
781 $form_preview = filter_var( $form_preview_attr, FILTER_VALIDATE_BOOLEAN );
782 }
783
784 if ( is_singular( 'sureforms_form' ) && ! $form_preview && ! current_user_can( 'manage_options' ) ) {
785 wp_safe_redirect( home_url() );
786 return;
787 }
788 }
789
790 /**
791 * Restrict RankMath meta boxes in edit page.
792 *
793 * @since 0.0.5
794 * @return void
795 */
796 public function restrict_data() {
797 add_filter( 'rank_math/excluded_post_types', [ $this, 'unset_sureforms_post_type' ] );
798 }
799
800 /**
801 * Remove SureForms post type from RankMath and Yoast.
802 *
803 * @param array<mixed> $post_types Post types.
804 * @since 0.0.5
805 * @return array<mixed> $post_types Modified post types.
806 */
807 public function unset_sureforms_post_type( $post_types ) {
808 return array_filter(
809 $post_types,
810 static function( $post_type ) {
811 if ( is_array( $post_type ) && isset( $post_type['name'] ) ) {
812 return SRFM_FORMS_POST_TYPE !== $post_type['name'];
813 }
814 return SRFM_FORMS_POST_TYPE !== $post_type;
815 }
816 );
817 }
818
819 /**
820 * Restrict interference of other plugins with SureForms.
821 *
822 * @since 0.0.5
823 * @return void
824 */
825 private function restrict_unwanted_insertions() {
826 // Restrict RankMath metaboxes in edit page.
827 add_action( 'cmb2_admin_init', [ $this, 'restrict_data' ] );
828
829 // Restrict Yoast columns.
830 add_filter( 'wpseo_accessible_post_types', [ $this, 'unset_sureforms_post_type' ] );
831 add_filter( 'wpseo_metabox_prio', '__return_false' );
832
833 // Restrict AIOSEO columns.
834 add_filter( 'aioseo_public_post_types', [ $this, 'unset_sureforms_post_type' ] );
835 }
836 }
837