PluginProbe
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz / 1.3.0
SureForms – Contact Form Builder, AI Forms, Payment Form, Survey & Quiz v1.3.0
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
← All changes | admin/admin.php +359 -41 0.0.21.3.0 View file →
@@ -6,8 +6,14 @@
6 6 */
7 7
8 8 namespace SRFM\Admin;
9 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;
10 16 use SRFM\Inc\Traits\Get_Instance;
11 17
12 18 if ( ! defined( 'ABSPATH' ) ) {
13 19 exit; // Exit if accessed directly.
@@ -17,9 +23,8 @@
17 23 *
18 24 * @since 0.0.1
19 25 */
20 26 class Admin {
21 -
22 27 use Get_Instance;
23 28
24 29 /**
25 30 * Class constructor.
@@ -34,15 +39,52 @@
34 39 add_action( 'admin_menu', [ $this, 'add_new_form' ] );
35 40 add_filter( 'plugin_action_links', [ $this, 'add_settings_link' ], 10, 2 );
36 41 add_action( 'enqueue_block_assets', [ $this, 'enqueue_styles' ] );
37 42 add_action( 'admin_head', [ $this, 'enqueue_header_styles' ] );
38 - add_action( 'admin_body_class', [ $this, 'admin_template_picker_body_class' ] );
43 + add_filter( 'admin_body_class', [ $this, 'admin_template_picker_body_class' ] );
39 44
40 45 // this action is used to restrict Spectra's quick action bar on SureForms CPTS.
41 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 + add_action( 'admin_notices', [ $this, 'srfm_pro_version_compatibility' ] );
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 + // This action enqueues translations for NPS Survey library.
56 + // A better solution will be required from library to resolve plugin conflict.
57 + add_action(
58 + 'admin_footer',
59 + static function() {
60 + Helper::register_script_translations( 'nps-survey-script' );
61 + },
62 + 1000
63 + );
42 64 }
43 65
44 66 /**
67 + * Enable Gutenberg for SureForms associated post types.
68 + *
69 + * @since 0.0.10
70 + */
71 + public function enable_gutenberg_for_sureforms() {
72 +
73 + // Check if the Classic Editor plugin is active and if it is set to replace the block editor.
74 + if ( ! class_exists( 'Classic_Editor' ) || 'block' === get_option( 'classic-editor-replace' ) ) {
75 + return;
76 + }
77 +
78 + $srfm_post_types = apply_filters( 'srfm_enable_gutenberg_post_types', [ SRFM_FORMS_POST_TYPE ] );
79 +
80 + if ( in_array( get_current_screen()->post_type, $srfm_post_types, true ) ) {
81 + add_filter( 'use_block_editor_for_post_type', '__return_true', 110 );
82 + add_filter( 'gutenberg_can_edit_post_type', '__return_true', 110 );
83 + }
84 + }
85 +
86 + /**
45 87 * Sureforms editor header styles.
46 88 *
47 89 * @since 0.0.1
48 90 */
@@ -82,9 +124,10 @@
82 124 __( 'SureForms', 'sureforms' ),
83 125 __( 'SureForms', 'sureforms' ),
84 126 'edit_others_posts',
85 127 $menu_slug,
86 - function () {},
128 + static function () {
129 + },
87 130 'data:image/svg+xml;base64,' . base64_encode( $logo ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
88 131 30
89 132 );
90 133
@@ -160,8 +203,17 @@
160 203 'add-new-form',
161 204 [ $this, 'add_new_form_callback' ],
162 205 2
163 206 );
207 + add_submenu_page(
208 + 'sureforms_menu',
209 + __( 'Entries', 'sureforms' ),
210 + __( 'Entries', 'sureforms' ),
211 + 'edit_others_posts',
212 + SRFM_ENTRIES,
213 + [ $this, 'render_entries' ],
214 + 3
215 + );
164 216 }
165 217
166 218 /**
167 219 * Add new form mentu item callback.
@@ -173,8 +225,40 @@
173 225 echo '<div id="srfm-add-new-form-container"></div>';
174 226 }
175 227
176 228 /**
229 + * Entries page callback.
230 + *
231 + * @since 0.0.13
232 + * @return void
233 + */
234 + public function render_entries() {
235 + // Render single entry view.
236 + // Adding the phpcs ignore nonce verification as no database operations are performed in this function, it is used to display the single entry view.
237 + if ( isset( $_GET['entry_id'] ) && is_numeric( $_GET['entry_id'] ) && isset( $_GET['view'] ) && 'details' === $_GET['view'] ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended
238 + $single_entry_view = new Single_Entry();
239 + $single_entry_view->render();
240 + return;
241 + }
242 +
243 + // Render all entries view.
244 + $entries_table = new Entries_List_Table();
245 + $entries_table->prepare_items();
246 + echo '<div class="wrap"><h1 class="wp-heading-inline">' . esc_html__( 'Entries', 'sureforms' ) . '</h1>';
247 + if ( empty( $entries_table->all_entries_count ) && empty( $entries_table->trash_entries_count ) ) {
248 + $instance = Post_Types::get_instance();
249 + $instance->sureforms_render_blank_state( SRFM_ENTRIES );
250 + $instance->get_blank_state_styles();
251 + return;
252 + }
253 + echo '<form method="get">';
254 + echo '<input type="hidden" name="page" value="sureforms_entries">';
255 + $entries_table->display();
256 + echo '</form>';
257 + echo '</div>';
258 + }
259 +
260 + /**
177 261 * Adds a settings link to the plugin action links on the plugins page.
178 262 *
179 263 * @param array $links An array of plugin action links.
180 264 * @param string $file The plugin file path.
@@ -182,10 +266,15 @@
182 266 * @since 0.0.1
183 267 */
184 268 public function add_settings_link( $links, $file ) {
185 269 if ( 'sureforms/sureforms.php' === $file ) {
186 - $settings_link = '<a href="' . esc_url( admin_url( 'admin.php?page=sureforms_form_settings&tab=general-settings' ) ) . '">' . esc_html__( 'Settings', 'sureforms' ) . '</a>';
187 - array_push( $links, $settings_link );
270 + $plugin_links = apply_filters(
271 + 'sureforms_plugin_action_links',
272 + [
273 + 'sureforms_settings' => '<a href="' . esc_url( admin_url( 'admin.php?page=sureforms_form_settings&tab=general-settings' ) ) . '">' . esc_html__( 'Settings', 'sureforms' ) . '</a>',
274 + ]
275 + );
276 + $links = array_merge( $plugin_links, $links );
188 277 }
189 278 return $links;
190 279 }
191 280
@@ -195,8 +284,9 @@
195 284 * @since 0.0.1
196 285 */
197 286 public function enqueue_styles() {
198 287 $current_screen = get_current_screen();
288 + global $wp_version;
199 289
200 290 $file_prefix = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? '' : '.min';
201 291 $dir_name = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? 'unminified' : 'minified';
202 292
@@ -214,8 +304,17 @@
214 304 wp_enqueue_style( SRFM_SLUG . '-backend-blocks', $css_uri . 'blocks/default/backend' . $file_prefix . '.css', [], SRFM_VER );
215 305 wp_enqueue_style( SRFM_SLUG . '-intl', $vendor_css_uri . 'intl/intlTelInput-backend.min.css', [], SRFM_VER );
216 306 wp_enqueue_style( SRFM_SLUG . '-common', $css_uri . 'common' . $file_prefix . '.css', [], SRFM_VER );
217 307 wp_enqueue_style( SRFM_SLUG . '-reactQuill', $vendor_css_uri . 'quill/quill.snow.css', [], SRFM_VER );
308 + wp_enqueue_style( SRFM_SLUG . '-single-form-modal', $css_uri . 'single-form-setting' . $file_prefix . '.css', [], SRFM_VER );
309 +
310 + // if version is equal to or lower than 6.6.2 then add compatibility css.
311 + if ( version_compare( $wp_version, '6.6.2', '<=' ) ) {
312 + $srfm_inline_css = '.srfm-settings-modal .srfm-setting-modal-container .components-toggle-control .components-base-control__help{
313 + margin-left: 4em;
314 + }';
315 + wp_add_inline_style( SRFM_SLUG . '-single-form-modal', $srfm_inline_css );
316 + }
218 317 }
219 318
220 319 wp_enqueue_style( SRFM_SLUG . '-form-selector', $css_uri . 'srfm-form-selector' . $file_prefix . '.css', [], SRFM_VER );
221 320 wp_enqueue_style( SRFM_SLUG . '-common-editor', SRFM_URL . 'assets/build/common-editor.css', [], SRFM_VER, 'all' );
@@ -262,13 +361,8 @@
262 361 $breadcrumbs[] = [
263 362 'title' => 'Forms',
264 363 'link' => '',
265 364 ];
266 - } elseif ( $current_screen && 'sureforms_entry' === $current_screen->post_type ) {
267 - $breadcrumbs[] = [
268 - 'title' => 'Entries',
269 - 'link' => '',
270 - ];
271 365 } else {
272 366 $breadcrumbs[] = [
273 367 'title' => '',
274 368 'link' => '',
@@ -278,9 +372,8 @@
278 372
279 373 return $breadcrumbs;
280 374 }
281 375
282 -
283 376 /**
284 377 * Enqueue Admin Scripts.
285 378 *
286 379 * @return void
@@ -287,8 +380,9 @@
287 380 * @since 0.0.1
288 381 */
289 382 public function enqueue_scripts() {
290 383 $current_screen = get_current_screen();
384 + global $wp_version;
291 385
292 386 $file_prefix = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? '' : '.min';
293 387 $dir_name = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? 'unminified' : 'minified';
294 388 $js_uri = SRFM_URL . 'assets/js/' . $dir_name . '/';
@@ -293,16 +387,39 @@
293 387 $dir_name = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? 'unminified' : 'minified';
294 388 $js_uri = SRFM_URL . 'assets/js/' . $dir_name . '/';
295 389 $css_uri = SRFM_URL . 'assets/css/' . $dir_name . '/';
296 390
391 + /**
392 + * List of the handles in which we need to add translation compatibility.
393 + */
394 + $script_translations_handlers = [];
395 +
297 396 /* RTL */
298 397 if ( is_rtl() ) {
299 398 $file_prefix .= '-rtl';
300 399 }
301 400
302 - if ( SRFM_FORMS_POST_TYPE === $current_screen->post_type || 'toplevel_page_sureforms_menu' === $current_screen->base || SRFM_ENTRIES_POST_TYPE === $current_screen->post_type
303 - || 'sureforms_page_sureforms_form_settings' === $current_screen->id
304 - ) {
401 + $localization_data = [
402 + 'site_url' => get_site_url(),
403 + 'breadcrumbs' => $this->get_breadcrumbs_for_current_page(),
404 + 'sureforms_dashboard_url' => admin_url( '/admin.php?page=sureforms_menu' ),
405 + 'plugin_version' => SRFM_VER,
406 + 'global_settings_nonce' => current_user_can( 'manage_options' ) ? wp_create_nonce( 'wp_rest' ) : '',
407 + 'is_pro_active' => defined( 'SRFM_PRO_VER' ),
408 + 'pro_plugin_version' => defined( 'SRFM_PRO_VER' ) ? SRFM_PRO_VER : '',
409 + 'pro_plugin_name' => defined( 'SRFM_PRO_VER' ) && defined( 'SRFM_PRO_PRODUCT' ) ? SRFM_PRO_PRODUCT : 'SureForms Pro',
410 + 'sureforms_pricing_page' => $this->get_sureforms_website_url( 'pricing' ),
411 + 'field_spacing_vars' => Helper::get_css_vars(),
412 + 'is_ver_lower_than_6_7' => version_compare( $wp_version, '6.6.2', '<=' ),
413 + ];
414 +
415 + $is_screen_sureforms_menu = Helper::validate_request_context( 'sureforms_menu', 'page' );
416 + $is_screen_add_new_form = Helper::validate_request_context( 'add-new-form', 'page' );
417 + $is_screen_sureforms_form_settings = Helper::validate_request_context( 'sureforms_form_settings', 'page' );
418 + $is_screen_sureforms_entries = Helper::validate_request_context( SRFM_ENTRIES, 'page' );
419 + $is_post_type_sureforms_form = SRFM_FORMS_POST_TYPE === $current_screen->post_type;
420 +
421 + if ( $is_screen_sureforms_menu || $is_post_type_sureforms_form || $is_screen_add_new_form || $is_screen_sureforms_form_settings || $is_screen_sureforms_entries ) {
305 422 $asset_handle = '-dashboard';
306 423
307 424 wp_enqueue_style( SRFM_SLUG . $asset_handle . '-font', 'https://fonts.googleapis.com/css2?family=Inter:wght@400;500&display=swap', [], SRFM_VER );
308 425
@@ -315,21 +432,31 @@
315 432 ];
316 433 wp_enqueue_script( SRFM_SLUG . $asset_handle, SRFM_URL . 'assets/build/dashboard.js', $script_info['dependencies'], SRFM_VER, true );
317 434
318 435 wp_localize_script( SRFM_SLUG . $asset_handle, 'scIcons', [ 'path' => SRFM_URL . 'assets/build/icon-assets' ] );
436 +
437 + $script_translations_handlers[] = SRFM_SLUG . $asset_handle;
438 +
439 + if ( class_exists( 'SRFM_PRO\Admin\Licensing' ) ) {
440 + $license_active = \SRFM_PRO\Admin\Licensing::is_license_active();
441 + $localization_data['is_license_active'] = $license_active;
442 +
443 + // Updating current licensing status.
444 + $srfm_pro_license_status = get_option( 'srfm_pro_license_status', '' );
445 + $current_license_status = $license_active ? 'licensed' : 'unlicensed';
446 + if ( $current_license_status !== $srfm_pro_license_status ) {
447 + update_option( 'srfm_pro_license_status', $current_license_status );
448 + }
449 + }
450 +
451 + $localization_data['security_settings_url'] = admin_url( '/admin.php?page=sureforms_form_settings&tab=security-settings' );
452 + $localization_data['integration_settings_url'] = admin_url( '/admin.php?page=sureforms_form_settings&tab=integration-settings' );
319 453 wp_localize_script(
320 454 SRFM_SLUG . $asset_handle,
321 455 SRFM_SLUG . '_admin',
322 456 apply_filters(
323 457 SRFM_SLUG . '_admin_filter',
324 - [
325 - 'site_url' => get_site_url(),
326 - 'breadcrumbs' => $this->get_breadcrumbs_for_current_page(),
327 - 'sureforms_dashboard_url' => admin_url( '/admin.php?page=sureforms_menu' ),
328 - 'plugin_version' => SRFM_VER,
329 - 'global_settings_nonce' => ( current_user_can( 'manage_options' ) ) ? wp_create_nonce( 'wp_rest' ) : '',
330 - 'security_settings_url' => admin_url( '/admin.php?page=sureforms_form_settings&tab=security-settings' ),
331 - ]
458 + $localization_data
332 459 )
333 460 );
334 461 wp_enqueue_style( SRFM_SLUG . '-dashboard', SRFM_URL . 'assets/build/dashboard.css', [], SRFM_VER, 'all' );
335 462
@@ -334,17 +461,38 @@
334 461 wp_enqueue_style( SRFM_SLUG . '-dashboard', SRFM_URL . 'assets/build/dashboard.css', [], SRFM_VER, 'all' );
335 462
336 463 }
337 464
338 - if ( 'sureforms_page_sureforms_form_settings' === $current_screen->id ) {
465 + if ( $is_screen_sureforms_form_settings ) {
339 466 wp_enqueue_style( SRFM_SLUG . '-settings', $css_uri . 'backend/settings' . $file_prefix . '.css', [], SRFM_VER );
467 +
468 + // if version is equal to or lower than 6.6.2 then add compatibility css.
469 + if ( version_compare( $wp_version, '6.6.2', '<=' ) ) {
470 + $srfm_inline_css = '
471 + .srfm-settings-page-container
472 + .components-toggle-control {
473 + .components-base-control__help{
474 + margin-left: 4em;
475 + }
476 + }
477 + }
478 + ';
479 + wp_add_inline_style( SRFM_SLUG . '-settings', $srfm_inline_css );
480 + }
340 481 }
341 482
483 + // Enqueue styles for the entries page.
484 + if ( $is_screen_sureforms_entries ) {
485 + $asset_handle = '-entries';
486 + wp_enqueue_script( SRFM_SLUG . $asset_handle, SRFM_URL . 'assets/build/entries.js', $script_info['dependencies'], SRFM_VER, true );
487 +
488 + $script_translations_handlers[] = SRFM_SLUG . $asset_handle;
489 + }
490 +
342 491 // Admin Submenu Styles.
343 492 wp_enqueue_style( SRFM_SLUG . '-admin', $css_uri . 'backend/admin' . $file_prefix . '.css', [], SRFM_VER );
344 - wp_enqueue_style( SRFM_SLUG . '-single-form-modal', $css_uri . 'single-form-setting' . $file_prefix . '.css', [], SRFM_VER );
345 493
346 - if ( 'edit-' . SRFM_FORMS_POST_TYPE === $current_screen->id || 'edit-' . SRFM_ENTRIES_POST_TYPE === $current_screen->id ) {
494 + if ( 'edit-' . SRFM_FORMS_POST_TYPE === $current_screen->id ) {
347 495 $asset_handle = 'page_header';
348 496
349 497 $script_asset_path = SRFM_DIR . 'assets/build/' . $asset_handle . '.asset.php';
350 498 $script_info = file_exists( $script_asset_path )
@@ -354,10 +502,13 @@
354 502 'version' => SRFM_VER,
355 503 ];
356 504 wp_enqueue_script( SRFM_SLUG . '-form-page-header', SRFM_URL . 'assets/build/' . $asset_handle . '.js', $script_info['dependencies'], SRFM_VER, true );
357 505 wp_enqueue_style( SRFM_SLUG . '-form-archive-styles', $css_uri . 'form-archive-styles' . $file_prefix . '.css', [], SRFM_VER );
506 +
507 + $script_translations_handlers[] = SRFM_SLUG . '-form-page-header';
358 508 }
359 - if ( 'sureforms_page_' . SRFM_FORMS_POST_TYPE . '_settings' === $current_screen->base ) {
509 +
510 + if ( $is_screen_sureforms_form_settings ) {
360 511 $asset_handle = 'settings';
361 512
362 513 $script_asset_path = SRFM_DIR . 'assets/build/' . $asset_handle . '.asset.php';
363 514 $script_info = file_exists( $script_asset_path )
@@ -365,25 +516,22 @@
365 516 : [
366 517 'dependencies' => [],
367 518 'version' => SRFM_VER,
368 519 ];
520 +
369 521 wp_enqueue_script( SRFM_SLUG . '-settings', SRFM_URL . 'assets/build/' . $asset_handle . '.js', $script_info['dependencies'], SRFM_VER, true );
370 522 wp_enqueue_style( SRFM_SLUG . '-setting-styles', SRFM_URL . 'assets/build/' . $asset_handle . '.css', [ 'wp-components' ], SRFM_VER, 'all' );
371 523 wp_localize_script(
372 524 SRFM_SLUG . '-settings',
373 525 SRFM_SLUG . '_admin',
374 - [
375 - 'site_url' => get_site_url(),
376 - 'breadcrumbs' => $this->get_breadcrumbs_for_current_page(),
377 - 'sureforms_dashboard_url' => admin_url( '/admin.php?page=sureforms_menu' ),
378 - 'plugin_version' => SRFM_VER,
379 - 'global_settings_nonce' => current_user_can( 'manage_options' ) ? wp_create_nonce( 'wp_rest' ) : '',
380 - ]
526 + $localization_data
381 527 );
528 +
529 + $script_translations_handlers[] = SRFM_SLUG . '-settings';
382 530 }
383 531 if ( 'edit-' . SRFM_FORMS_POST_TYPE === $current_screen->id ) {
384 532 wp_enqueue_script( SRFM_SLUG . '-form-archive', $js_uri . 'form-archive' . $file_prefix . '.js', [], SRFM_VER, true );
385 - wp_enqueue_script( SRFM_SLUG . '-export', $js_uri . 'export' . $file_prefix . '.js', [], SRFM_VER, true );
533 + wp_enqueue_script( SRFM_SLUG . '-export', $js_uri . 'export' . $file_prefix . '.js', [ 'wp-i18n' ], SRFM_VER, true );
386 534 wp_localize_script(
387 535 SRFM_SLUG . '-export',
388 536 SRFM_SLUG . '_export',
389 537 [
@@ -390,9 +538,9 @@
390 538 'ajaxurl' => admin_url( 'admin-ajax.php' ),
391 539 'srfm_export_nonce' => wp_create_nonce( 'export_form_nonce' ),
392 540 'site_url' => get_site_url(),
393 541 'srfm_import_endpoint' => '/wp-json/sureforms/v1/sureforms_import',
394 - 'import_form_nonce' => ( current_user_can( 'edit_posts' ) ) ? wp_create_nonce( 'wp_rest' ) : '',
542 + 'import_form_nonce' => current_user_can( 'edit_posts' ) ? wp_create_nonce( 'wp_rest' ) : '',
395 543 ]
396 544 );
397 545
398 546 wp_enqueue_script( SRFM_SLUG . '-backend', $js_uri . 'backend' . $file_prefix . '.js', [], SRFM_VER, true );
@@ -403,12 +551,14 @@
403 551 'site_url' => get_site_url(),
404 552 ]
405 553 );
406 554
555 + $script_translations_handlers[] = SRFM_SLUG . '-form-archive';
556 + $script_translations_handlers[] = SRFM_SLUG . '-export';
557 + $script_translations_handlers[] = SRFM_SLUG . '-backend';
407 558 }
408 559
409 - if ( 'sureforms_page_add-new-form' === $current_screen->id ) {
410 -
560 + if ( $is_screen_add_new_form ) {
411 561 $file_prefix = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? '' : '.min';
412 562 $dir_name = defined( 'SRFM_DEBUG' ) && SRFM_DEBUG ? 'unminified' : 'minified';
413 563
414 564 $css_uri = SRFM_URL . 'assets/css/' . $dir_name . '/';
@@ -442,10 +592,16 @@
442 592 'new_template_picker_base_url' => admin_url( 'post-new.php?post_type=sureforms_form' ),
443 593 'capability' => current_user_can( 'edit_posts' ),
444 594 'template_picker_nonce' => current_user_can( 'edit_posts' ) ? wp_create_nonce( 'wp_rest' ) : '',
445 595 'is_pro_active' => defined( 'SRFM_PRO_VER' ),
596 + 'srfm_ai_usage_details' => AI_Helper::get_current_usage_details(),
597 + 'is_pro_license_active' => AI_Helper::is_pro_license_active(),
598 + 'srfm_ai_auth_user_email' => get_option( 'srfm_ai_auth_user_email' ),
599 + 'pricing_page_url' => $this->get_sureforms_website_url( 'pricing' ),
446 600 ]
447 601 );
602 +
603 + $script_translations_handlers[] = SRFM_SLUG . '-template-picker';
448 604 }
449 605 // Quick action sidebar.
450 606 $default_allowed_quick_sidebar_blocks = apply_filters(
451 607 'srfm_quick_sidebar_allowed_blocks',
@@ -452,10 +608,12 @@
452 608 [
453 609 'srfm/input',
454 610 'srfm/email',
455 611 'srfm/textarea',
612 + 'srfm/checkbox',
456 613 'srfm/number',
457 - 'srfm/address',
614 + 'srfm/inline-button',
615 + 'srfm/advanced-heading',
458 616 ]
459 617 );
460 618 if ( ! is_array( $default_allowed_quick_sidebar_blocks ) ) {
461 619 $default_allowed_quick_sidebar_blocks = [];
@@ -478,22 +636,66 @@
478 636 'srfm_ajax_nonce' => $srfm_ajax_nonce,
479 637 'srfm_ajax_url' => admin_url( 'admin-ajax.php' ),
480 638 ]
481 639 );
640 +
641 + $script_translations_handlers[] = SRFM_SLUG . '-quick-action-siderbar';
642 +
643 + /**
644 + * Enqueuing SureTriggers Integration script.
645 + * This script loads suretriggers iframe in Intergations tab.
646 + */
647 + if ( $is_post_type_sureforms_form ) {
648 + wp_enqueue_script( SRFM_SLUG . '-suretriggers-integration', SRFM_SURETRIGGERS_INTEGRATION_BASE_URL . 'js/v2/embed.js', [], SRFM_VER, true );
649 + }
650 +
651 + // Check $script_translations_handlers is not empty before calling the function.
652 + if ( ! empty( $script_translations_handlers ) ) {
653 + // Remove duplicates values from the array.
654 + $script_translations_handlers = array_unique( $script_translations_handlers );
655 +
656 + foreach ( $script_translations_handlers as $script_handle ) {
657 + Helper::register_script_translations( $script_handle );
658 + }
659 + }
482 660 }
483 661
484 662 /**
485 663 * Form Template Picker Admin Body Classes
664 + * WordPress sometimes translates class names in the admin body tag, which can result in
665 + * incorrect or missing class names when rendering the admin pages. This function ensures
666 + * that essential class names are manually added to the body tag to maintain proper functionality.
486 667 *
487 668 * @since 0.0.1
488 669 * @param string $classes Space separated class string.
489 670 */
490 671 public function admin_template_picker_body_class( $classes = '' ) {
491 - $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.
492 - $classes .= ' ' . $theme_builder_class . ' ';
672 + // Define an associative array of class names and their corresponding conditions.
673 + // Each condition checks whether a specific request context matches.
674 + $srfm_classes = [
675 + 'sureforms_page_sureforms_entries' => Helper::validate_request_context( SRFM_ENTRIES, 'page' ),
676 + 'sureforms_page_sureforms_form_settings' => Helper::validate_request_context( 'sureforms_form_settings', 'page' ),
677 + 'srfm-template-picker' => Helper::validate_request_context( 'add-new-form', 'page' ),
678 + ];
493 679
680 + $add_srfm_classes = '';
681 +
682 + // Loop through the defined classes and conditions.
683 + foreach ( $srfm_classes as $class => $condition ) {
684 + // Check if the condition evaluates to true.
685 + if ( $condition ) {
686 + // Append the class to the existing classes string, followed by a space.
687 + $add_srfm_classes .= empty( $add_srfm_classes ) ? $class : ' ' . $class;
688 + }
689 + }
690 +
691 + // Append the new classes to the existing classes string.
692 + if ( ! empty( $add_srfm_classes ) ) {
693 + $classes .= ' ' . $add_srfm_classes;
694 + }
695 +
696 + // Return the updated list of classes.
494 697 return $classes;
495 -
496 698 }
497 699
498 700 /**
499 701 * Disable spectra's quick action bar in sureforms CPT.
@@ -509,5 +711,121 @@
509 711 }
510 712
511 713 return $status;
512 714 }
715 +
716 + /**
717 + * Get SureForms Website URL.
718 + *
719 + * @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.
720 + * @since 0.0.7
721 + * @return string
722 + */
723 + public static function get_sureforms_website_url( $trail ) {
724 + $url = SRFM_WEBSITE;
725 + if ( ! empty( $trail ) && is_string( $trail ) ) {
726 + $url = SRFM_WEBSITE . $trail;
727 + }
728 +
729 + $url = \BSF_UTM_Analytics\Inc\Utils::get_utm_ready_link( $url, 'sureforms' );
730 +
731 + return esc_url( $url );
732 + }
733 +
734 + // Entries methods.
735 +
736 + /**
737 + * Handle entry actions.
738 + *
739 + * @since 0.0.13
740 + * @return void
741 + */
742 + public function handle_entry_actions() {
743 + Entries_List_Table::process_bulk_actions();
744 +
745 + if ( ! isset( $_GET['page'] ) || SRFM_ENTRIES !== $_GET['page'] ) {
746 + return;
747 + }
748 + if ( ! isset( $_GET['entry_id'] ) || ! isset( $_GET['action'] ) ) {
749 + return;
750 + }
751 + if ( ! isset( $_GET['_wpnonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_GET['_wpnonce'] ) ), 'srfm_entries_action' ) ) {
752 + wp_die( esc_html__( 'Nonce verification failed.', 'sureforms' ) );
753 + }
754 + $action = isset( $_GET['action'] ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : '';
755 + $entry_id = Helper::get_integer_value( sanitize_text_field( wp_unslash( $_GET['entry_id'] ) ) );
756 + $view = isset( $_GET['view'] ) ? sanitize_text_field( wp_unslash( $_GET['view'] ) ) : '';
757 + if ( $entry_id > 0 ) {
758 + if ( 'read' === $action && 'details' === $view ) {
759 + $entry_status = Entries::get( $entry_id )['status'];
760 + if ( 'trash' === $entry_status ) {
761 + wp_die( esc_html__( 'You cannot view this entry because it is in trash.', 'sureforms' ) );
762 + }
763 + }
764 + Entries_List_Table::handle_entry_status( $entry_id, $action, $view );
765 + }
766 + }
767 +
768 + /**
769 + * Admin Notice Callback if sureforms pro is out of date.
770 + *
771 + * Hooked - admin_notices
772 + *
773 + * @return void
774 + * @since 1.0.4
775 + */
776 + public function srfm_pro_version_compatibility() {
777 + $plugin_file = 'sureforms-pro/sureforms-pro.php';
778 + if ( ! is_plugin_active( $plugin_file ) || ! defined( 'SRFM_PRO_VER' ) ) {
779 + return;
780 + }
781 +
782 + if ( empty( get_current_screen() ) ) {
783 + return;
784 + }
785 +
786 + if ( ! current_user_can( 'update_plugins' ) ) {
787 + return;
788 + }
789 +
790 + $srfm_pro_license_status = get_option( 'srfm_pro_license_status', '' );
791 + /**
792 + * If the license status is not set then get the license status and update the option accordingly.
793 + * This will be executed only once. Subsequently, the option status is updated by the licensing class on license activation or deactivation.
794 + */
795 + if ( empty( $srfm_pro_license_status ) && class_exists( 'SRFM_PRO\Admin\Licensing' ) ) {
796 + $srfm_pro_license_status = \SRFM_PRO\Admin\Licensing::is_license_active() ? 'licensed' : 'unlicensed';
797 + update_option( 'srfm_pro_license_status', $srfm_pro_license_status );
798 + }
799 +
800 + $pro_plugin_name = defined( 'SRFM_PRO_PRODUCT' ) ? SRFM_PRO_PRODUCT : 'SureForms Pro';
801 + $message = '';
802 + $url = admin_url( 'admin.php?page=sureforms_form_settings&tab=account-settings' );
803 + if ( 'unlicensed' === $srfm_pro_license_status ) {
804 + $message = '<p>' . sprintf(
805 + // translators: %1$s: Opening anchor tag with URL, %2$s: Closing anchor tag, %3$s: SureForms Pro Plugin Name.
806 + esc_html__( 'Please %1$sactivate%2$s your copy of %3$s to get new features, access support, receive update notifications, and more.', 'sureforms' ),
807 + '<a href="' . esc_url( $url ) . '">',
808 + '</a>',
809 + '<i>' . esc_html( $pro_plugin_name ) . '</i>'
810 + ) . '</p>';
811 + }
812 +
813 + if ( ! version_compare( SRFM_PRO_VER, SRFM_PRO_RECOMMENDED_VER, '>=' ) ) {
814 + $message .= '<p>' . sprintf(
815 + // translators: %1$s: SureForms version, %2$s: SureForms Pro Plugin Name, %3$s: SureForms Pro Version, %4$s: Anchor tag open, %5$s: Closing anchor tag.
816 + esc_html__( 'SureForms %1$s requires minimum %2$s %3$s to work properly. Please update to the latest version from %4$shere%5$s.', 'sureforms' ),
817 + esc_html( SRFM_VER ),
818 + esc_html( $pro_plugin_name ),
819 + esc_html( SRFM_PRO_RECOMMENDED_VER ),
820 + '<a href=' . esc_url( admin_url( 'update-core.php' ) ) . '>',
821 + '</a>'
822 + ) . '</p>';
823 + }
824 +
825 + if ( ! empty( $message ) ) {
826 + // Phpcs ignore comment is required as $message variable is already escaped.
827 + echo '<div class="notice notice-warning">' . $message . '</div>'; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
828 + }
829 + }
830 +
513 831 }