PluginProbe
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 1.0.2
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v1.0.2
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
668 lines 22.6 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', [ Entries_List_Table::class, 'display_bulk_action_notice' ] );
54 }
55
56 /**
57 * Enable Gutenberg for SureForms associated post types.
58 *
59 * @since 0.0.10
60 */
61 public function enable_gutenberg_for_sureforms() {
62
63 // Check if the Classic Editor plugin is active and if it is set to replace the block editor.
64 if ( ! class_exists( 'Classic_Editor' ) || 'block' === get_option( 'classic-editor-replace' ) ) {
65 return;
66 }
67
68 $srfm_post_types = apply_filters( 'srfm_enable_gutenberg_post_types', [ SRFM_FORMS_POST_TYPE ] );
69
70 if ( in_array( get_current_screen()->post_type, $srfm_post_types, true ) ) {
71 add_filter( 'use_block_editor_for_post_type', '__return_true', 110 );
72 add_filter( 'gutenberg_can_edit_post_type', '__return_true', 110 );
73 }
74 }
75
76
77 /**
78 * Sureforms editor header styles.
79 *
80 * @since 0.0.1
81 */
82 public function enqueue_header_styles() {
83 $current_screen = get_current_screen();
84 $file_prefix = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? '' : '.min';
85 $dir_name = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? 'unminified' : 'minified';
86
87 $css_uri = SRFM_URL . 'assets/css/' . $dir_name . '/';
88
89 /* RTL */
90 if ( is_rtl() ) {
91 $file_prefix .= '-rtl';
92 }
93
94 if ( 'sureforms_form' === $current_screen->id ) {
95 wp_enqueue_style( SRFM_SLUG . '-editor-header-styles', $css_uri . 'header-styles' . $file_prefix . '.css', [], SRFM_VER );
96 }
97 }
98
99 /**
100 * Add menu page.
101 *
102 * @return void
103 * @since 0.0.1
104 */
105 public function add_menu_page() {
106 if ( ! current_user_can( 'manage_options' ) ) {
107 return;
108 }
109
110 $capability = 'manage_options';
111 $menu_slug = 'sureforms_menu';
112
113 $logo = file_get_contents( plugin_dir_path( SRFM_FILE ) . 'images/icon.svg' );
114 add_menu_page(
115 __( 'SureForms', 'sureforms' ),
116 __( 'SureForms', 'sureforms' ),
117 'edit_others_posts',
118 $menu_slug,
119 function () {},
120 'data:image/svg+xml;base64,' . base64_encode( $logo ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
121 30
122 );
123
124 // Add the Dashboard Submenu.
125 add_submenu_page(
126 $menu_slug,
127 __( 'Dashboard', 'sureforms' ),
128 __( 'Dashboard', 'sureforms' ),
129 $capability,
130 $menu_slug,
131 [ $this, 'render_dashboard' ]
132 );
133 }
134
135 /**
136 * Add Settings page.
137 *
138 * @return void
139 * @since 0.0.1
140 */
141 public function settings_page() {
142 $callback = [ $this, 'settings_page_callback' ];
143 add_submenu_page(
144 'sureforms_menu',
145 __( 'Settings', 'sureforms' ),
146 __( 'Settings', 'sureforms' ),
147 'edit_others_posts',
148 'sureforms_form_settings',
149 $callback
150 );
151
152 // Get the current submenu page.
153 $submenu_page = isset( $_GET['page'] ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- $_GET['page'] does not provide nonce.
154
155 if ( ! isset( $_GET['tab'] ) && 'sureforms_form_settings' === $submenu_page ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- $_GET['page'] does not provide nonce.
156 wp_safe_redirect( admin_url( 'admin.php?page=sureforms_form_settings&tab=general-settings' ) );
157 exit;
158 }
159 }
160
161 /**
162 * Render Admin Dashboard.
163 *
164 * @return void
165 * @since 0.0.1
166 */
167 public function render_dashboard() {
168 echo '<div id="srfm-dashboard-container"></div>';
169 }
170
171 /**
172 * Settings page callback.
173 *
174 * @return void
175 * @since 0.0.1
176 */
177 public function settings_page_callback() {
178 echo '<div id="srfm-settings-container"></div>';
179 }
180
181 /**
182 * Add new form menu item.
183 *
184 * @return void
185 * @since 0.0.1
186 */
187 public function add_new_form() {
188 add_submenu_page(
189 'sureforms_menu',
190 __( 'New Form', 'sureforms' ),
191 __( 'New Form', 'sureforms' ),
192 'edit_others_posts',
193 'add-new-form',
194 [ $this, 'add_new_form_callback' ],
195 2
196 );
197 add_submenu_page(
198 'sureforms_menu',
199 __( 'Entries', 'sureforms' ),
200 __( 'Entries', 'sureforms' ),
201 'edit_others_posts',
202 SRFM_ENTRIES,
203 [ $this, 'render_entries' ],
204 3
205 );
206 }
207
208 /**
209 * Add new form mentu item callback.
210 *
211 * @return void
212 * @since 0.0.1
213 */
214 public function add_new_form_callback() {
215 echo '<div id="srfm-add-new-form-container"></div>';
216 }
217
218 /**
219 * Entries page callback.
220 *
221 * @since 0.0.13
222 * @return void
223 */
224 public function render_entries() {
225 // Render single entry view.
226 // Adding the phpcs ignore nonce verification as no database operations are performed in this function, it is used to display the single entry view.
227 if ( isset( $_GET['entry_id'] ) && is_numeric( $_GET['entry_id'] ) && isset( $_GET['view'] ) && 'details' === $_GET['view'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
228 $single_entry_view = new Single_Entry();
229 $single_entry_view->render();
230 return;
231 }
232
233 // Render all entries view.
234 $entries_table = new Entries_List_Table();
235 $entries_table->prepare_items();
236 echo '<div class="wrap"><h1 class="wp-heading-inline">Entries</h1>';
237 if ( empty( $entries_table->all_entries_count ) && empty( $entries_table->trash_entries_count ) ) {
238 $instance = Post_Types::get_instance();
239 $instance->sureforms_render_blank_state( SRFM_ENTRIES );
240 $instance->get_blank_state_styles();
241 return;
242 }
243 echo '<form method="get">';
244 echo '<input type="hidden" name="page" value="sureforms_entries">';
245 $entries_table->display();
246 echo '</form>';
247 echo '</div>';
248 }
249
250 /**
251 * Adds a settings link to the plugin action links on the plugins page.
252 *
253 * @param array $links An array of plugin action links.
254 * @param string $file The plugin file path.
255 * @return array The updated array of plugin action links.
256 * @since 0.0.1
257 */
258 public function add_settings_link( $links, $file ) {
259 if ( 'sureforms/sureforms.php' === $file ) {
260 $plugin_links = apply_filters(
261 'sureforms_plugin_action_links',
262 [
263 'sureforms_settings' => '<a href="' . esc_url( admin_url( 'admin.php?page=sureforms_form_settings&tab=general-settings' ) ) . '">' . esc_html__( 'Settings', 'sureforms' ) . '</a>',
264 ]
265 );
266 $links = array_merge( $plugin_links, $links );
267 }
268 return $links;
269 }
270
271 /**
272 * Sureforms block editor styles.
273 *
274 * @since 0.0.1
275 */
276 public function enqueue_styles() {
277 $current_screen = get_current_screen();
278
279 $file_prefix = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? '' : '.min';
280 $dir_name = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? 'unminified' : 'minified';
281
282 $css_uri = SRFM_URL . 'assets/css/' . $dir_name . '/';
283 $vendor_css_uri = SRFM_URL . 'assets/css/minified/deps/';
284
285 /* RTL */
286 if ( is_rtl() ) {
287 $file_prefix .= '-rtl';
288 }
289
290 // Enqueue editor styles for post and page.
291 if ( SRFM_FORMS_POST_TYPE === $current_screen->post_type ) {
292 wp_enqueue_style( SRFM_SLUG . '-editor', $css_uri . 'backend/editor' . $file_prefix . '.css', [], SRFM_VER );
293 wp_enqueue_style( SRFM_SLUG . '-backend-blocks', $css_uri . 'blocks/default/backend' . $file_prefix . '.css', [], SRFM_VER );
294 wp_enqueue_style( SRFM_SLUG . '-intl', $vendor_css_uri . 'intl/intlTelInput-backend.min.css', [], SRFM_VER );
295 wp_enqueue_style( SRFM_SLUG . '-common', $css_uri . 'common' . $file_prefix . '.css', [], SRFM_VER );
296 wp_enqueue_style( SRFM_SLUG . '-reactQuill', $vendor_css_uri . 'quill/quill.snow.css', [], SRFM_VER );
297 wp_enqueue_style( SRFM_SLUG . '-single-form-modal', $css_uri . 'single-form-setting' . $file_prefix . '.css', [], SRFM_VER );
298 }
299
300 wp_enqueue_style( SRFM_SLUG . '-form-selector', $css_uri . 'srfm-form-selector' . $file_prefix . '.css', [], SRFM_VER );
301 wp_enqueue_style( SRFM_SLUG . '-common-editor', SRFM_URL . 'assets/build/common-editor.css', [], SRFM_VER, 'all' );
302 }
303
304 /**
305 * Get Breadcrumbs for current page.
306 *
307 * @since 0.0.1
308 * @return array Breadcrumbs Array.
309 */
310 public function get_breadcrumbs_for_current_page() {
311 global $post, $pagenow;
312 $breadcrumbs = [];
313
314 if ( 'admin.php' === $pagenow && isset( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
315 $page_title = get_admin_page_title();
316 $breadcrumbs[] = [
317 'title' => $page_title,
318 'link' => '',
319 ];
320 } elseif ( $post && in_array( $pagenow, [ 'post.php', 'post-new.php', 'edit.php' ], true ) ) {
321 $post_type_obj = get_post_type_object( get_post_type() );
322 if ( $post_type_obj ) {
323 $post_type_plural = $post_type_obj->labels->name;
324 $breadcrumbs[] = [
325 'title' => $post_type_plural,
326 'link' => admin_url( 'edit.php?post_type=' . $post_type_obj->name ),
327 ];
328
329 if ( 'edit.php' === $pagenow && ! isset( $_GET['page'] ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
330 $breadcrumbs[ count( $breadcrumbs ) - 1 ]['link'] = '';
331 } else {
332 $breadcrumbs[] = [
333 /* Translators: Post Title. */
334 'title' => sprintf( __( 'Edit %1$s', 'sureforms' ), get_the_title() ),
335 'link' => get_edit_post_link( $post->ID ),
336 ];
337 }
338 }
339 } else {
340 $current_screen = get_current_screen();
341 if ( $current_screen && 'sureforms_form' === $current_screen->post_type ) {
342 $breadcrumbs[] = [
343 'title' => 'Forms',
344 'link' => '',
345 ];
346 } else {
347 $breadcrumbs[] = [
348 'title' => '',
349 'link' => '',
350 ];
351 }
352 }
353
354 return $breadcrumbs;
355 }
356
357
358 /**
359 * Enqueue Admin Scripts.
360 *
361 * @return void
362 * @since 0.0.1
363 */
364 public function enqueue_scripts() {
365 $current_screen = get_current_screen();
366
367 $file_prefix = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? '' : '.min';
368 $dir_name = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? 'unminified' : 'minified';
369 $js_uri = SRFM_URL . 'assets/js/' . $dir_name . '/';
370 $css_uri = SRFM_URL . 'assets/css/' . $dir_name . '/';
371
372 /* RTL */
373 if ( is_rtl() ) {
374 $file_prefix .= '-rtl';
375 }
376
377 $localization_data = [
378 'site_url' => get_site_url(),
379 'breadcrumbs' => $this->get_breadcrumbs_for_current_page(),
380 'sureforms_dashboard_url' => admin_url( '/admin.php?page=sureforms_menu' ),
381 'plugin_version' => SRFM_VER,
382 'global_settings_nonce' => current_user_can( 'manage_options' ) ? wp_create_nonce( 'wp_rest' ) : '',
383 'is_pro_active' => defined( 'SRFM_PRO_VER' ),
384 'pro_plugin_version' => defined( 'SRFM_PRO_VER' ) ? SRFM_PRO_VER : '',
385 'pro_plugin_name' => defined( 'SRFM_PRO_VER' ) && defined( 'SRFM_PRO_PRODUCT' ) ? SRFM_PRO_PRODUCT : 'SureForms Pro',
386 'sureforms_pricing_page' => $this->get_sureforms_website_url( 'pricing' ),
387 'field_spacing_vars' => Helper::get_css_vars(),
388 ];
389
390 if ( class_exists( 'SRFM_PRO\Admin\Licensing' ) ) {
391 $license_active = \SRFM_PRO\Admin\Licensing::is_license_active();
392 $localization_data['is_license_active'] = $license_active;
393 }
394
395 if ( SRFM_FORMS_POST_TYPE === $current_screen->post_type || 'toplevel_page_sureforms_menu' === $current_screen->base || 'sureforms_page_sureforms_form_settings' === $current_screen->id || 'sureforms_page_' . SRFM_ENTRIES === $current_screen->id ) {
396 $asset_handle = '-dashboard';
397
398 wp_enqueue_style( SRFM_SLUG . $asset_handle . '-font', 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500&display=swap', [], SRFM_VER );
399
400 $script_asset_path = SRFM_DIR . 'assets/build/dashboard.asset.php';
401 $script_info = file_exists( $script_asset_path )
402 ? include $script_asset_path
403 : [
404 'dependencies' => [],
405 'version' => SRFM_VER,
406 ];
407 wp_enqueue_script( SRFM_SLUG . $asset_handle, SRFM_URL . 'assets/build/dashboard.js', $script_info['dependencies'], SRFM_VER, true );
408
409 wp_localize_script( SRFM_SLUG . $asset_handle, 'scIcons', [ 'path' => SRFM_URL . 'assets/build/icon-assets' ] );
410
411 $localization_data['security_settings_url'] = admin_url( '/admin.php?page=sureforms_form_settings&tab=security-settings' );
412 wp_localize_script(
413 SRFM_SLUG . $asset_handle,
414 SRFM_SLUG . '_admin',
415 apply_filters(
416 SRFM_SLUG . '_admin_filter',
417 $localization_data
418 )
419 );
420 wp_enqueue_style( SRFM_SLUG . '-dashboard', SRFM_URL . 'assets/build/dashboard.css', [], SRFM_VER, 'all' );
421
422 }
423
424 if ( 'sureforms_page_sureforms_form_settings' === $current_screen->id ) {
425 wp_enqueue_style( SRFM_SLUG . '-settings', $css_uri . 'backend/settings' . $file_prefix . '.css', [], SRFM_VER );
426 }
427
428 // Enqueue styles for the entries page.
429 if ( 'sureforms_page_' . SRFM_ENTRIES === $current_screen->id ) {
430 $asset_handle = '-entries';
431 wp_enqueue_style( SRFM_SLUG . $asset_handle, $css_uri . 'backend/entries' . $file_prefix . '.css', [], SRFM_VER );
432 wp_enqueue_script( SRFM_SLUG . $asset_handle, SRFM_URL . 'assets/build/entries.js', $script_info['dependencies'], SRFM_VER, true );
433 }
434
435 // Admin Submenu Styles.
436 wp_enqueue_style( SRFM_SLUG . '-admin', $css_uri . 'backend/admin' . $file_prefix . '.css', [], SRFM_VER );
437
438 if ( 'edit-' . SRFM_FORMS_POST_TYPE === $current_screen->id ) {
439 $asset_handle = 'page_header';
440
441 $script_asset_path = SRFM_DIR . 'assets/build/' . $asset_handle . '.asset.php';
442 $script_info = file_exists( $script_asset_path )
443 ? include $script_asset_path
444 : [
445 'dependencies' => [],
446 'version' => SRFM_VER,
447 ];
448 wp_enqueue_script( SRFM_SLUG . '-form-page-header', SRFM_URL . 'assets/build/' . $asset_handle . '.js', $script_info['dependencies'], SRFM_VER, true );
449 wp_enqueue_style( SRFM_SLUG . '-form-archive-styles', $css_uri . 'form-archive-styles' . $file_prefix . '.css', [], SRFM_VER );
450 }
451 if ( 'sureforms_page_' . SRFM_FORMS_POST_TYPE . '_settings' === $current_screen->base ) {
452 $asset_handle = 'settings';
453
454 $script_asset_path = SRFM_DIR . 'assets/build/' . $asset_handle . '.asset.php';
455 $script_info = file_exists( $script_asset_path )
456 ? include $script_asset_path
457 : [
458 'dependencies' => [],
459 'version' => SRFM_VER,
460 ];
461
462 wp_enqueue_script( SRFM_SLUG . '-settings', SRFM_URL . 'assets/build/' . $asset_handle . '.js', $script_info['dependencies'], SRFM_VER, true );
463 wp_enqueue_style( SRFM_SLUG . '-setting-styles', SRFM_URL . 'assets/build/' . $asset_handle . '.css', [ 'wp-components' ], SRFM_VER, 'all' );
464 wp_localize_script(
465 SRFM_SLUG . '-settings',
466 SRFM_SLUG . '_admin',
467 $localization_data
468 );
469 }
470 if ( 'edit-' . SRFM_FORMS_POST_TYPE === $current_screen->id ) {
471 wp_enqueue_script( SRFM_SLUG . '-form-archive', $js_uri . 'form-archive' . $file_prefix . '.js', [], SRFM_VER, true );
472 wp_enqueue_script( SRFM_SLUG . '-export', $js_uri . 'export' . $file_prefix . '.js', [ 'wp-i18n' ], SRFM_VER, true );
473 wp_localize_script(
474 SRFM_SLUG . '-export',
475 SRFM_SLUG . '_export',
476 [
477 'ajaxurl' => admin_url( 'admin-ajax.php' ),
478 'srfm_export_nonce' => wp_create_nonce( 'export_form_nonce' ),
479 'site_url' => get_site_url(),
480 'srfm_import_endpoint' => '/wp-json/sureforms/v1/sureforms_import',
481 'import_form_nonce' => ( current_user_can( 'edit_posts' ) ) ? wp_create_nonce( 'wp_rest' ) : '',
482 ]
483 );
484
485 wp_enqueue_script( SRFM_SLUG . '-backend', $js_uri . 'backend' . $file_prefix . '.js', [], SRFM_VER, true );
486 wp_localize_script(
487 SRFM_SLUG . '-backend',
488 SRFM_SLUG . '_backend',
489 [
490 'site_url' => get_site_url(),
491 ]
492 );
493
494 }
495
496 if ( 'sureforms_page_add-new-form' === $current_screen->id ) {
497
498 $file_prefix = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? '' : '.min';
499 $dir_name = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? 'unminified' : 'minified';
500
501 $css_uri = SRFM_URL . 'assets/css/' . $dir_name . '/';
502
503 /* RTL */
504 if ( is_rtl() ) {
505 $file_prefix .= '-rtl';
506 }
507
508 wp_enqueue_style( SRFM_SLUG . '-template-picker', $css_uri . 'template-picker' . $file_prefix . '.css', [], SRFM_VER );
509
510 $sureforms_admin = 'templatePicker';
511
512 $script_asset_path = SRFM_DIR . 'assets/build/' . $sureforms_admin . '.asset.php';
513 $script_info = file_exists( $script_asset_path )
514 ? include $script_asset_path
515 : [
516 'dependencies' => [],
517 'version' => SRFM_VER,
518 ];
519 wp_enqueue_script( SRFM_SLUG . '-template-picker', SRFM_URL . 'assets/build/' . $sureforms_admin . '.js', $script_info['dependencies'], SRFM_VER, true );
520
521 wp_localize_script(
522 SRFM_SLUG . '-template-picker',
523 SRFM_SLUG . '_admin',
524 [
525 'site_url' => get_site_url(),
526 'plugin_url' => SRFM_URL,
527 'preview_images_url' => SRFM_URL . 'images/template-previews/',
528 'admin_url' => admin_url( 'admin.php' ),
529 'new_template_picker_base_url' => admin_url( 'post-new.php?post_type=sureforms_form' ),
530 'capability' => current_user_can( 'edit_posts' ),
531 'template_picker_nonce' => current_user_can( 'edit_posts' ) ? wp_create_nonce( 'wp_rest' ) : '',
532 'is_pro_active' => defined( 'SRFM_PRO_VER' ),
533 'srfm_ai_usage_details' => AI_Helper::get_current_usage_details(),
534 'is_pro_license_active' => AI_Helper::is_pro_license_active(),
535 'srfm_ai_auth_user_email' => get_option( 'srfm_ai_auth_user_email' ),
536 'pricing_page_url' => $this->get_sureforms_website_url( 'pricing' ),
537 ]
538 );
539 }
540 // Quick action sidebar.
541 $default_allowed_quick_sidebar_blocks = apply_filters(
542 'srfm_quick_sidebar_allowed_blocks',
543 [
544 'srfm/input',
545 'srfm/email',
546 'srfm/textarea',
547 'srfm/checkbox',
548 'srfm/number',
549 'srfm/inline-button',
550 'srfm/advanced-heading',
551 ]
552 );
553 if ( ! is_array( $default_allowed_quick_sidebar_blocks ) ) {
554 $default_allowed_quick_sidebar_blocks = [];
555 }
556
557 $srfm_enable_quick_action_sidebar = get_option( 'srfm_enable_quick_action_sidebar' );
558 if ( ! $srfm_enable_quick_action_sidebar ) {
559 $srfm_enable_quick_action_sidebar = 'disabled';
560 }
561 $quick_sidebar_allowed_blocks = get_option( 'srfm_quick_sidebar_allowed_blocks' );
562 $quick_sidebar_allowed_blocks = ! empty( $quick_sidebar_allowed_blocks ) && is_array( $quick_sidebar_allowed_blocks ) ? $quick_sidebar_allowed_blocks : $default_allowed_quick_sidebar_blocks;
563 $srfm_ajax_nonce = wp_create_nonce( 'srfm_ajax_nonce' );
564 wp_enqueue_script( SRFM_SLUG . '-quick-action-siderbar', SRFM_URL . 'assets/build/quickActionSidebar.js', [], SRFM_VER, true );
565 wp_localize_script(
566 SRFM_SLUG . '-quick-action-siderbar',
567 SRFM_SLUG . '_quick_sidebar_blocks',
568 [
569 'allowed_blocks' => $quick_sidebar_allowed_blocks,
570 'srfm_enable_quick_action_sidebar' => $srfm_enable_quick_action_sidebar,
571 'srfm_ajax_nonce' => $srfm_ajax_nonce,
572 'srfm_ajax_url' => admin_url( 'admin-ajax.php' ),
573 ]
574 );
575
576 /**
577 * Enqueuing SureTriggers Integration script.
578 * This script loads suretriggers iframe in Intergations tab.
579 */
580 if ( SRFM_FORMS_POST_TYPE === $current_screen->post_type ) {
581 wp_enqueue_script( SRFM_SLUG . '-suretriggers-integration', SRFM_SURETRIGGERS_INTEGRATION_BASE_URL . 'js/v2/embed.js', [], SRFM_VER, true );
582 }
583 }
584
585 /**
586 * Form Template Picker Admin Body Classes
587 *
588 * @since 0.0.1
589 * @param string $classes Space separated class string.
590 */
591 public function admin_template_picker_body_class( $classes = '' ) {
592 $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.
593 $classes .= ' ' . $theme_builder_class . ' ';
594
595 return $classes;
596
597 }
598
599 /**
600 * Disable spectra's quick action bar in sureforms CPT.
601 *
602 * @param string $status current status of the quick action bar.
603 * @since 0.0.2
604 * @return string
605 */
606 public function restrict_spectra_quick_action_bar( $status ) {
607 $screen = get_current_screen();
608 if ( 'disabled' !== $status && isset( $screen->id ) && 'sureforms_form' === $screen->id ) {
609 $status = 'disabled';
610 }
611
612 return $status;
613 }
614
615 /**
616 * Get SureForms Website URL.
617 *
618 * @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.
619 * @since 0.0.7
620 * @return string
621 */
622 public static function get_sureforms_website_url( $trail ) {
623 $url = SRFM_WEBSITE;
624 if ( ! empty( $trail ) && is_string( $trail ) ) {
625 $url = SRFM_WEBSITE . $trail;
626 }
627
628 return esc_url( $url );
629 }
630
631 // Entries methods.
632
633 /**
634 * Handle entry actions.
635 *
636 * @since 0.0.13
637 * @return void
638 */
639 public function handle_entry_actions() {
640 if ( isset( $_GET['entry'] ) && isset( $_GET['action'] ) ) {
641 Entries_List_Table::process_bulk_actions();
642 return;
643 }
644 if ( ! isset( $_GET['page'] ) || SRFM_ENTRIES !== $_GET['page'] ) {
645 return;
646 }
647 if ( ! isset( $_GET['entry_id'] ) || ! isset( $_GET['action'] ) ) {
648 return;
649 }
650 if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'srfm_entries_action' ) ) {
651 wp_die( esc_html__( 'Nonce verification failed.', 'sureforms' ) );
652 }
653 $action = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : '';
654 $entry_id = Helper::get_integer_value( sanitize_text_field( wp_unslash( $_GET['entry_id'] ) ) );
655 $view = isset( $_GET['view'] ) ? sanitize_text_field( wp_unslash( $_GET['view'] ) ) : '';
656 if ( $entry_id > 0 ) {
657 if ( 'read' === $action && 'details' === $view ) {
658 $entry_status = Entries::get( $entry_id )['status'];
659 if ( 'trash' === $entry_status ) {
660 wp_die( esc_html__( 'You cannot view this entry because it is in trash.', 'sureforms' ) );
661 }
662 }
663 Entries_List_Table::handle_entry_status( $entry_id, $action, $view );
664 }
665 }
666
667 }
668