PluginProbe
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 1.0.1
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v1.0.1
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 in SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz 1.0.1, at inc/post-types.php

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