PluginProbe
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 0.0.13
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v0.0.13
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 / admin / admin.php

admin.php in SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz 0.0.13, at admin/admin.php

749 lines 25.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Admin Class.
4 *
5 * @package sureforms.
6 */
7
8 namespace SRFM\Admin;
9
10 use SRFM\Inc\Traits\Get_Instance;
11 use SRFM\Inc\AI_Form_Builder\AI_Helper;
12 use SRFM\Inc\Helper;
13 use SRFM\Admin\Views\Single_Entry;
14 use SRFM\Admin\Views\Entries_List_Table;
15 use SRFM\Inc\Post_Types;
16 use SRFM\Inc\Database\Tables\Entries;
17
18 if ( ! defined( 'ABSPATH' ) ) {
19 exit; // Exit if accessed directly.
20 }
21 /**
22 * Admin handler class.
23 *
24 * @since 0.0.1
25 */
26 class Admin {
27
28 use Get_Instance;
29
30 /**
31 * Class constructor.
32 *
33 * @return void
34 * @since 0.0.1
35 */
36 public function __construct() {
37 add_action( 'admin_menu', [ $this, 'add_menu_page' ], 9 );
38 add_action( 'admin_enqueue_scripts', [ $this, 'enqueue_scripts' ] );
39 add_action( 'admin_menu', [ $this, 'settings_page' ] );
40 add_action( 'admin_menu', [ $this, 'add_new_form' ] );
41 add_filter( 'plugin_action_links', [ $this, 'add_settings_link' ], 10, 2 );
42 add_action( 'enqueue_block_assets', [ $this, 'enqueue_styles' ] );
43 add_action( 'admin_head', [ $this, 'enqueue_header_styles' ] );
44 add_action( 'admin_body_class', [ $this, 'admin_template_picker_body_class' ] );
45
46 // this action is used to restrict Spectra's quick action bar on SureForms CPTS.
47 add_action( 'uag_enable_quick_action_sidebar', [ $this, 'restrict_spectra_quick_action_bar' ] );
48
49 add_action( 'current_screen', [ $this, 'enable_gutenberg_for_sureforms' ], 100 );
50
51 // Handle entry actions.
52 add_action( 'admin_init', [ $this, 'handle_entry_actions' ] );
53 add_action( 'admin_notices', [ $this, 'entries_migration_notice' ] );
54 add_action( 'admin_notices', [ Entries_List_Table::class, 'display_bulk_action_notice' ] );
55 }
56
57 /**
58 * Print notice to inform users about entries database migration.
59 *
60 * @since 0.0.13
61 * @return void
62 */
63 public function entries_migration_notice() {
64 if ( get_option( 'srfm_dismiss_entries_migration_notice', false ) ) {
65 return;
66 }
67
68 if ( empty( get_posts( [ 'post_type' => SRFM_ENTRIES_POST_TYPE ] ) ) ) {
69 // Bail if we don't have legacy post type entries.
70 return;
71 }
72
73 $ajaxurl = add_query_arg(
74 [
75 'action' => 'sureforms_dismiss_plugin_notice',
76 'security' => wp_create_nonce( 'srfm_notice_dismiss_nonce' ),
77 ],
78 admin_url( 'admin-ajax.php' )
79 );
80 ?>
81 <!-- Adding this internal style to maintain notice styling without worrying about conditional loading of the css files. -->
82 <style>
83 .srfm-plugin-notice-container {
84 display: flex;
85 align-items: center;
86 gap: 20px;
87 padding: 10px 0;
88 }
89 .srfm-plugin-notice--logo svg {
90 width: 60px;
91 height: 60px;
92 }
93 .srfm-plugin-notice--content .srfm-plugin-notice--title {
94 margin: 0;
95 font-size: 20px;
96 line-height: 1.5;
97 }
98 .srfm-plugin-notice--content .srfm-plugin-notice--message {
99 margin-top: 4px;
100 padding: 0;
101 }
102 </style>
103 <div class="notice notice-warning is-dismissible srfm-plugin-notice">
104 <div class="srfm-plugin-notice-container">
105 <div class="srfm-plugin-notice--logo">
106 <svg width="500" height="500" viewBox="0 0 500 500" fill="none" xmlns="http://www.w3.org/2000/svg">
107 <path fill-rule="evenodd" clip-rule="evenodd" d="M250 500C388.072 500 500 388.071 500 250C500 111.929 388.072 0 250 0C111.929 0 0 111.929 0 250C0 388.071 111.929 500 250 500ZM251.076 125C231.002 125 203.224 136.48 189.028 150.641L150.477 189.103H342.635L406.887 125H251.076ZM310.648 349.359C296.454 363.52 268.673 375 248.599 375H92.7892L157.043 310.897H349.199L310.648 349.359ZM373.1 221.154H118.42L106.39 233.173C77.9043 258.814 86.3526 278.846 126.246 278.846H381.615L393.649 266.827C421.859 241.336 412.993 221.154 373.1 221.154Z" fill="#D54407"/>
108 </svg>
109 </div>
110 <div class="srfm-plugin-notice--content">
111 <h3 class="srfm-plugin-notice--title"><?php esc_html_e( 'SureForms - Important Update Notice', 'sureforms' ); ?></h3>
112 <p class="srfm-plugin-notice--message"><strong><?php esc_html_e( "From version 0.0.13 we're migrating to a custom database to enhance SureForms' performance and features.", 'sureforms' ); ?></strong></p>
113 <p class="srfm-plugin-notice--message"><?php esc_html_e( 'This step is necessary and irreversible and your current existing entries will be lost. Thank you for your understanding!', 'sureforms' ); ?></p>
114 </div>
115 </div>
116 </div>
117 <script>
118 (function() {
119 window.addEventListener('load', function() {
120 const dismissNotice = document.querySelector('.is-dismissible.srfm-plugin-notice .notice-dismiss');
121
122 dismissNotice.addEventListener('click', function() {
123 fetch('<?php echo esc_url_raw( $ajaxurl ); ?>');
124 });
125 });
126 }());
127 </script>
128 <?php
129 }
130
131 /**
132 * Enable Gutenberg for SureForms associated post types.
133 *
134 * @since 0.0.10
135 */
136 public function enable_gutenberg_for_sureforms() {
137
138 // Check if the Classic Editor plugin is active and if it is set to replace the block editor.
139 if ( ! class_exists( 'Classic_Editor' ) || 'block' === get_option( 'classic-editor-replace' ) ) {
140 return;
141 }
142
143 $srfm_post_types = apply_filters( 'srfm_enable_gutenberg_post_types', [ SRFM_FORMS_POST_TYPE ] );
144
145 if ( in_array( get_current_screen()->post_type, $srfm_post_types, true ) ) {
146 add_filter( 'use_block_editor_for_post_type', '__return_true', 110 );
147 add_filter( 'gutenberg_can_edit_post_type', '__return_true', 110 );
148 }
149 }
150
151
152 /**
153 * Sureforms editor header styles.
154 *
155 * @since 0.0.1
156 */
157 public function enqueue_header_styles() {
158 $current_screen = get_current_screen();
159 $file_prefix = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? '' : '.min';
160 $dir_name = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? 'unminified' : 'minified';
161
162 $css_uri = SRFM_URL . 'assets/css/' . $dir_name . '/';
163
164 /* RTL */
165 if ( is_rtl() ) {
166 $file_prefix .= '-rtl';
167 }
168
169 if ( 'sureforms_form' === $current_screen->id ) {
170 wp_enqueue_style( SRFM_SLUG . '-editor-header-styles', $css_uri . 'header-styles' . $file_prefix . '.css', [], SRFM_VER );
171 }
172 }
173
174 /**
175 * Add menu page.
176 *
177 * @return void
178 * @since 0.0.1
179 */
180 public function add_menu_page() {
181 if ( ! current_user_can( 'manage_options' ) ) {
182 return;
183 }
184
185 $capability = 'manage_options';
186 $menu_slug = 'sureforms_menu';
187
188 $logo = file_get_contents( plugin_dir_path( SRFM_FILE ) . 'images/icon.svg' );
189 add_menu_page(
190 __( 'SureForms', 'sureforms' ),
191 __( 'SureForms', 'sureforms' ),
192 'edit_others_posts',
193 $menu_slug,
194 function () {},
195 'data:image/svg+xml;base64,' . base64_encode( $logo ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
196 30
197 );
198
199 // Add the Dashboard Submenu.
200 add_submenu_page(
201 $menu_slug,
202 __( 'Dashboard', 'sureforms' ),
203 __( 'Dashboard', 'sureforms' ),
204 $capability,
205 $menu_slug,
206 [ $this, 'render_dashboard' ]
207 );
208 }
209
210 /**
211 * Add Settings page.
212 *
213 * @return void
214 * @since 0.0.1
215 */
216 public function settings_page() {
217 $callback = [ $this, 'settings_page_callback' ];
218 add_submenu_page(
219 'sureforms_menu',
220 __( 'Settings', 'sureforms' ),
221 __( 'Settings', 'sureforms' ),
222 'edit_others_posts',
223 'sureforms_form_settings',
224 $callback
225 );
226
227 // Get the current submenu page.
228 $submenu_page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- $_GET['page'] does not provide nonce.
229
230 if ( ! isset( $_GET['tab'] ) && 'sureforms_form_settings' === $submenu_page ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- $_GET['page'] does not provide nonce.
231 wp_safe_redirect( admin_url( 'admin.php?page=sureforms_form_settings&tab=general-settings' ) );
232 exit;
233 }
234 }
235
236 /**
237 * Render Admin Dashboard.
238 *
239 * @return void
240 * @since 0.0.1
241 */
242 public function render_dashboard() {
243 echo '<div id="srfm-dashboard-container"></div>';
244 }
245
246 /**
247 * Settings page callback.
248 *
249 * @return void
250 * @since 0.0.1
251 */
252 public function settings_page_callback() {
253 echo '<div id="srfm-settings-container"></div>';
254 }
255
256 /**
257 * Add new form menu item.
258 *
259 * @return void
260 * @since 0.0.1
261 */
262 public function add_new_form() {
263 add_submenu_page(
264 'sureforms_menu',
265 __( 'New Form', 'sureforms' ),
266 __( 'New Form', 'sureforms' ),
267 'edit_others_posts',
268 'add-new-form',
269 [ $this, 'add_new_form_callback' ],
270 2
271 );
272 add_submenu_page(
273 'sureforms_menu',
274 __( 'Entries', 'sureforms' ),
275 __( 'Entries', 'sureforms' ),
276 'edit_others_posts',
277 'sureforms_entries',
278 [ $this, 'render_entries' ],
279 3
280 );
281 }
282
283 /**
284 * Add new form mentu item callback.
285 *
286 * @return void
287 * @since 0.0.1
288 */
289 public function add_new_form_callback() {
290 echo '<div id="srfm-add-new-form-container"></div>';
291 }
292
293 /**
294 * Entries page callback.
295 *
296 * @since 0.0.13
297 * @return void
298 */
299 public function render_entries() {
300 // Render single entry view.
301 // Adding the phpcs ignore nonce verification as no database operations are performed in this function, it is used to display the single entry view.
302 if ( isset( $_GET['entry_id'] ) && is_numeric( $_GET['entry_id'] ) && isset( $_GET['view'] ) && 'details' === $_GET['view'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
303 $single_entry_view = new Single_Entry();
304 $single_entry_view->render();
305 return;
306 }
307
308 // Render all entries view.
309 $entries_table = new Entries_List_Table();
310 $entries_table->prepare_items();
311 echo '<div class="wrap"><h1 class="wp-heading-inline">Entries</h1>';
312 if ( 0 >= $entries_table->all_entries_count && 0 >= $entries_table->trash_count ) {
313 $instance = Post_Types::get_instance();
314 $instance->sureforms_render_blank_state( SRFM_ENTRIES_POST_TYPE );
315 $instance->get_blank_state_styles();
316 return;
317 }
318 echo '<form method="get">';
319 echo '<input type="hidden" name="page" value="sureforms_entries">';
320 $entries_table->display();
321 echo '</form>';
322 echo '</div>';
323 }
324
325 /**
326 * Adds a settings link to the plugin action links on the plugins page.
327 *
328 * @param array $links An array of plugin action links.
329 * @param string $file The plugin file path.
330 * @return array The updated array of plugin action links.
331 * @since 0.0.1
332 */
333 public function add_settings_link( $links, $file ) {
334 if ( 'sureforms/sureforms.php' === $file ) {
335 $plugin_links = apply_filters(
336 'sureforms_plugin_action_links',
337 [
338 'sureforms_settings' => '<a href="' . esc_url( admin_url( 'admin.php?page=sureforms_form_settings&tab=general-settings' ) ) . '">' . esc_html__( 'Settings', 'sureforms' ) . '</a>',
339 ]
340 );
341 $links = array_merge( $plugin_links, $links );
342 }
343 return $links;
344 }
345
346 /**
347 * Sureforms block editor styles.
348 *
349 * @since 0.0.1
350 */
351 public function enqueue_styles() {
352 $current_screen = get_current_screen();
353
354 $file_prefix = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? '' : '.min';
355 $dir_name = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? 'unminified' : 'minified';
356
357 $css_uri = SRFM_URL . 'assets/css/' . $dir_name . '/';
358 $vendor_css_uri = SRFM_URL . 'assets/css/minified/deps/';
359
360 /* RTL */
361 if ( is_rtl() ) {
362 $file_prefix .= '-rtl';
363 }
364
365 // Enqueue editor styles for post and page.
366 if ( SRFM_FORMS_POST_TYPE === $current_screen->post_type ) {
367 wp_enqueue_style( SRFM_SLUG . '-editor', $css_uri . 'backend/editor' . $file_prefix . '.css', [], SRFM_VER );
368 wp_enqueue_style( SRFM_SLUG . '-backend-blocks', $css_uri . 'blocks/default/backend' . $file_prefix . '.css', [], SRFM_VER );
369 wp_enqueue_style( SRFM_SLUG . '-intl', $vendor_css_uri . 'intl/intlTelInput-backend.min.css', [], SRFM_VER );
370 wp_enqueue_style( SRFM_SLUG . '-common', $css_uri . 'common' . $file_prefix . '.css', [], SRFM_VER );
371 wp_enqueue_style( SRFM_SLUG . '-reactQuill', $vendor_css_uri . 'quill/quill.snow.css', [], SRFM_VER );
372 wp_enqueue_style( SRFM_SLUG . '-single-form-modal', $css_uri . 'single-form-setting' . $file_prefix . '.css', [], SRFM_VER );
373 }
374
375 wp_enqueue_style( SRFM_SLUG . '-form-selector', $css_uri . 'srfm-form-selector' . $file_prefix . '.css', [], SRFM_VER );
376 wp_enqueue_style( SRFM_SLUG . '-common-editor', SRFM_URL . 'assets/build/common-editor.css', [], SRFM_VER, 'all' );
377 }
378
379 /**
380 * Get Breadcrumbs for current page.
381 *
382 * @since 0.0.1
383 * @return array Breadcrumbs Array.
384 */
385 public function get_breadcrumbs_for_current_page() {
386 global $post, $pagenow;
387 $breadcrumbs = [];
388
389 if ( 'admin.php' === $pagenow && isset( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
390 $page_title = get_admin_page_title();
391 $breadcrumbs[] = [
392 'title' => $page_title,
393 'link' => '',
394 ];
395 } elseif ( $post && in_array( $pagenow, [ 'post.php', 'post-new.php', 'edit.php' ], true ) ) {
396 $post_type_obj = get_post_type_object( get_post_type() );
397 if ( $post_type_obj ) {
398 $post_type_plural = $post_type_obj->labels->name;
399 $breadcrumbs[] = [
400 'title' => $post_type_plural,
401 'link' => admin_url( 'edit.php?post_type=' . $post_type_obj->name ),
402 ];
403
404 if ( 'edit.php' === $pagenow && ! isset( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
405 $breadcrumbs[ count( $breadcrumbs ) - 1 ]['link'] = '';
406 } else {
407 $breadcrumbs[] = [
408 /* Translators: Post Title. */
409 'title' => sprintf( __( 'Edit %1$s', 'sureforms' ), get_the_title() ),
410 'link' => get_edit_post_link( $post->ID ),
411 ];
412 }
413 }
414 } else {
415 $current_screen = get_current_screen();
416 if ( $current_screen && 'sureforms_form' === $current_screen->post_type ) {
417 $breadcrumbs[] = [
418 'title' => 'Forms',
419 'link' => '',
420 ];
421 } elseif ( $current_screen && 'sureforms_entry' === $current_screen->post_type ) {
422 $breadcrumbs[] = [
423 'title' => 'Entries',
424 'link' => '',
425 ];
426 } else {
427 $breadcrumbs[] = [
428 'title' => '',
429 'link' => '',
430 ];
431 }
432 }
433
434 return $breadcrumbs;
435 }
436
437
438 /**
439 * Enqueue Admin Scripts.
440 *
441 * @return void
442 * @since 0.0.1
443 */
444 public function enqueue_scripts() {
445 $current_screen = get_current_screen();
446
447 $file_prefix = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? '' : '.min';
448 $dir_name = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? 'unminified' : 'minified';
449 $js_uri = SRFM_URL . 'assets/js/' . $dir_name . '/';
450 $css_uri = SRFM_URL . 'assets/css/' . $dir_name . '/';
451
452 /* RTL */
453 if ( is_rtl() ) {
454 $file_prefix .= '-rtl';
455 }
456
457 $localization_data = [
458 'site_url' => get_site_url(),
459 'breadcrumbs' => $this->get_breadcrumbs_for_current_page(),
460 'sureforms_dashboard_url' => admin_url( '/admin.php?page=sureforms_menu' ),
461 'plugin_version' => SRFM_VER,
462 'global_settings_nonce' => current_user_can( 'manage_options' ) ? wp_create_nonce( 'wp_rest' ) : '',
463 'is_pro_active' => defined( 'SRFM_PRO_VER' ),
464 'pro_plugin_version' => defined( 'SRFM_PRO_VER' ) ? SRFM_PRO_VER : '',
465 'sureforms_pricing_page' => $this->get_sureforms_website_url( 'pricing' ),
466 'field_spacing_vars' => Helper::get_css_vars(),
467 ];
468
469 if ( class_exists( 'SRFM_PRO\Admin\Licensing' ) ) {
470 $license_active = \SRFM_PRO\Admin\Licensing::is_license_active();
471 $localization_data['is_license_active'] = $license_active;
472 }
473
474 if ( SRFM_FORMS_POST_TYPE === $current_screen->post_type || 'toplevel_page_sureforms_menu' === $current_screen->base || SRFM_ENTRIES_POST_TYPE === $current_screen->post_type
475 || 'sureforms_page_sureforms_form_settings' === $current_screen->id || 'sureforms_page_sureforms_entries' === $current_screen->id
476 ) {
477 $asset_handle = '-dashboard';
478
479 wp_enqueue_style( SRFM_SLUG . $asset_handle . '-font', 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500&display=swap', [], SRFM_VER );
480
481 $script_asset_path = SRFM_DIR . 'assets/build/dashboard.asset.php';
482 $script_info = file_exists( $script_asset_path )
483 ? include $script_asset_path
484 : [
485 'dependencies' => [],
486 'version' => SRFM_VER,
487 ];
488 wp_enqueue_script( SRFM_SLUG . $asset_handle, SRFM_URL . 'assets/build/dashboard.js', $script_info['dependencies'], SRFM_VER, true );
489
490 wp_localize_script( SRFM_SLUG . $asset_handle, 'scIcons', [ 'path' => SRFM_URL . 'assets/build/icon-assets' ] );
491
492 $localization_data['security_settings_url'] = admin_url( '/admin.php?page=sureforms_form_settings&tab=security-settings' );
493 wp_localize_script(
494 SRFM_SLUG . $asset_handle,
495 SRFM_SLUG . '_admin',
496 apply_filters(
497 SRFM_SLUG . '_admin_filter',
498 $localization_data
499 )
500 );
501 wp_enqueue_style( SRFM_SLUG . '-dashboard', SRFM_URL . 'assets/build/dashboard.css', [], SRFM_VER, 'all' );
502
503 }
504
505 if ( 'sureforms_page_sureforms_form_settings' === $current_screen->id ) {
506 wp_enqueue_style( SRFM_SLUG . '-settings', $css_uri . 'backend/settings' . $file_prefix . '.css', [], SRFM_VER );
507 }
508
509 // Enqueue styles for the entries page.
510 if ( 'sureforms_page_sureforms_entries' === $current_screen->id ) {
511 $asset_handle = '-entries';
512 wp_enqueue_style( SRFM_SLUG . $asset_handle, $css_uri . 'backend/entries' . $file_prefix . '.css', [], SRFM_VER );
513 wp_enqueue_script( SRFM_SLUG . $asset_handle, SRFM_URL . 'assets/build/entries.js', $script_info['dependencies'], SRFM_VER, true );
514 }
515
516 // Admin Submenu Styles.
517 wp_enqueue_style( SRFM_SLUG . '-admin', $css_uri . 'backend/admin' . $file_prefix . '.css', [], SRFM_VER );
518
519 if ( 'edit-' . SRFM_FORMS_POST_TYPE === $current_screen->id || 'edit-' . SRFM_ENTRIES_POST_TYPE === $current_screen->id ) {
520 $asset_handle = 'page_header';
521
522 $script_asset_path = SRFM_DIR . 'assets/build/' . $asset_handle . '.asset.php';
523 $script_info = file_exists( $script_asset_path )
524 ? include $script_asset_path
525 : [
526 'dependencies' => [],
527 'version' => SRFM_VER,
528 ];
529 wp_enqueue_script( SRFM_SLUG . '-form-page-header', SRFM_URL . 'assets/build/' . $asset_handle . '.js', $script_info['dependencies'], SRFM_VER, true );
530 wp_enqueue_style( SRFM_SLUG . '-form-archive-styles', $css_uri . 'form-archive-styles' . $file_prefix . '.css', [], SRFM_VER );
531 }
532 if ( 'sureforms_page_' . SRFM_FORMS_POST_TYPE . '_settings' === $current_screen->base ) {
533 $asset_handle = 'settings';
534
535 $script_asset_path = SRFM_DIR . 'assets/build/' . $asset_handle . '.asset.php';
536 $script_info = file_exists( $script_asset_path )
537 ? include $script_asset_path
538 : [
539 'dependencies' => [],
540 'version' => SRFM_VER,
541 ];
542
543 wp_enqueue_script( SRFM_SLUG . '-settings', SRFM_URL . 'assets/build/' . $asset_handle . '.js', $script_info['dependencies'], SRFM_VER, true );
544 wp_enqueue_style( SRFM_SLUG . '-setting-styles', SRFM_URL . 'assets/build/' . $asset_handle . '.css', [ 'wp-components' ], SRFM_VER, 'all' );
545 wp_localize_script(
546 SRFM_SLUG . '-settings',
547 SRFM_SLUG . '_admin',
548 $localization_data
549 );
550 }
551 if ( 'edit-' . SRFM_FORMS_POST_TYPE === $current_screen->id ) {
552 wp_enqueue_script( SRFM_SLUG . '-form-archive', $js_uri . 'form-archive' . $file_prefix . '.js', [], SRFM_VER, true );
553 wp_enqueue_script( SRFM_SLUG . '-export', $js_uri . 'export' . $file_prefix . '.js', [ 'wp-i18n' ], SRFM_VER, true );
554 wp_localize_script(
555 SRFM_SLUG . '-export',
556 SRFM_SLUG . '_export',
557 [
558 'ajaxurl' => admin_url( 'admin-ajax.php' ),
559 'srfm_export_nonce' => wp_create_nonce( 'export_form_nonce' ),
560 'site_url' => get_site_url(),
561 'srfm_import_endpoint' => '/wp-json/sureforms/v1/sureforms_import',
562 'import_form_nonce' => ( current_user_can( 'edit_posts' ) ) ? wp_create_nonce( 'wp_rest' ) : '',
563 ]
564 );
565
566 wp_enqueue_script( SRFM_SLUG . '-backend', $js_uri . 'backend' . $file_prefix . '.js', [], SRFM_VER, true );
567 wp_localize_script(
568 SRFM_SLUG . '-backend',
569 SRFM_SLUG . '_backend',
570 [
571 'site_url' => get_site_url(),
572 ]
573 );
574
575 }
576
577 if ( 'sureforms_page_add-new-form' === $current_screen->id ) {
578
579 $file_prefix = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? '' : '.min';
580 $dir_name = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? 'unminified' : 'minified';
581
582 $css_uri = SRFM_URL . 'assets/css/' . $dir_name . '/';
583
584 /* RTL */
585 if ( is_rtl() ) {
586 $file_prefix .= '-rtl';
587 }
588
589 wp_enqueue_style( SRFM_SLUG . '-template-picker', $css_uri . 'template-picker' . $file_prefix . '.css', [], SRFM_VER );
590
591 $sureforms_admin = 'templatePicker';
592
593 $script_asset_path = SRFM_DIR . 'assets/build/' . $sureforms_admin . '.asset.php';
594 $script_info = file_exists( $script_asset_path )
595 ? include $script_asset_path
596 : [
597 'dependencies' => [],
598 'version' => SRFM_VER,
599 ];
600 wp_enqueue_script( SRFM_SLUG . '-template-picker', SRFM_URL . 'assets/build/' . $sureforms_admin . '.js', $script_info['dependencies'], SRFM_VER, true );
601
602 wp_localize_script(
603 SRFM_SLUG . '-template-picker',
604 SRFM_SLUG . '_admin',
605 [
606 'site_url' => get_site_url(),
607 'plugin_url' => SRFM_URL,
608 'preview_images_url' => SRFM_URL . 'images/template-previews/',
609 'admin_url' => admin_url( 'admin.php' ),
610 'new_template_picker_base_url' => admin_url( 'post-new.php?post_type=sureforms_form' ),
611 'capability' => current_user_can( 'edit_posts' ),
612 'template_picker_nonce' => current_user_can( 'edit_posts' ) ? wp_create_nonce( 'wp_rest' ) : '',
613 'is_pro_active' => defined( 'SRFM_PRO_VER' ),
614 'srfm_ai_usage_details' => AI_Helper::get_current_usage_details(),
615 'is_pro_license_active' => AI_Helper::is_pro_license_active(),
616 'srfm_ai_auth_user_email' => get_option( 'srfm_ai_auth_user_email' ),
617 'pricing_page_url' => $this->get_sureforms_website_url( 'pricing' ),
618 ]
619 );
620 }
621 // Quick action sidebar.
622 $default_allowed_quick_sidebar_blocks = apply_filters(
623 'srfm_quick_sidebar_allowed_blocks',
624 [
625 'srfm/input',
626 'srfm/email',
627 'srfm/textarea',
628 'srfm/checkbox',
629 'srfm/number',
630 'srfm/inline-button',
631 'srfm/advanced-heading',
632 ]
633 );
634 if ( ! is_array( $default_allowed_quick_sidebar_blocks ) ) {
635 $default_allowed_quick_sidebar_blocks = [];
636 }
637
638 $srfm_enable_quick_action_sidebar = get_option( 'srfm_enable_quick_action_sidebar' );
639 if ( ! $srfm_enable_quick_action_sidebar ) {
640 $srfm_enable_quick_action_sidebar = 'disabled';
641 }
642 $quick_sidebar_allowed_blocks = get_option( 'srfm_quick_sidebar_allowed_blocks' );
643 $quick_sidebar_allowed_blocks = ! empty( $quick_sidebar_allowed_blocks ) && is_array( $quick_sidebar_allowed_blocks ) ? $quick_sidebar_allowed_blocks : $default_allowed_quick_sidebar_blocks;
644 $srfm_ajax_nonce = wp_create_nonce( 'srfm_ajax_nonce' );
645 wp_enqueue_script( SRFM_SLUG . '-quick-action-siderbar', SRFM_URL . 'assets/build/quickActionSidebar.js', [], SRFM_VER, true );
646 wp_localize_script(
647 SRFM_SLUG . '-quick-action-siderbar',
648 SRFM_SLUG . '_quick_sidebar_blocks',
649 [
650 'allowed_blocks' => $quick_sidebar_allowed_blocks,
651 'srfm_enable_quick_action_sidebar' => $srfm_enable_quick_action_sidebar,
652 'srfm_ajax_nonce' => $srfm_ajax_nonce,
653 'srfm_ajax_url' => admin_url( 'admin-ajax.php' ),
654 ]
655 );
656
657 /**
658 * Enqueuing SureTriggers Integration script.
659 * This script loads suretriggers iframe in Intergations tab.
660 */
661 if ( SRFM_FORMS_POST_TYPE === $current_screen->post_type ) {
662 wp_enqueue_script( SRFM_SLUG . '-suretriggers-integration', SRFM_SURETRIGGERS_INTERGATION_BASE_URL . 'js/v2/embed.js', [], SRFM_VER, true );
663 }
664 }
665
666 /**
667 * Form Template Picker Admin Body Classes
668 *
669 * @since 0.0.1
670 * @param string $classes Space separated class string.
671 */
672 public function admin_template_picker_body_class( $classes = '' ) {
673 $theme_builder_class = isset( $_GET['page'] ) && 'add-new-form' === $_GET['page'] ? 'srfm-template-picker' : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- Fetching a $_GET value, no nonce available to validate.
674 $classes .= ' ' . $theme_builder_class . ' ';
675
676 return $classes;
677
678 }
679
680 /**
681 * Disable spectra's quick action bar in sureforms CPT.
682 *
683 * @param string $status current status of the quick action bar.
684 * @since 0.0.2
685 * @return string
686 */
687 public function restrict_spectra_quick_action_bar( $status ) {
688 $screen = get_current_screen();
689 if ( 'disabled' !== $status && isset( $screen->id ) && 'sureforms_form' === $screen->id ) {
690 $status = 'disabled';
691 }
692
693 return $status;
694 }
695
696 /**
697 * Get SureForms Website URL.
698 *
699 * @param string $trail The URL trail to append to SureForms website URL. The parameter should not include a leading slash as the base URL already ends with a trailing slash.
700 * @since 0.0.7
701 * @return string
702 */
703 public static function get_sureforms_website_url( $trail ) {
704 $url = SRFM_WEBSITE;
705 if ( ! empty( $trail ) && is_string( $trail ) ) {
706 $url = SRFM_WEBSITE . $trail;
707 }
708
709 return esc_url( $url );
710 }
711
712 // Entries methods.
713
714 /**
715 * Handle entry actions.
716 *
717 * @since 0.0.13
718 * @return void
719 */
720 public function handle_entry_actions() {
721 if ( isset( $_GET['entry'] ) && isset( $_GET['action'] ) ) {
722 Entries_List_Table::process_bulk_actions();
723 return;
724 }
725 if ( ! isset( $_GET['page'] ) || 'sureforms_entries' !== $_GET['page'] ) {
726 return;
727 }
728 if ( ! isset( $_GET['entry_id'] ) || ! isset( $_GET['action'] ) ) {
729 return;
730 }
731 if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'srfm_entries_action' ) ) {
732 wp_die( esc_html__( 'Nonce verification failed.', 'sureforms' ) );
733 }
734 $action = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : '';
735 $entry_id = Helper::get_integer_value( sanitize_text_field( wp_unslash( $_GET['entry_id'] ) ) );
736 $view = isset( $_GET['view'] ) ? sanitize_text_field( wp_unslash( $_GET['view'] ) ) : '';
737 if ( $entry_id > 0 ) {
738 if ( 'read' === $action && 'details' === $view ) {
739 $entry_status = Entries::get( $entry_id )['status'];
740 if ( 'trash' === $entry_status ) {
741 wp_die( esc_html__( 'You cannot view this entry because it is in trash.', 'sureforms' ) );
742 }
743 }
744 Entries_List_Table::handle_entry_status( $entry_id, $action, $view );
745 }
746 }
747
748 }
749