PluginProbe
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 1.0.3
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v1.0.3
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 1.0.3, at admin/admin.php

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