PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.16
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.16
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/models/FrmSolution.php +31 -108 6.296.16 View file →
@@ -3,9 +3,8 @@
3 3 * Handles the installation of a solution and any dependencies.
4 4 * This page is shown when a Formidable plugin is activated.
5 5 *
6 6 * @since 4.06.02
7 - *
8 7 * @package Formidable
9 8 */
10 9
11 10 if ( ! defined( 'ABSPATH' ) ) {
@@ -13,16 +12,10 @@
13 12 }
14 13
15 14 class FrmSolution {
16 15
17 - /**
18 - * @var string
19 - */
20 16 protected $plugin_slug = '';
21 17
22 - /**
23 - * @var string
24 - */
25 18 protected $plugin_file = '';
26 19
27 20 /**
28 21 * Hidden welcome page slug.
@@ -27,23 +20,16 @@
27 20 /**
28 21 * Hidden welcome page slug.
29 22 *
30 23 * @since 4.06.02
31 - *
32 24 * @var string
33 25 */
34 26 protected $page = '';
35 27
36 - /**
37 - * @var string
38 - */
39 - protected $icon = 'frmfont frm_settings_icon';
28 + protected $icon = 'frm_icon_font frm_settings_icon';
40 29
41 - /**
42 - * @param array $atts
43 - */
44 30 public function __construct( $atts = array() ) {
45 - if ( ! $this->plugin_slug ) {
31 + if ( empty( $this->plugin_slug ) ) {
46 32 return;
47 33 }
48 34
49 35 add_action( 'plugins_loaded', array( $this, 'load_hooks' ), 50 );
@@ -48,9 +34,9 @@
48 34
49 35 add_action( 'plugins_loaded', array( $this, 'load_hooks' ), 50 );
50 36 add_action( 'admin_init', array( $this, 'redirect' ), 9999 );
51 37
52 - if ( ! $this->plugin_file ) {
38 + if ( empty( $this->plugin_file ) ) {
53 39 $this->plugin_file = $this->plugin_slug . '.php';
54 40 }
55 41 }
56 42
@@ -82,16 +68,11 @@
82 68 add_action( 'admin_menu', array( $this, 'register' ) );
83 69 add_action( 'admin_head', array( $this, 'hide_menu' ) );
84 70 }
85 71
86 - /**
87 - * @param array $links
88 - *
89 - * @return array
90 - */
91 72 public function plugin_links( $links ) {
92 73 if ( ! $this->is_complete() ) {
93 - $settings = '<a href="' . esc_url( $this->settings_link() ) . '">' . esc_html__( 'Setup', 'formidable' ) . '</a>';
74 + $settings = '<a href="' . esc_url( $this->settings_link() ) . '">' . __( 'Setup', 'formidable' ) . '</a>';
94 75 array_unshift( $links, $settings );
95 76 }
96 77
97 78 return $links;
@@ -107,8 +88,9 @@
107 88 *
108 89 * @return void
109 90 */
110 91 public function register() {
92 +
111 93 // Getting started - shows after installation.
112 94 add_dashboard_page(
113 95 esc_html( $this->page_title() ),
114 96 esc_html( $this->page_title() ),
@@ -164,10 +146,10 @@
164 146 *
165 147 * @return void
166 148 */
167 149 public function redirect() {
150 +
168 151 $current_page = FrmAppHelper::simple_get( 'page', 'sanitize_title' );
169 -
170 152 if ( $current_page === $this->page ) {
171 153 // Prevent endless loop.
172 154 return;
173 155 }
@@ -197,12 +179,8 @@
197 179 }
198 180
199 181 /**
200 182 * Add page to global settings.
201 - *
202 - * @param array $sections Sections.
203 - *
204 - * @return array
205 183 */
206 184 public function add_settings( $sections ) {
207 185 wp_enqueue_style( 'formidable-pro-fields' );
208 186 $sections[ $this->plugin_slug ] = array(
@@ -222,9 +200,8 @@
222 200 * @return void
223 201 */
224 202 public function settings_page() {
225 203 $steps = $this->get_steps_data();
226 -
227 204 if ( ! $steps['license']['complete'] || ( isset( $steps['plugin'] ) && ! $steps['plugin']['complete'] ) ) {
228 205 // Redirect to the welcome page if install hasn't been done.
229 206 $url = $this->settings_link();
230 207 echo '<script>window.location.replace("' . esc_url_raw( $url ) . '");</script>';
@@ -230,9 +207,10 @@
230 207 echo '<script>window.location.replace("' . esc_url_raw( $url ) . '");</script>';
231 208 return;
232 209 }
233 210
234 - $all_imported = $this->is_complete( 'all' );
211 + $all_imported = $this->is_complete( 'all' );
212 +
235 213 $step = $steps['import'];
236 214 $step['label'] = '';
237 215 $step['nested'] = true;
238 216
@@ -242,24 +220,19 @@
242 220
243 221 $new_class = $all_imported ? ' button frm_hidden' : '';
244 222 $step['button_class'] = str_replace( 'frm_grey disabled', $new_class, $step['button_class'] );
245 223 }
246 -
247 224 if ( $all_imported ) {
248 225 $step['description'] = __( 'The following form(s) have been created.', 'formidable' );
249 226 }
250 -
251 227 $this->show_app_install( $step );
252 228
253 - if ( $all_imported ) {
254 - return;
229 + if ( ! $all_imported ) {
230 + $step = $steps['complete'];
231 + $step['current'] = false;
232 + $step['button_class'] .= ' frm_grey disabled';
233 + $this->show_page_links( $step );
255 234 }
256 -
257 - $step = $steps['complete'];
258 - $step['current'] = false;
259 - $step['button_class'] .= ' frm_grey disabled';
260 -
261 - $this->show_page_links( $step );
262 235 }
263 236
264 237 /**
265 238 * Getting Started screen. Shows after first install.
@@ -289,9 +262,8 @@
289 262 'height' => 90,
290 263 'width' => 90,
291 264 );
292 265
293 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
294 266 ?>
295 267 <section class="top">
296 268 <div class="frm-smtp-logos">
297 269 <?php FrmAppHelper::show_logo( $size ); ?>
@@ -315,9 +287,8 @@
315 287 <h1><?php echo esc_html( $this->page_title() ); ?></h1>
316 288 <p><?php echo esc_html( $this->page_description() ); ?></p>
317 289 </section>
318 290 <?php
319 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
320 291 }
321 292
322 293 /**
323 294 * This is the welcome page content.
@@ -327,9 +298,8 @@
327 298 */
328 299 protected function main_content() {
329 300 $steps = $this->get_steps_data();
330 301 $this->license_box( $steps['license'] );
331 -
332 302 if ( isset( $steps['plugin'] ) ) {
333 303 $this->show_plugin_install( $steps['plugin'] );
334 304 }
335 305 $this->show_app_install( $steps['import'] );
@@ -335,11 +305,8 @@
335 305 $this->show_app_install( $steps['import'] );
336 306 $this->show_page_links( $steps['complete'] );
337 307 }
338 308
339 - /**
340 - * @return array
341 - */
342 309 protected function get_steps_data() {
343 310 $pro_installed = FrmAppHelper::pro_is_connected();
344 311
345 312 $steps = array(
@@ -346,9 +313,9 @@
346 313 'license' => array(
347 314 'label' => __( 'Connect to FormidableForms.com', 'formidable' ),
348 315 'description' => __( 'Create a connection to get plugin downloads.', 'formidable' ),
349 316 'button_label' => __( 'Connect an Account', 'formidable' ),
350 - 'current' => ! $pro_installed,
317 + 'current' => empty( $pro_installed ),
351 318 'complete' => $pro_installed,
352 319 'num' => 1,
353 320 ),
354 321 'plugin' => array(
@@ -377,9 +344,8 @@
377 344
378 345 $this->adjust_plugin_install_step( $steps );
379 346
380 347 $has_current = false;
381 -
382 348 foreach ( $steps as $k => $step ) {
383 349 // Set the current step.
384 350 if ( ! isset( $step['current'] ) ) {
385 351 if ( $step['complete'] ) {
@@ -392,11 +358,10 @@
392 358 $has_current = true;
393 359 }
394 360
395 361 // Set disabled buttons.
396 - $class = $step['button_class'] ?? '';
362 + $class = isset( $step['button_class'] ) ? $step['button_class'] : '';
397 363 $class .= ' button-primary frm-button-primary';
398 -
399 364 if ( ! $steps[ $k ]['current'] ) {
400 365 $class .= ' frm_grey disabled';
401 366 }
402 367 $steps[ $k ]['button_class'] = $class;
@@ -411,10 +376,9 @@
411 376 * @return void
412 377 */
413 378 protected function adjust_plugin_install_step( &$steps ) {
414 379 $plugins = $this->required_plugins();
415 -
416 - if ( ! $plugins ) {
380 + if ( empty( $plugins ) ) {
417 381 unset( $steps['plugin'] );
418 382 $steps['import']['num'] = 2;
419 383 $steps['complete']['num'] = 3;
420 384 return;
@@ -421,16 +385,13 @@
421 385 }
422 386
423 387 $missing = array();
424 388 $rel = array();
425 -
426 389 foreach ( $plugins as $plugin_key ) {
427 390 $plugin = FrmAddonsController::install_link( $plugin_key );
428 -
429 391 if ( $plugin['status'] === 'active' ) {
430 392 continue;
431 393 }
432 -
433 394 if ( isset( $plugin['url'] ) ) {
434 395 $rel[] = $plugin['url'];
435 396 } else {
436 397 // Add-on is required but not allowed.
@@ -436,12 +397,11 @@
436 397 // Add-on is required but not allowed.
437 398 $missing[] = $plugin_key;
438 399 }
439 400 }
440 -
441 - if ( ! $rel && ! $missing ) {
401 + if ( empty( $rel ) && empty( $missing ) ) {
442 402 $steps['plugin']['complete'] = true;
443 - } elseif ( $missing ) {
403 + } elseif ( ! empty( $missing ) ) {
444 404 $steps['plugin']['error'] = sprintf(
445 405 /* translators: %1$s: Plugin name */
446 406 esc_html__( 'You need permission to download the Formidable %1$s plugin', 'formidable' ),
447 407 implode( ', ', $missing )
@@ -456,21 +416,18 @@
456 416 }
457 417 }
458 418
459 419 /**
460 - * @param array $step Step.
461 - *
462 420 * @return void
463 421 */
464 422 protected function step_top( $step ) {
465 - $section_class = ! empty( $step['current'] ) ? '' : 'frm_grey';
423 + $section_class = empty( $step['current'] ) ? 'frm_grey' : '';
466 424
467 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
468 425 ?>
469 426 <section class="step step-install <?php echo esc_attr( $section_class ); ?>">
470 427 <aside class="num">
471 428 <?php
472 - if ( ! empty( $step['complete'] ) ) {
429 + if ( isset( $step['complete'] ) && $step['complete'] ) {
473 430 FrmAppHelper::icon_by_class(
474 431 'frmfont frm_step_complete_icon',
475 432 array(
476 433 /* translators: %1$s: Step number */
@@ -479,9 +436,9 @@
479 436 )
480 437 );
481 438 } else {
482 439 ?>
483 - <svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 100 100"><circle cx="50" cy="50" r="50" fill="#ccc"/><text x="50%" y="50%" text-anchor="middle" fill="#fff" stroke="#fff" stroke-width="2px" dy=".3em" font-size="3.7em"><?php echo esc_html( $step['num'] ); ?></text></svg><?php // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong ?>
440 + <svg xmlns="http://www.w3.org/2000/svg" width="50" height="50" viewBox="0 0 100 100"><circle cx="50" cy="50" r="50" fill="#ccc"/><text x="50%" y="50%" text-anchor="middle" fill="#fff" stroke="#fff" stroke-width="2px" dy=".3em" font-size="3.7em"><?php echo esc_html( $step['num'] ); ?></text></svg>
484 441 <?php
485 442 }
486 443 ?>
487 444 <i class="loader hidden"></i>
@@ -494,30 +451,23 @@
494 451 <?php if ( isset( $step['error'] ) ) { ?>
495 452 <p class="frm_error"><?php echo esc_html( $step['error'] ); ?></p>
496 453 <?php } ?>
497 454 <?php
498 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
499 455 }
500 456
501 457 /**
502 - * @param array $step Step.
503 - *
504 458 * @return void
505 459 */
506 460 protected function step_bottom( $step ) {
507 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
508 461 ?>
509 462 </div>
510 463 </section>
511 464 <?php
512 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
513 465 }
514 466
515 467 /**
516 468 * Generate and output Connect step section HTML.
517 469 *
518 - * @param array $step Step.
519 - *
520 470 * @return void
521 471 */
522 472 protected function license_box( $step ) {
523 473 $this->step_top( $step );
@@ -522,15 +472,13 @@
522 472 protected function license_box( $step ) {
523 473 $this->step_top( $step );
524 474
525 475 if ( $step['complete'] ) {
526 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
527 476 ?>
528 477 <a href="#" class="<?php echo esc_attr( $step['button_class'] ); ?>">
529 478 <?php echo esc_html( $step['button_label'] ); ?>
530 479 </a>
531 480 <?php
532 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
533 481 } else {
534 482 FrmSettingsController::license_box();
535 483 }
536 484
@@ -537,10 +485,8 @@
537 485 $this->step_bottom( $step );
538 486 }
539 487
540 488 /**
541 - * @param array $step Step.
542 - *
543 489 * @return void
544 490 */
545 491 protected function show_plugin_install( $step ) {
546 492 $this->step_top( $step );
@@ -545,17 +491,15 @@
545 491 protected function show_plugin_install( $step ) {
546 492 $this->step_top( $step );
547 493
548 494 if ( ! isset( $step['error'] ) ) {
549 - $rel = $step['links'] ?? array();
495 + $rel = isset( $step['links'] ) ? $step['links'] : array();
550 496
551 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
552 497 ?>
553 498 <a rel="<?php echo esc_attr( implode( ',', $rel ) ); ?>" class="<?php echo esc_attr( $step['button_class'] ); ?>">
554 499 <?php echo esc_html( $step['button_label'] ); ?>
555 500 </a>
556 501 <?php
557 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
558 502 }
559 503
560 504 $this->step_bottom( $step );
561 505 }
@@ -560,27 +504,24 @@
560 504 $this->step_bottom( $step );
561 505 }
562 506
563 507 /**
564 - * @param array $step Step.
565 - *
566 508 * @return void
567 509 */
568 510 protected function show_app_install( $step ) {
569 511 $is_complete = $step['complete'];
570 -
571 - if ( $this->form_options() && ! $is_complete ) {
512 + if ( ! empty( $this->form_options() ) && ! $is_complete ) {
572 513 $step['description'] = __( 'Select the form or view you would like to create.', 'formidable' );
573 514 }
574 515
575 516 $this->step_top( $step );
576 517
577 - $api = new FrmFormApi();
578 - $addons = $api->get_api_info();
518 + $api = new FrmFormApi();
519 + $addons = $api->get_api_info();
520 +
579 521 $id = $this->download_id();
580 522 $has_file = isset( $addons[ $id ] ) && isset( $addons[ $id ]['beta'] );
581 523
582 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
583 524 if ( ! $step['current'] ) {
584 525 ?>
585 526 <a href="#" class="<?php echo esc_attr( $step['button_class'] ); ?>">
586 527 <?php echo esc_html( $step['button_label'] ); ?>
@@ -593,12 +534,11 @@
593 534
594 535 if ( ! $has_file ) {
595 536 echo '<p class="frm_error_style">' . esc_html__( 'We didn\'t find anything to import. Please contact our team.', 'formidable' ) . '</p>';
596 537 } elseif ( ! isset( $addons[ $id ]['beta']['package'] ) ) {
597 - echo '<p class="frm_error_style">' . esc_html__( 'Looks like you may not have a current subscription for this solution. Please check your account.', 'formidable' ) . '</p>'; // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong
538 + echo '<p class="frm_error_style">' . esc_html__( 'Looks like you may not have a current subscription for this solution. Please check your account.', 'formidable' ) . '</p>';
598 539 } else {
599 540 $xml = $addons[ $id ]['beta']['package'];
600 -
601 541 if ( is_array( $xml ) ) {
602 542 $xml = reset( $xml );
603 543 }
604 544
@@ -636,16 +576,13 @@
636 576 } else {
637 577 echo '</form>';
638 578 }
639 579 }//end if
640 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
641 580
642 581 $this->step_bottom( $step );
643 582 }
644 583
645 584 /**
646 - * @param string $xml
647 - *
648 585 * @return void
649 586 */
650 587 protected function show_form_options( $xml ) {
651 588 $this->show_import_options( $this->form_options(), 'form', $xml );
@@ -667,15 +604,14 @@
667 604 *
668 605 * @return void
669 606 */
670 607 protected function show_import_options( $options, $importing, $xml = '' ) {
671 - if ( ! $options ) {
608 + if ( empty( $options ) ) {
672 609 return;
673 610 }
674 611
675 612 $imported = $this->previously_imported_forms();
676 613 $count = count( $options );
677 -
678 614 foreach ( $options as $info ) {
679 615 // Count the number of options displayed for css.
680 616 if ( $count > 1 && ! isset( $info['img'] ) ) {
681 617 --$count;
@@ -680,9 +616,8 @@
680 616 if ( $count > 1 && ! isset( $info['img'] ) ) {
681 617 --$count;
682 618 }
683 619 }
684 -
685 620 $width = floor( ( 533 - ( ( $count - 1 ) * 20 ) ) / $count );
686 621 unset( $count );
687 622
688 623 $selected = false;
@@ -694,32 +629,26 @@
694 629 * @return void
695 630 */
696 631 protected function show_page_options() {
697 632 $pages = $this->needed_pages();
698 -
699 - if ( ! $pages ) {
633 + if ( empty( $pages ) ) {
700 634 return;
701 635 }
702 636
703 637 echo '<h3>Choose New Page Title</h3>';
704 -
705 638 foreach ( $pages as $page ) {
706 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
707 639 ?>
708 640 <p>
709 641 <label for="pages_<?php echo esc_html( $page['type'] ); ?>">
710 642 <?php echo esc_html( $page['label'] ); ?>
711 643 </label>
712 - <input type="text" name="pages[<?php echo esc_html( $page['type'] ); ?>]" value="<?php echo esc_attr( $page['name'] ); ?>" id="pages_<?php echo esc_html( $page['type'] ); ?>" required /><?php // phpcs:ignore SlevomatCodingStandard.Files.LineLength.LineTooLong ?>
644 + <input type="text" name="pages[<?php echo esc_html( $page['type'] ); ?>]" value="<?php echo esc_attr( $page['name'] ); ?>" id="pages_<?php echo esc_html( $page['type'] ); ?>" required />
713 645 </p>
714 646 <?php
715 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
716 647 }
717 648 }
718 649
719 650 /**
720 - * @param array $step
721 - *
722 651 * @return void
723 652 */
724 653 protected function show_page_links( $step ) {
725 654 if ( $step['current'] ) {
@@ -727,15 +656,13 @@
727 656 }
728 657
729 658 $this->step_top( $step );
730 659
731 - // phpcs:disable Generic.WhiteSpace.ScopeIndent
732 660 ?>
733 661 <a href="#" target="_blank" rel="noopener" id="frm-redirect-link" class="<?php echo esc_attr( $step['button_class'] ); ?>">
734 662 <?php echo esc_html( $step['button_label'] ); ?>
735 663 </a>
736 664 <?php
737 - // phpcs:enable Generic.WhiteSpace.ScopeIndent
738 665
739 666 $this->step_bottom( $step );
740 667 }
741 668
@@ -745,9 +672,9 @@
745 672 * @return bool
746 673 */
747 674 protected function is_current_plugin() {
748 675 $to_redirect = get_transient( FrmOnboardingWizardController::TRANSIENT_NAME );
749 - return $to_redirect === $this->plugin_slug && ! $this->is_complete();
676 + return $to_redirect === $this->plugin_slug && empty( $this->is_complete() );
750 677 }
751 678
752 679 /**
753 680 * Override this function to indicate when install is complete.
@@ -759,13 +686,11 @@
759 686 * @return bool
760 687 */
761 688 protected function is_complete( $count = 1 ) {
762 689 $imported = $this->previously_imported_forms();
763 -
764 690 if ( $count === 'all' ) {
765 691 return count( $imported ) >= count( $this->form_options() );
766 692 }
767 -
768 693 return ! empty( $imported );
769 694 }
770 695
771 696 /**
@@ -775,12 +700,10 @@
775 700 */
776 701 protected function previously_imported_forms() {
777 702 $imported = array();
778 703 $forms = $this->form_options();
779 -
780 704 foreach ( $forms as $form ) {
781 705 $was_imported = isset( $form['form'] ) ? FrmForm::get_id_by_key( $form['form'] ) : false;
782 -
783 706 if ( $was_imported ) {
784 707 $imported[ $form['form'] ] = $was_imported;
785 708 }
786 709 }