PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.20
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.20
6.35 6.34 6.33.1 6.33 6.32.1 6.32 6.31 6.25 6.25.1 6.26 6.26.1 6.27 6.28 6.29 6.3 6.3.1 6.3.2 6.30 6.4 6.4.1 6.4.2 6.5 6.5.1 6.5.2 6.5.3 All 141 releases
← All changes | classes/controllers/FrmAppController.php +572 -189 6.4.16.20 View file →
@@ -14,8 +14,13 @@
14 14 return;
15 15 }
16 16
17 17 $menu_name = FrmAppHelper::get_menu_name();
18 +
19 + if ( in_array( $menu_name, array( 'Formidable', 'Forms' ), true ) ) {
20 + $menu_name .= wp_kses_post( FrmInboxController::get_notice_count() );
21 + }
22 +
18 23 add_menu_page( 'Formidable', $menu_name, 'frm_view_forms', 'formidable', 'FrmFormsController::route', self::menu_icon(), self::get_menu_position() );
19 24 }
20 25
21 26 /**
@@ -61,14 +66,20 @@
61 66 $classes .= ' frm-admin-page-' . $page;
62 67 }
63 68 }
64 69
70 + if ( self::is_grey_page() ) {
71 + $classes .= ' frm-grey-body ';
72 + }
73 +
65 74 if ( FrmAppHelper::is_full_screen() ) {
66 75 $full_screen_on = self::get_full_screen_setting();
67 - $add_class = '';
76 + $add_class = '';
68 77 if ( $full_screen_on ) {
69 78 $add_class = ' frm-full-screen is-fullscreen-mode';
70 - wp_enqueue_style( 'wp-edit-post' ); // Load the CSS for .is-fullscreen-mode.
79 +
80 + // Load the CSS for .is-fullscreen-mode.
81 + wp_enqueue_style( 'wp-edit-post' );
71 82 }
72 83 $classes .= apply_filters( 'frm_admin_full_screen_class', $add_class );
73 84 }
74 85
@@ -75,8 +86,12 @@
75 86 if ( ! FrmAppHelper::pro_is_installed() ) {
76 87 $classes .= ' frm-lite ';
77 88 }
78 89
90 + if ( get_user_setting( 'unfold' ) && 'f' !== get_user_setting( 'mfold' ) ) {
91 + $classes .= ' frm-unfold ';
92 + }
93 +
79 94 return $classes;
80 95 }
81 96
82 97 /**
@@ -124,9 +139,8 @@
124 139 'formidable',
125 140 'formidable-entries',
126 141 'formidable-views',
127 142 'formidable-views-editor',
128 - 'formidable-pro-upgrade',
129 143 'formidable-addons',
130 144 'formidable-import',
131 145 'formidable-settings',
132 146 'formidable-styles',
@@ -131,20 +145,25 @@
131 145 'formidable-settings',
132 146 'formidable-styles',
133 147 'formidable-styles2',
134 148 'formidable-inbox',
135 - 'formidable-welcome',
136 - 'formidable-applications',
149 + FrmFormTemplatesController::PAGE_SLUG,
150 + FrmOnboardingWizardController::PAGE_SLUG,
137 151 );
138 152
139 - $get_page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
140 - $is_white_page = in_array( $get_page, $white_pages, true );
153 + if ( ! class_exists( 'FrmTransHooksController', false ) && ! FrmTransLiteAppHelper::should_fallback_to_paypal() ) {
154 + // Only consider the payments page as a "white page" when the Payments submodule is off.
155 + // Otherwise this causes a lot of styling issues when the Stripe add-on (or Authorize.Net) is active.
141 156
142 - if ( ! $is_white_page ) {
143 - $screen = get_current_screen();
144 - $is_white_page = ( $screen && strpos( $screen->id, 'frm_display' ) !== false );
157 + // Add an extra check to avoid white page styling on the PayPal "edit" action.
158 + // We fallback to the PayPal add on for the "edit" action since Stripe Lite does not have an edit view.
159 + if ( ! in_array( FrmAppHelper::simple_get( 'action' ), array( 'edit', 'new' ), true ) || ! is_callable( 'FrmPaymentsController::route' ) ) {
160 + $white_pages[] = 'formidable-payments';
161 + }
145 162 }
146 163
164 + $is_white_page = self::is_page_in_list( $white_pages ) || self::is_grey_page() || FrmAppHelper::is_view_builder_page();
165 +
147 166 /**
148 167 * Allow another add on to style a page as a Formidable "white page", which adds a white background color.
149 168 *
150 169 * @since 5.3
@@ -156,8 +175,46 @@
156 175 return $is_white_page;
157 176 }
158 177
159 178 /**
179 + * Add a grey bg instead of white.
180 + *
181 + * @since 6.8
182 + *
183 + * @return bool
184 + */
185 + private static function is_grey_page() {
186 + $grey_pages = array(
187 + 'formidable-applications',
188 + 'formidable-dashboard',
189 + 'formidable-views',
190 + );
191 +
192 + $is_grey_page = self::is_page_in_list( $grey_pages );
193 +
194 + /**
195 + * Filter to change FF wrapper background to grey.
196 + *
197 + * @since 6.8
198 + *
199 + * @param bool $is_grey_page
200 + * @return bool
201 + */
202 + return apply_filters( 'frm_is_grey_page', $is_grey_page );
203 + }
204 +
205 + /**
206 + * @since 6.8
207 + *
208 + * @param array $pages A list of page names to check.
209 + * @return bool
210 + */
211 + private static function is_page_in_list( $pages ) {
212 + $get_page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
213 + return in_array( $get_page, $pages, true );
214 + }
215 +
216 + /**
160 217 * @return void
161 218 */
162 219 public static function load_wp_admin_style() {
163 220 FrmAppHelper::load_font_style();
@@ -163,10 +220,11 @@
163 220 FrmAppHelper::load_font_style();
164 221 }
165 222
166 223 /**
167 - * @param bool $show_nav
168 - * @param string $title
224 + * @param int|object $form
225 + * @param bool $show_nav
226 + * @param string $title
169 227 *
170 228 * @psalm-param 'hide'|'show' $title
171 229 *
172 230 * @return void
@@ -185,9 +243,9 @@
185 243 $id = $form->id;
186 244 $current_page = self::get_current_page();
187 245 $nav_items = self::get_form_nav_items( $form );
188 246
189 - include( FrmAppHelper::plugin_path() . '/classes/views/shared/form-nav.php' );
247 + include FrmAppHelper::plugin_path() . '/classes/views/shared/form-nav.php';
190 248 }
191 249
192 250 /**
193 251 * @return string
@@ -241,18 +299,18 @@
241 299 'permission' => 'frm_view_entries',
242 300 ),
243 301 );
244 302
245 - $views_installed = is_callable( 'FrmProAppHelper::views_is_installed' ) ? FrmProAppHelper::views_is_installed() : FrmAppHelper::pro_is_installed();
303 + $views_installed = is_callable( 'FrmProAppHelper::views_is_installed' ) && FrmProAppHelper::views_is_installed();
246 304
247 305 if ( ! $views_installed ) {
248 306 $nav_items[] = array(
249 - 'link' => admin_url( 'admin.php?page=formidable-views&form=' . absint( $id ) ),
250 - 'label' => __( 'Views', 'formidable' ),
251 - 'current' => array(),
252 - 'page' => 'formidable-views',
307 + 'link' => admin_url( 'admin.php?page=formidable-views&form=' . absint( $id ) ),
308 + 'label' => __( 'Views', 'formidable' ),
309 + 'current' => array(),
310 + 'page' => 'formidable-views',
253 311 'permission' => 'frm_view_entries',
254 - 'atts' => array(
312 + 'atts' => array(
255 313 'class' => 'frm_noallow',
256 314 ),
257 315 );
258 316 }
@@ -259,14 +317,14 @@
259 317
260 318 // Let people know reports and views exist.
261 319 if ( ! FrmAppHelper::pro_is_installed() ) {
262 320 $nav_items[] = array(
263 - 'link' => admin_url( 'admin.php?page=formidable&frm_action=lite-reports&form=' . absint( $id ) ),
264 - 'label' => __( 'Reports', 'formidable' ),
265 - 'current' => array( 'reports' ),
266 - 'page' => 'formidable',
321 + 'link' => admin_url( 'admin.php?page=formidable&frm_action=lite-reports&form=' . absint( $id ) ),
322 + 'label' => __( 'Reports', 'formidable' ),
323 + 'current' => array( 'reports' ),
324 + 'page' => 'formidable',
267 325 'permission' => 'frm_view_entries',
268 - 'atts' => array(
326 + 'atts' => array(
269 327 'class' => 'frm_noallow',
270 328 ),
271 329 );
272 330 }
@@ -278,10 +336,12 @@
278 336
279 337 return (array) apply_filters( 'frm_form_nav_list', $nav_items, $nav_args );
280 338 }
281 339
282 - // Adds a settings link to the plugins page
283 340 /**
341 + * Adds a settings link to the plugins page
342 + *
343 + * @param array $links
284 344 * @return array
285 345 */
286 346 public static function settings_link( $links ) {
287 347 $settings = array();
@@ -286,9 +346,23 @@
286 346 public static function settings_link( $links ) {
287 347 $settings = array();
288 348
289 349 if ( ! FrmAppHelper::pro_is_installed() ) {
290 - $settings[] = '<a href="' . esc_url( FrmAppHelper::admin_upgrade_link( 'plugin-row' ) ) . '" target="_blank" rel="noopener"><b>' . esc_html__( 'Upgrade to Pro', 'formidable' ) . '</b></a>';
350 + if ( FrmAddonsController::is_license_expired() ) {
351 + $label = __( 'Renew', 'formidable' );
352 + } else {
353 + $label = FrmSalesApi::get_best_sale_value( 'plugin_page_cta_text' );
354 + if ( ! $label ) {
355 + $label = __( 'Upgrade to Pro', 'formidable' );
356 + }
357 + }
358 +
359 + $upgrade_link = FrmSalesApi::get_best_sale_value( 'plugin_page_cta_link' );
360 + if ( ! $upgrade_link ) {
361 + $upgrade_link = FrmAppHelper::admin_upgrade_link( 'plugin-row' );
362 + }
363 +
364 + $settings[] = '<a href="' . esc_url( $upgrade_link ) . '" target="_blank" rel="noopener"><b style="color:#1da867;font-weight:700;">' . esc_html( $label ) . '</b></a>';
291 365 }
292 366
293 367 $settings[] = '<a href="' . esc_url( admin_url( 'admin.php?page=formidable' ) ) . '">' . __( 'Build a Form', 'formidable' ) . '</a>';
294 368
@@ -299,9 +373,9 @@
299 373 * @return void
300 374 */
301 375 public static function pro_get_started_headline() {
302 376 self::review_request();
303 - FrmAppHelper::min_pro_version_notice( '4.0' );
377 + FrmAppHelper::min_pro_version_notice( '6.0' );
304 378 }
305 379
306 380 /**
307 381 * Add admin notices as needed for reviews
@@ -368,63 +442,26 @@
368 442 $shared_path = $plugin_path . '/classes/views/shared/';
369 443
370 444 include $shared_path . 'upgrade_overlay.php';
371 445 include $shared_path . 'confirm-overlay.php';
372 -
373 - if ( FrmAppHelper::is_admin_page( 'formidable-welcome' ) || FrmAppHelper::on_form_listing_page() ) {
374 - self::new_form_overlay_html();
375 - }
376 446 }
377 447
378 448 /**
449 + * Create a basic form with an email field.
450 + *
451 + * @param string $form_key
452 + * @param string $title
453 + * @param string $description
379 454 * @return void
380 455 */
381 - private static function new_form_overlay_html() {
382 - FrmFormsController::before_list_templates();
383 -
384 - $plugin_path = FrmAppHelper::plugin_path();
385 - $path = $plugin_path . '/classes/views/frm-forms/';
386 - $expired = FrmFormsController::expired();
387 - $expiring = FrmAddonsController::is_license_expiring();
388 - $user = wp_get_current_user(); // $user used in leave-email.php to determine a default value for field
389 - $view_path = $path . 'new-form-overlay/';
390 - $modal_class = '';
391 - $upgrade_link = FrmAppHelper::admin_upgrade_link(
392 - array(
393 - 'medium' => 'new-template',
394 - 'content' => 'upgrade',
395 - )
456 + public static function api_email_form( $form_key, $title = '', $description = '' ) {
457 + $user = wp_get_current_user();
458 + $args = array(
459 + 'api_url' => 'https://sandbox.formidableforms.com/api/wp-json/frm/v2/forms/' . $form_key . '?return=html&exclude_script=jquery&exclude_style=formidable-css',
460 + 'title' => $title,
461 + 'description' => $description,
396 462 );
397 - $renew_link = FrmAppHelper::admin_upgrade_link(
398 - array(
399 - 'medium' => 'new-template',
400 - 'content' => 'renew',
401 - )
402 - );
403 - $blocks_to_render = array();
404 -
405 - if ( ! FrmAppHelper::pro_is_installed() ) {
406 - // avoid rendering the email and code blocks for users who have upgraded or have a free license already
407 - $api = new FrmFormTemplateApi();
408 - if ( ! $api->has_free_access() ) {
409 - array_push( $blocks_to_render, 'email', 'code' );
410 - }
411 - }
412 -
413 - // avoid rendering the upgrade block for users with elite
414 - if ( 'elite' !== FrmAddonsController::license_type() ) {
415 - $blocks_to_render[] = 'upgrade';
416 - }
417 -
418 - // avoid rendering the renew block for users who are not currently expired
419 - if ( $expired ) {
420 - $blocks_to_render[] = 'renew';
421 - $modal_class = 'frm-expired';
422 - } elseif ( $expiring ) {
423 - $modal_class = 'frm-expiring';
424 - }
425 -
426 - include $path . 'new-form-overlay.php';
463 + require FrmAppHelper::plugin_path() . '/classes/views/form-templates/modals/leave-email-modal.php';
427 464 }
428 465
429 466 /**
430 467 * @return void
@@ -448,9 +485,8 @@
448 485 */
449 486 public static function remove_upsells() {
450 487 remove_action( 'frm_before_settings', 'FrmSettingsController::license_box' );
451 488 remove_action( 'frm_after_settings', 'FrmSettingsController::settings_cta' );
452 - remove_action( 'frm_add_form_style_tab_options', 'FrmFormsController::add_form_style_tab_options' );
453 489 remove_action( 'frm_after_field_options', 'FrmFormsController::logic_tip' );
454 490 }
455 491
456 492 /**
@@ -472,9 +508,9 @@
472 508 /**
473 509 * Check if the database is outdated
474 510 *
475 511 * @since 2.0.1
476 - * @return boolean
512 + * @return bool
477 513 */
478 514 public static function needs_update() {
479 515 $needs_upgrade = self::compare_for_update(
480 516 array(
@@ -521,19 +557,43 @@
521 557 *
522 558 * @return void
523 559 */
524 560 public static function admin_init() {
561 + if ( FrmAppHelper::get_param( 'delete_all' ) && FrmAppHelper::is_admin_page( 'formidable' ) && 'trash' === FrmAppHelper::get_param( 'form_type' ) ) {
562 + FrmFormsController::delete_all();
563 + }
564 +
525 565 if ( FrmAppHelper::is_admin_page( 'formidable' ) && 'duplicate' === FrmAppHelper::get_param( 'frm_action' ) ) {
526 566 FrmFormsController::duplicate();
527 567 }
528 568
569 + if ( FrmAppHelper::is_admin_page( 'formidable' ) && FrmAppHelper::simple_get( 'frm_add_tables' ) ) {
570 + self::add_missing_tables();
571 + }
572 +
529 573 if ( FrmAppHelper::is_style_editor_page() && 'save' === FrmAppHelper::get_param( 'frm_action' ) ) {
530 574 // Hook in earlier than FrmStylesController::route so we can redirect before the headers have been sent.
531 575 FrmStylesController::save_style();
532 576 }
533 577
534 - new FrmPersonalData(); // register personal data hooks
578 + if ( 'formidable-pro-upgrade' === FrmAppHelper::get_param( 'page' ) && ! FrmAppHelper::pro_is_installed() && current_user_can( 'frm_view_forms' ) ) {
579 + $redirect = FrmSalesApi::get_best_sale_value( 'menu_cta_link' );
580 + if ( ! $redirect ) {
581 + $redirect = FrmAppHelper::admin_upgrade_link(
582 + array(
583 + 'medium' => 'upgrade',
584 + 'content' => 'submenu-upgrade',
585 + )
586 + );
587 + }
535 588
589 + wp_redirect( $redirect );
590 + die();
591 + }
592 +
593 + // Register personal data hooks.
594 + new FrmPersonalData();
595 +
536 596 if ( ! FrmAppHelper::doing_ajax() && self::needs_update() ) {
537 597 self::network_upgrade_site();
538 598 }
539 599
@@ -541,82 +601,51 @@
541 601 // don't continue during ajax calls
542 602 self::admin_js();
543 603 }
544 604
605 + self::trigger_page_load_hooks();
606 +
545 607 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
546 - $action = FrmAppHelper::get_param( 'frm_action' );
608 + // Redirect to the "Form Templates" page if the 'frm_action' parameter matches specific actions.
609 + // This provides backward compatibility for old addons that use legacy modal templates.
610 + $action = FrmAppHelper::get_param( 'frm_action' );
611 + $trigger_name_modal = FrmAppHelper::get_param( 'triggerNewFormModal' );
612 + if ( $trigger_name_modal || in_array( $action, array( 'add_new', 'list_templates' ), true ) ) {
613 + $application_id = FrmAppHelper::simple_get( 'applicationId', 'absint' );
614 + $url_param = $application_id ? '&applicationId=' . $application_id : '';
547 615
548 - if ( in_array( $action, array( 'add_new', 'list_templates' ), true ) ) {
549 - wp_safe_redirect( admin_url( 'admin.php?page=formidable&triggerNewFormModal=1' ) );
616 + wp_safe_redirect( admin_url( 'admin.php?page=' . FrmFormTemplatesController::PAGE_SLUG . $url_param ) );
550 617 exit;
551 618 }
552 619
553 620 FrmInbox::maybe_disable_screen_options();
554 621 }
555 -
556 - self::maybe_add_ip_warning();
557 622 }
558 623
559 624 /**
560 - * Show a warning for the IP address setting if it hasn't been set.
625 + * Get the current page and check for a possible function to trigger.
626 + * If a class name matches the page name, and the class has a load_page() method, trigger it.
561 627 *
562 - * @since 6.1
628 + * @since 6.8
563 629 *
564 630 * @return void
565 631 */
566 - private static function maybe_add_ip_warning() {
567 - $settings = FrmAppHelper::get_settings();
568 - if ( false !== $settings->custom_header_ip ) {
569 - // The setting has been changed from the false default (to either 1 or 0), so stop showing the message.
632 + private static function trigger_page_load_hooks() {
633 + $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
634 + if ( strpos( $page, 'formidable-' ) !== 0 ) {
635 + // Only trigger hooks on Formidable pages.
570 636 return;
571 637 }
572 638
573 - if ( ! self::is_behind_proxy() ) {
574 - // This message is only applicable when using a reverse proxy.
575 - return;
639 + $page = str_replace( array( 'formidable-', '-' ), array( '', ' ' ), $page );
640 + $page = str_replace( ' ', '', ucwords( $page ) );
641 + $class = 'Frm' . $page . 'Controller';
642 + if ( class_exists( $class ) && method_exists( $class, 'load_page' ) ) {
643 + call_user_func( array( $class, 'load_page' ) );
576 644 }
577 -
578 - if ( FrmAppHelper::get_post_param( 'frm_action', '', 'sanitize_text_field' ) ) {
579 - // Avoid the message on a POST action. We don't want to show the message if we're saving global settings.
580 - return;
581 - }
582 -
583 - $global_settings_link = admin_url( 'admin.php?page=formidable-settings' ) . '#frm_custom_header_ip';
584 - $message = sprintf(
585 - // Translators: 1: Global Settings Link
586 - __( 'IP addresses in form submissions may no longer be accurate! If you are experiencing issues, we recommend going to %1$s and enabling the "Use custom headers when retrieving IPs with form submissions." setting.', 'formidable' ),
587 - '<a href="' . esc_url( $global_settings_link ) . '">Global Settings</a>'
588 - );
589 - $option_name = 'frm_dismiss_ip_address_notice';
590 - FrmAppHelper::add_dismissable_warning_message( $message, $option_name );
591 645 }
592 646
593 647 /**
594 - * Check if any reverse proxy headers are set.
595 - *
596 - * @since 6.1
597 - *
598 - * @return bool
599 - */
600 - private static function is_behind_proxy() {
601 - $custom_headers = FrmAppHelper::get_custom_header_keys_for_ip();
602 - foreach ( $custom_headers as $header ) {
603 - if ( 'REMOTE_ADDR' === $header ) {
604 - // We want to check every key but REMOTE_ADDR. REMOTE_ATTR is not unique to reverse proxy servers.
605 - continue;
606 - }
607 -
608 - $ip = trim( FrmAppHelper::get_server_value( $header ) );
609 - // Return true for anything that isn't empty but ignoring values like ::1.
610 - if ( $ip && 0 !== strpos( $ip, '::' ) ) {
611 - return true;
612 - }
613 - }
614 -
615 - return false;
616 - }
617 -
618 - /**
619 648 * @return void
620 649 */
621 650 public static function admin_js() {
622 651 $plugin_url = FrmAppHelper::plugin_url();
@@ -623,8 +652,17 @@
623 652 $version = FrmAppHelper::plugin_version();
624 653
625 654 FrmAppHelper::load_admin_wide_js();
626 655
656 + // Register component assets early to ensure they can be enqueued later in controllers.
657 + wp_register_style( 'formidable-animations', $plugin_url . '/css/admin/animations.css', array(), $version );
658 +
659 + if ( class_exists( 'FrmOverlayController' ) ) {
660 + // This should always exist.
661 + // But it may not have loaded properly when updating the plugin.
662 + FrmOverlayController::register_assets();
663 + }
664 +
627 665 wp_register_style( 'formidable_admin_global', $plugin_url . '/css/admin/frm_admin_global.css', array(), $version );
628 666 wp_enqueue_style( 'formidable_admin_global' );
629 667
630 668 wp_register_style( 'formidable-admin', $plugin_url . '/css/frm_admin.css', array(), $version );
@@ -633,28 +671,19 @@
633 671 wp_register_script( 'formidable_dom', $plugin_url . '/js/admin/dom.js', array( 'jquery', 'jquery-ui-dialog', 'wp-i18n' ), $version, true );
634 672 wp_register_script( 'formidable_embed', $plugin_url . '/js/admin/embed.js', array( 'formidable_dom', 'jquery-ui-autocomplete' ), $version, true );
635 673 self::register_popper1();
636 674 wp_register_script( 'bootstrap_tooltip', $plugin_url . '/js/bootstrap.min.js', array( 'jquery', 'popper' ), '4.6.1', true );
675 +
676 + $settings_js_vars = array(
677 + 'currencies' => FrmCurrencyHelper::get_currencies(),
678 + );
637 679 wp_register_script( 'formidable_settings', $plugin_url . '/js/admin/settings.js', array(), $version, true );
680 + wp_localize_script( 'formidable_settings', 'frmSettings', $settings_js_vars );
638 681
639 - $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
640 -
641 - // Enqueue Floating Links.
642 - $is_valid_page =
643 - FrmAppHelper::is_formidable_admin() &&
644 - ! FrmAppHelper::is_style_editor_page() &&
645 - ! FrmAppHelper::is_admin_page( 'formidable-views-editor' ) &&
646 - ! FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
647 - if ( $is_valid_page ) {
682 + if ( self::should_show_floating_links() ) {
648 683 self::enqueue_floating_links( $plugin_url, $version );
649 684 }
650 - unset( $is_valid_page );
651 685
652 - if ( 'formidable-applications' === $page ) {
653 - FrmApplicationsController::load_assets();
654 - return;
655 - }
656 -
657 686 $dependencies = array(
658 687 'formidable_admin_global',
659 688 'jquery',
660 689 'jquery-ui-core',
@@ -662,9 +691,10 @@
662 691 'jquery-ui-sortable',
663 692 'bootstrap_tooltip',
664 693 'bootstrap-multiselect',
665 694 'wp-i18n',
666 - 'wp-hooks', // Required in WP versions older than 5.7
695 + // Required in WP versions older than 5.7
696 + 'wp-hooks',
667 697 'formidable_dom',
668 698 'formidable_embed',
669 699 );
670 700
@@ -681,8 +711,20 @@
681 711 }
682 712
683 713 wp_register_script( 'bootstrap-multiselect', $plugin_url . '/js/bootstrap-multiselect.js', array( 'jquery', 'bootstrap_tooltip', 'popper' ), '1.1.1', true );
684 714
715 + if ( ! class_exists( 'FrmTransHooksController', false ) ) {
716 + /**
717 + * Gateway fields are included for add-on compatibility but we do not want it to be visible.
718 + * They do however need to be visible when the payments submodule is active.
719 + */
720 + wp_add_inline_style(
721 + 'formidable-admin',
722 + '#frm_builder_page li[data-ftype="gateway"] { display: none; }'
723 + );
724 + }
725 +
726 + $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
685 727 $post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title' );
686 728
687 729 global $pagenow;
688 730 if ( strpos( $page, 'formidable' ) === 0 || ( $pagenow === 'edit.php' && $post_type === 'frm_display' ) ) {
@@ -690,15 +732,18 @@
690 732 wp_enqueue_script( 'admin-widgets' );
691 733 wp_enqueue_style( 'widgets' );
692 734 self::maybe_deregister_popper2();
693 735 wp_enqueue_script( 'formidable_admin' );
736 + wp_set_script_translations( 'formidable_admin', 'formidable' );
694 737 wp_enqueue_script( 'formidable_embed' );
738 + wp_set_script_translations( 'formidable_embed', 'formidable' );
695 739 FrmAppHelper::localize_script( 'admin' );
696 740
741 + wp_enqueue_style( 'formidable-animations' );
697 742 wp_enqueue_style( 'formidable-admin' );
698 743 if ( 'formidable-styles' !== $page && 'formidable-styles2' !== $page ) {
699 744 wp_enqueue_style( 'formidable-grids' );
700 - wp_enqueue_style( 'formidable-dropzone' );
745 + self::maybe_enqueue_dropzone_css( $page );
701 746 } else {
702 747 wp_enqueue_style( 'formidable-grids' );
703 748 }
704 749
@@ -704,8 +749,12 @@
704 749
705 750 if ( 'formidable-entries' === $page ) {
706 751 // Load front end js for entries.
707 752 wp_enqueue_script( 'formidable' );
753 +
754 + // Registers and enqueues the entries page scripts.
755 + wp_register_script( 'formidable_entries', $plugin_url . '/js/admin/entries.js', array( 'formidable_admin', 'wp-dom-ready' ), $version, true );
756 + wp_enqueue_script( 'formidable_entries' );
708 757 }
709 758
710 759 do_action( 'frm_enqueue_builder_scripts' );
711 760 self::include_upgrade_overlay();
@@ -725,13 +774,55 @@
725 774
726 775 if ( $post_type === 'frm_display' ) {
727 776 self::enqueue_legacy_views_assets();
728 777 }
778 + }//end if
779 +
780 + if ( 'formidable-addons' === $page ) {
781 + wp_register_script( 'formidable_addons', $plugin_url . '/js/admin/addons.js', array( 'formidable_admin', 'wp-dom-ready' ), $version, true );
782 + wp_enqueue_script( 'formidable_addons' );
729 783 }
784 + }
730 785
786 + /**
787 + * Avoid loading dropzone CSS on the form list page. It isn't required there.
788 + *
789 + * @since 6.11
790 + *
791 + * @param string $page
792 + * @return void
793 + */
794 + private static function maybe_enqueue_dropzone_css( $page ) {
795 + if ( ! FrmAppHelper::pro_is_installed() ) {
796 + return;
797 + }
798 +
799 + $should_avoid_loading_dropzone = 'formidable' === $page && ! FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
800 + if ( ! $should_avoid_loading_dropzone ) {
801 + wp_enqueue_style( 'formidable-dropzone' );
802 + }
731 803 }
732 804
733 805 /**
806 + * The floating links are not shown on every page.
807 + * They are also not shown if white labeling is being used.
808 + *
809 + * @since 6.8.4
810 + *
811 + * @return bool
812 + */
813 + private static function should_show_floating_links() {
814 + if ( ! FrmAppHelper::is_formidable_branding() ) {
815 + return false;
816 + }
817 +
818 + return FrmAppHelper::is_formidable_admin() &&
819 + ! FrmAppHelper::is_style_editor_page() &&
820 + ! FrmAppHelper::is_admin_page( 'formidable-views-editor' ) &&
821 + ! FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
822 + }
823 +
824 + /**
734 825 * @since 6.3.2
735 826 *
736 827 * @return void
737 828 */
@@ -737,8 +828,14 @@
737 828 */
738 829 public static function admin_enqueue_scripts() {
739 830 self::load_wp_admin_style();
740 831 self::maybe_force_formidable_block_on_gutenberg_page();
832 +
833 + if ( FrmAppHelper::is_admin_page( 'formidable-settings' ) ) {
834 + wp_enqueue_style( FrmDashboardController::PAGE_SLUG, FrmAppHelper::plugin_url() . '/css/admin/dashboard.css', array(), FrmAppHelper::plugin_version() );
835 + }
836 +
837 + FrmUsageController::load_scripts();
741 838 }
742 839
743 840 /**
744 841 * Enqueue required assets for the Legacy Views editor (Views v4.x).
@@ -807,12 +904,45 @@
807 904 *
808 905 * @return void
809 906 */
810 907 private static function register_popper1() {
908 + if ( ! self::should_register_popper() ) {
909 + return;
910 + }
811 911 wp_register_script( 'popper', FrmAppHelper::plugin_url() . '/js/popper.min.js', array( 'jquery' ), '1.16.0', true );
812 912 }
813 913
814 914 /**
915 + * Only register popper on Formidable pages.
916 + * This helps to avoid popper conflicts on other plugin pages, including the WP Bakery page editor.
917 + *
918 + * @since 6.11.1
919 + *
920 + * @return bool
921 + */
922 + private static function should_register_popper() {
923 + global $pagenow;
924 +
925 + $post_id = FrmAppHelper::simple_get( 'post', 'absint' );
926 + if ( 'post.php' === $pagenow && $post_id && 'frm_display' === get_post_type( $post_id ) ) {
927 + return true;
928 + }
929 +
930 + $post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title' );
931 + $is_views_post_type = 'frm_display' === $post_type;
932 + if ( in_array( $pagenow, array( 'post-new.php', 'edit.php' ), true ) && $is_views_post_type ) {
933 + return true;
934 + }
935 +
936 + $page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
937 + if ( strpos( $page, 'formidable' ) === 0 ) {
938 + return true;
939 + }
940 +
941 + return in_array( $pagenow, array( 'term.php', 'edit-tags.php' ), true ) && FrmAppHelper::simple_get( 'taxonomy' ) === 'frm_application';
942 + }
943 +
944 + /**
815 945 * Automatically insert a Formidable block when loading Gutenberg when $_GET['frmForm' is set.
816 946 *
817 947 * @since 5.2
818 948 *
@@ -871,10 +1001,10 @@
871 1001 * @return void
872 1002 */
873 1003 public static function create_rest_routes() {
874 1004 $args = array(
875 - 'methods' => 'GET',
876 - 'callback' => 'FrmAppController::api_install',
1005 + 'methods' => 'GET',
1006 + 'callback' => 'FrmAppController::api_install',
877 1007 'permission_callback' => __CLASS__ . '::can_update_db',
878 1008 );
879 1009
880 1010 register_rest_route( 'frm-admin/v1', '/install', $args );
@@ -879,10 +1009,10 @@
879 1009
880 1010 register_rest_route( 'frm-admin/v1', '/install', $args );
881 1011
882 1012 $args = array(
883 - 'methods' => 'GET',
884 - 'callback' => 'FrmAddonsController::install_addon_api',
1013 + 'methods' => 'GET',
1014 + 'callback' => 'FrmAddonsController::install_addon_api',
885 1015 'permission_callback' => 'FrmAddonsController::can_install_addon_api',
886 1016 );
887 1017
888 1018 register_rest_route( 'frm-admin/v1', '/install-addon', $args );
@@ -995,9 +1125,9 @@
995 1125
996 1126 $frmdb = new FrmMigrate();
997 1127 $frmdb->uninstall();
998 1128
999 - //disable the plugin and redirect after uninstall so the tables don't get added right back
1129 + // Disable the plugin and redirect after uninstall so the tables don't get added right back.
1000 1130 $plugins = array( FrmAppHelper::plugin_folder() . '/formidable.php', 'formidable-pro/formidable-pro.php' );
1001 1131 deactivate_plugins( $plugins, false, false );
1002 1132 echo esc_url_raw( admin_url( 'plugins.php?deactivate=true' ) );
1003 1133
@@ -1027,8 +1157,33 @@
1027 1157 delete_site_option( 'frmpro-authorized' );
1028 1158 wp_die();
1029 1159 }
1030 1160
1161 + /**
1162 + * This is triggered when Formidable is activated.
1163 + *
1164 + * @return void
1165 + */
1166 + public static function handle_activation() {
1167 + self::maybe_activate_payment_cron();
1168 + }
1169 +
1170 + /**
1171 + * The payment cron is unscheduled when Formidable is deactivated.
1172 + * We need to add it back again on activation if Stripe is configured.
1173 + *
1174 + * @since 6.5
1175 + *
1176 + * @return void
1177 + */
1178 + private static function maybe_activate_payment_cron() {
1179 + if ( ! FrmStrpLiteConnectHelper::stripe_connect_is_setup() ) {
1180 + return;
1181 + }
1182 +
1183 + FrmTransLiteAppController::maybe_schedule_cron();
1184 + }
1185 +
1031 1186 public static function set_footer_text( $text ) {
1032 1187 if ( FrmAppHelper::is_formidable_admin() ) {
1033 1188 $text = '';
1034 1189 }
@@ -1043,57 +1198,72 @@
1043 1198 *
1044 1199 * @return void
1045 1200 */
1046 1201 public static function add_admin_footer_links() {
1047 - $post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title' );
1048 -
1049 - if ( ( ! FrmAppHelper::is_formidable_admin() && $post_type !== 'frm_logs' ) || FrmAppHelper::is_full_screen() ) {
1050 - return;
1202 + FrmFormsController::include_device_too_small_message();
1203 + if ( self::should_show_footer_links() ) {
1204 + include FrmAppHelper::plugin_path() . '/classes/views/shared/admin-footer-links.php';
1051 1205 }
1052 -
1053 - include FrmAppHelper::plugin_path() . '/classes/views/shared/admin-footer-links.php';
1054 1206 }
1055 1207
1056 1208 /**
1057 - * @deprecated 3.0.04
1209 + * Check if the footer links should be shown.
1058 1210 *
1059 - * @codeCoverageIgnore
1211 + * @since 6.7
1060 1212 *
1061 - * @return void
1213 + * @return bool
1062 1214 */
1063 - public static function activation_install() {
1064 - FrmDeprecated::activation_install();
1065 - }
1215 + private static function should_show_footer_links() {
1216 + $post_type = FrmAppHelper::simple_get( 'post_type', 'sanitize_title' );
1217 + $is_formidable_page = FrmAppHelper::is_formidable_admin() || 'frm_logs' === $post_type;
1218 + $show_footer_links = $is_formidable_page;
1219 + if ( FrmAppHelper::is_full_screen() || ! FrmAppHelper::is_formidable_branding() ) {
1220 + $show_footer_links = false;
1221 + }
1066 1222
1067 - /**
1068 - * @deprecated 3.0
1069 - * @codeCoverageIgnore
1070 - */
1071 - public static function page_route( $content ) {
1072 - return FrmDeprecated::page_route( $content );
1223 + /**
1224 + * Filter whether to show the Formidable footer links.
1225 + *
1226 + * @since 6.7
1227 + *
1228 + * @param bool $show_footer_links
1229 + * @return bool
1230 + */
1231 + return apply_filters( 'frm_show_footer_links', $show_footer_links );
1073 1232 }
1074 1233
1075 1234 /**
1076 - * Include icons on page for Embed Form modal.
1235 + * Show an error modal and terminate the script execution.
1077 1236 *
1078 - * @since 5.2
1237 + * @since 6.7
1079 1238 *
1239 + * @param array $error_args Arguments that control the behavior of the error modal.
1240 + *
1080 1241 * @return void
1081 1242 */
1082 - public static function include_embed_form_icons() {
1083 - _deprecated_function( __METHOD__, '5.3' );
1084 - }
1243 + public static function show_error_modal( $error_args ) {
1244 + add_filter( 'frm_show_footer_links', '__return_false' );
1085 1245
1086 - /**
1087 - * @deprecated 1.07.05 This is still referenced in the API add on as of v1.13.
1088 - * @codeCoverageIgnore
1089 - *
1090 - * @param array $atts
1091 - * @return string
1092 - */
1093 - public static function get_form_shortcode( $atts ) {
1094 - _deprecated_function( __FUNCTION__, '1.07.05', 'FrmFormsController::get_form_shortcode' );
1095 - return FrmFormsController::get_form_shortcode( $atts );
1246 + $defaults = array(
1247 + 'title' => '',
1248 + 'body' => '',
1249 + 'cancel_url' => '',
1250 + 'cancel_classes' => '',
1251 + 'continue_url' => '',
1252 + 'continue_classes' => '',
1253 + 'icon' => 'frm_lock_simple',
1254 + );
1255 +
1256 + $error_args = wp_parse_args( $error_args, $defaults );
1257 + if ( ! isset( $error_args['cancel_text'] ) && ! empty( $error_args['cancel_url'] ) ) {
1258 + $error_args['cancel_text'] = __( 'Cancel', 'formidable' );
1259 + }
1260 +
1261 + if ( ! isset( $error_args['continue_text'] ) && ! empty( $error_args['continue_url'] ) ) {
1262 + $error_args['continue_text'] = __( 'Continue', 'formidable' );
1263 + }
1264 +
1265 + include FrmAppHelper::plugin_path() . '/classes/views/frm-forms/error-modal.php';
1096 1266 }
1097 1267
1098 1268 /**
1099 1269 * Handles Floating Links' scripts and styles enqueueing.
@@ -1113,15 +1283,228 @@
1113 1283 // Enqueue the Floating Links styles.
1114 1284 wp_enqueue_style( 's11-floating-links', $plugin_url . '/css/packages/s11-floating-links.css', array(), $version );
1115 1285
1116 1286 // Enqueue the Floating Links script.
1117 - wp_enqueue_script( 's11-floating-links', $plugin_url . '/js/packages/floating-links/s11-floating-links.js', array(), $version, true );
1287 + wp_enqueue_script( 's11-floating-links', $plugin_url . '/js/packages/floating-links/s11-floating-links.js', array( 'formidable_admin' ), $version, true );
1118 1288
1119 1289 // Enqueue the config script.
1120 1290 wp_enqueue_script( 's11-floating-links-config', $plugin_url . '/js/packages/floating-links/config.js', array( 'wp-i18n' ), $version, true );
1121 - wp_set_script_translations( 's11-floating-links-config', 's11-' );
1291 +
1292 + if ( function_exists( 'wp_set_script_translations' ) ) {
1293 + wp_set_script_translations( 's11-floating-links-config', 's11-' );
1294 + }
1295 +
1122 1296 $floating_links_data = array(
1123 1297 'proIsInstalled' => FrmAppHelper::pro_is_installed(),
1124 1298 );
1125 1299 wp_localize_script( 's11-floating-links-config', 's11FloatingLinksData', $floating_links_data );
1300 +
1301 + /**
1302 + * Prompt Pro to load additional floating links scripts.
1303 + * This is used to include images in the Inbox SlideIn when Pro is active.
1304 + *
1305 + * @since 6.8.4
1306 + */
1307 + do_action( 'frm_enqueue_floating_links' );
1308 + }
1309 +
1310 + /**
1311 + * Check if we are in our admin pages.
1312 + *
1313 + * @return bool
1314 + */
1315 + private static function in_our_pages() {
1316 + global $current_screen, $pagenow;
1317 + if ( FrmAppHelper::is_formidable_admin() ) {
1318 + return true;
1319 + }
1320 +
1321 + if ( ! empty( $current_screen->post_type ) && 'frm_logs' === $current_screen->post_type ) {
1322 + return true;
1323 + }
1324 +
1325 + if ( in_array( $pagenow, array( 'term.php', 'edit-tags.php' ), true ) && 'frm_application' === FrmAppHelper::simple_get( 'taxonomy' ) ) {
1326 + return true;
1327 + }
1328 +
1329 + return false;
1330 + }
1331 +
1332 + /**
1333 + * Handles actions related to the current screen.
1334 + *
1335 + * @since 6.19
1336 + *
1337 + * @return void
1338 + */
1339 + public static function handle_current_screen() {
1340 + if ( ! self::in_our_pages() ) {
1341 + return;
1342 + }
1343 +
1344 + self::filter_admin_notices();
1345 + self::remember_custom_sort();
1346 + }
1347 +
1348 + /**
1349 + * Hide all third-parties admin notices only in our admin pages.
1350 + *
1351 + * @return void
1352 + */
1353 + public static function filter_admin_notices() {
1354 + $actions = array(
1355 + 'admin_notices',
1356 + 'network_admin_notices',
1357 + 'user_admin_notices',
1358 + 'all_admin_notices',
1359 + );
1360 +
1361 + global $wp_filter;
1362 +
1363 + foreach ( $actions as $action ) {
1364 + if ( empty( $wp_filter[ $action ]->callbacks ) ) {
1365 + continue;
1366 + }
1367 + foreach ( $wp_filter[ $action ]->callbacks as $priority => $callbacks ) {
1368 + foreach ( $callbacks as $callback_name => $callback ) {
1369 + if ( self::is_our_callback_string( $callback_name ) || self::is_our_callback_array( $callback ) ) {
1370 + continue;
1371 + }
1372 + unset( $wp_filter[ $action ]->callbacks[ $priority ][ $callback_name ] );
1373 + }
1374 + }
1375 + }
1376 + }
1377 +
1378 + /**
1379 + * Remembers and applies user-specific sorting preferences.
1380 + *
1381 + * @return void
1382 + */
1383 + private static function remember_custom_sort() {
1384 + $screen = get_current_screen();
1385 + if ( ! $screen ) {
1386 + return;
1387 + }
1388 +
1389 + if ( ! FrmAppHelper::is_admin_list_page() && ! FrmAppHelper::is_admin_list_page( 'formidable-entries' ) ) {
1390 + return;
1391 + }
1392 +
1393 + $orderby = FrmAppHelper::get_param( 'orderby' );
1394 +
1395 + if ( ! $orderby ) {
1396 + return;
1397 + }
1398 +
1399 + $user_id = get_current_user_id();
1400 + $meta_key = 'frm_preferred_list_sort_' . $screen->id;
1401 + $order = FrmAppHelper::get_param( 'order' );
1402 +
1403 + $new_sort = array(
1404 + 'orderby' => $orderby,
1405 + 'order' => $order,
1406 + );
1407 +
1408 + $current_sort = get_user_meta( $user_id, $meta_key, true );
1409 +
1410 + if ( $new_sort !== $current_sort ) {
1411 + update_user_meta(
1412 + $user_id,
1413 + $meta_key,
1414 + array(
1415 + 'orderby' => $orderby,
1416 + 'order' => $order,
1417 + )
1418 + );
1419 + }
1420 + }
1421 +
1422 + /**
1423 + * Retrieve and apply any saved sorting preferences for the current screen.
1424 + *
1425 + * @since 6.19
1426 + *
1427 + * @param string &$orderby Reference to the current 'orderby' parameter.
1428 + * @param string &$order Reference to the current 'order' parameter.
1429 + * @return void
1430 + */
1431 + public static function apply_saved_sort_preference( &$orderby, &$order ) {
1432 + if ( ! function_exists( 'get_current_screen' ) ) {
1433 + return;
1434 + }
1435 +
1436 + $screen = get_current_screen();
1437 + if ( ! $screen ) {
1438 + return;
1439 + }
1440 +
1441 + $user_id = get_current_user_id();
1442 + $preferred_list_sort = get_user_meta( $user_id, 'frm_preferred_list_sort_' . $screen->id, true );
1443 +
1444 + if ( is_array( $preferred_list_sort ) && ! empty( $preferred_list_sort['orderby'] ) ) {
1445 + $orderby = $preferred_list_sort['orderby'];
1446 +
1447 + if ( ! empty( $preferred_list_sort['order'] ) ) {
1448 + $order = $preferred_list_sort['order'];
1449 + }
1450 + }
1451 + }
1452 +
1453 + /**
1454 + * Validate that the callback name is ours not from third-party.
1455 + *
1456 + * @param string $callback_name WordPress callback name.
1457 + *
1458 + * @return bool
1459 + */
1460 + private static function is_our_callback_string( $callback_name ) {
1461 + return 0 === stripos( $callback_name, 'frm' );
1462 + }
1463 +
1464 + /**
1465 + * Validate that the callback array is ours not from third-party.
1466 + *
1467 + * @param array $callback WordPress callback array.
1468 + *
1469 + * @return bool
1470 + */
1471 + private static function is_our_callback_array( $callback ) {
1472 + return ! empty( $callback['function'] ) &&
1473 + is_array( $callback['function'] ) &&
1474 + ! empty( $callback['function'][0] ) &&
1475 + self::is_our_callback_string( is_object( $callback['function'][0] ) ? get_class( $callback['function'][0] ) : $callback['function'][0] );
1476 + }
1477 +
1478 + /**
1479 + * In some cases, the DB tables may fail to install.
1480 + * This function tries to add them again when the user clicks the link to try again
1481 + * from the given inbox notice.
1482 + *
1483 + * @since 6.19
1484 + */
1485 + private static function add_missing_tables() {
1486 + FrmAppHelper::permission_check( 'frm_view_forms' );
1487 +
1488 + $inbox = new FrmInbox();
1489 + $error = $inbox->check_for_error();
1490 +
1491 + if ( ! $error || 'failed-to-create-tables' !== $error['key'] ) {
1492 + // Confirm the inbox item with this CTA exists.
1493 + wp_safe_redirect( admin_url( 'admin.php?page=formidable' ) );
1494 + exit;
1495 + }
1496 +
1497 + global $wpdb;
1498 + $exists = $wpdb->get_results( $wpdb->prepare( 'SHOW TABLES LIKE %s', $wpdb->prefix . 'frm_forms' ) );
1499 +
1500 + if ( $exists ) {
1501 + // Exit early if the table already exists.
1502 + wp_safe_redirect( admin_url( 'admin.php?page=formidable' ) );
1503 + exit;
1504 + }
1505 +
1506 + delete_option( 'frm_db_version' );
1507 + wp_safe_redirect( admin_url( 'admin.php?page=formidable' ) );
1508 + exit;
1126 1509 }
1127 1510 }