PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.7
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.7
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/FrmFormTemplatesController.php +69 -110 6.25.16.7 View file →
@@ -19,9 +19,9 @@
19 19
20 20 /**
21 21 * The slug of the Form Templates page.
22 22 *
23 - * @var string Unique identifier for the "Form Templates" page.
23 + * @var string PAGE_SLUG Unique identifier for the "Form Templates" page.
24 24 */
25 25 const PAGE_SLUG = 'formidable-form-templates';
26 26
27 27 /**
@@ -26,9 +26,9 @@
26 26
27 27 /**
28 28 * The script handle.
29 29 *
30 - * @var string Unique handle for the admin script.
30 + * @var string SCRIPT_HANDLE Unique handle for the admin script.
31 31 */
32 32 const SCRIPT_HANDLE = 'frm-form-templates';
33 33
34 34 /**
@@ -33,33 +33,26 @@
33 33
34 34 /**
35 35 * The required user capability to view form templates.
36 36 *
37 - * @var string Required capability to access the view form templates.
37 + * @var string REQUIRED_CAPABILITY Required capability to access the view form templates.
38 38 */
39 39 const REQUIRED_CAPABILITY = 'frm_view_forms';
40 40
41 41 /**
42 - * The IDs of the featured templates.
42 + * The keys of the featured templates.
43 43 *
44 - * Contains the unique IDs for the templates that are considered "featured":
44 + * Contains the unique keys for the templates that are considered "featured":
45 45 * "Contact Us", "Stripe Payment", "User Registration", "Create WordPress Post", "Survey", and "Quiz".
46 46 *
47 - * @var array Unique IDs for the featured templates.
47 + * @var array FEATURED_TEMPLATES_KEYS Unique keys for the featured templates.
48 48 */
49 - const FEATURED_TEMPLATES_IDS = array( 20872734, 28223640, 20874748, 20882522, 20908981, 28109851 );
49 + const FEATURED_TEMPLATES_KEYS = array( 20872734, 28223640, 20874748, 20882522, 20908981, 28109851 );
50 50
51 51 /**
52 - * The IDs of the free templates.
53 - *
54 - * @var array Unique IDs for the free templates.
55 - */
56 - const FREE_TEMPLATES_IDS = array( 20872734, 28223640 );
57 -
58 - /**
59 52 * Option name to store favorite templates.
60 53 *
61 - * @var string Unique identifier for storing favorite templates.
54 + * @var string FAVORITE_TEMPLATES_OPTION Unique identifier for storing favorite templates.
62 55 */
63 56 const FAVORITE_TEMPLATES_OPTION = 'frm_favorite_templates';
64 57
65 58 /**
@@ -64,9 +57,9 @@
64 57
65 58 /**
66 59 * Instance of the Form Template API handler.
67 60 *
68 - * @var FrmFormTemplateApi Form Template API handler.
61 + * @var FrmFormTemplateApi $form_template_api Form Template API handler.
69 62 */
70 63 private static $form_template_api;
71 64
72 65 /**
@@ -71,9 +64,9 @@
71 64
72 65 /**
73 66 * Templates fetched from the API.
74 67 *
75 - * @var array Templates information from API.
68 + * @var array $templates Templates information from API.
76 69 */
77 70 private static $templates = array();
78 71
79 72 /**
@@ -78,9 +71,9 @@
78 71
79 72 /**
80 73 * Featured templates.
81 74 *
82 - * @var array Associative array with the featured templates' information.
75 + * @var array $featured_templates Associative array with the featured templates' information.
83 76 */
84 77 private static $featured_templates = array();
85 78
86 79 /**
@@ -85,9 +78,9 @@
85 78
86 79 /**
87 80 * List of user favorite templates.
88 81 *
89 - * @var array List of templates that the user has marked as favorites.
82 + * @var array $favorite_templates List of templates that the user has marked as favorites.
90 83 */
91 84 private static $favorite_templates = array();
92 85
93 86 /**
@@ -92,9 +85,9 @@
92 85
93 86 /**
94 87 * Templates fetched from the published form by user.
95 88 *
96 - * @var array Templates information from published form.
89 + * @var array $custom_templates Templates information from published form.
97 90 */
98 91 private static $custom_templates = array();
99 92
100 93 /**
@@ -99,9 +92,9 @@
99 92
100 93 /**
101 94 * Categories for organizing templates.
102 95 *
103 - * @var array Categories for organizing templates.
96 + * @var array $categories Categories for organizing templates.
104 97 */
105 98 private static $categories = array();
106 99
107 100 /**
@@ -106,9 +99,9 @@
106 99
107 100 /**
108 101 * Status of API request, true if expired.
109 102 *
110 - * @var bool Whether the API request is expired or not.
103 + * @var bool $is_expired Whether the API request is expired or not.
111 104 */
112 105 private static $is_expired = false;
113 106
114 107 /**
@@ -113,9 +106,9 @@
113 106
114 107 /**
115 108 * The type of license received from the API.
116 109 *
117 - * @var string License type received from the API.
110 + * @var string $license_type License type received from the API.
118 111 */
119 112 private static $license_type = '';
120 113
121 114 /**
@@ -120,9 +113,9 @@
120 113
121 114 /**
122 115 * Path to views.
123 116 *
124 - * @var string Path to form templates views.
117 + * @var string $view_path Path to form templates views.
125 118 */
126 119 private static $view_path = '';
127 120
128 121 /**
@@ -127,9 +120,9 @@
127 120
128 121 /**
129 122 * Upgrade URL.
130 123 *
131 - * @var string URL for upgrading accounts.
124 + * @var string $upgrade_link URL for upgrading accounts.
132 125 */
133 126 private static $upgrade_link = '';
134 127
135 128 /**
@@ -134,9 +127,9 @@
134 127
135 128 /**
136 129 * Renew URL.
137 130 *
138 - * @var string URL for renewing accounts.
131 + * @var string $renew_link URL for renewing accounts.
139 132 */
140 133 private static $renew_link = '';
141 134
142 135 /**
@@ -144,18 +137,15 @@
144 137 *
145 138 * @since 6.7
146 139 */
147 140 public static function load_admin_hooks() {
148 - self::init_template_resources();
141 + add_action( 'admin_menu', __CLASS__ . '::menu', 14 ); // Use the same priority as Applications so Form Templates appear directly under Applications.
142 + add_action( 'admin_footer', __CLASS__ . '::render_modal' );
143 + add_filter( 'frm_form_nav_list', __CLASS__ . '::append_new_template_to_nav', 10, 2 );
149 144
150 - // Use the same priority as Applications so Form Templates appear directly under Applications.
151 - add_action( 'admin_menu', self::class . '::menu', 14 );
152 - add_action( 'admin_footer', self::class . '::render_modal' );
153 - add_filter( 'frm_form_nav_list', self::class . '::append_new_template_to_nav', 10, 2 );
154 -
155 145 if ( self::is_templates_page() ) {
156 - add_action( 'admin_init', self::class . '::set_form_templates_data' );
157 - add_action( 'admin_enqueue_scripts', self::class . '::enqueue_assets', 15 );
146 + add_action( 'admin_init', __CLASS__ . '::set_form_templates_data' );
147 + add_action( 'admin_enqueue_scripts', __CLASS__ . '::enqueue_assets', 15 );
158 148 add_filter( 'frm_show_footer_links', '__return_false' );
159 149 }
160 150 }
161 151
@@ -174,10 +164,12 @@
174 164 'Formidable | ' . $label,
175 165 $label,
176 166 self::REQUIRED_CAPABILITY,
177 167 self::PAGE_SLUG,
178 - array( self::class, 'render' )
168 + array( __CLASS__, 'render' )
179 169 );
170 +
171 + self::init_template_resources();
180 172 }
181 173
182 174 /**
183 175 * Renders the Form Templates page in the WordPress admin area.
@@ -206,8 +198,9 @@
206 198 $featured_templates = self::get_featured_templates();
207 199 $custom_templates = self::get_custom_templates();
208 200 $categories = self::get_categories();
209 201
202 + // Render the view.
210 203 include $view_path . 'index.php';
211 204 }
212 205
213 206 /**
@@ -232,15 +225,12 @@
232 225
233 226 // Add `create-template` modal view.
234 227 $view_parts[] = 'modals/create-template-modal.php';
235 228
236 - if ( FrmFormTemplatesHelper::needs_get_free_templates_banner() ) {
237 - $leave_email_args = array(
238 - 'title' => esc_html__( 'Get 30+ Free Form Templates', 'formidable' ),
239 - 'description' => esc_html__( 'Just add your email address and you\'ll get 30+ free form templates to your account.', 'formidable' ),
240 - 'submit_button_text' => esc_html_x( 'Get Templates', 'get free templates modal submit button text', 'formidable' ),
241 - );
242 - $view_parts[] = 'modals/leave-email-modal.php';
229 + // Add 'leave-email' and 'code-from-email' modals views for users without Pro or free access.
230 + if ( ! FrmAppHelper::pro_is_installed() && ! self::$form_template_api->has_free_access() ) {
231 + $view_parts[] = 'modals/leave-email-modal.php';
232 + $view_parts[] = 'modals/code-from-email-modal.php';
243 233 }
244 234
245 235 // Add 'upgrade' modal view for non-elite users.
246 236 if ( 'elite' !== FrmAddonsController::license_type() ) {
@@ -250,9 +240,9 @@
250 240 // Add 'renew-account' modal view for expired users.
251 241 if ( $expired ) {
252 242 $view_parts[] = 'modals/renew-account-modal.php';
253 243 }
254 - }//end if
244 + }
255 245
256 246 // Check if the current page is the form builder page.
257 247 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
258 248 $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
@@ -261,8 +251,9 @@
261 251 $view_parts[] = 'modals/name-your-form-modal.php';
262 252 }
263 253 }
264 254
255 + // Render the view.
265 256 include $view_path . 'modal.php';
266 257 }
267 258
268 259 /**
@@ -391,37 +382,8 @@
391 382 wp_die();
392 383 }
393 384
394 385 /**
395 - * Handle AJAX request to subscribe the user to ActiveCampaign.
396 - *
397 - * @since 6.25
398 - *
399 - * @return void
400 - */
401 - public static function ajax_get_free_templates() {
402 - FrmAppHelper::permission_check( self::REQUIRED_CAPABILITY );
403 - check_ajax_referer( 'frm_ajax', 'nonce' );
404 -
405 - $email = FrmAppHelper::get_post_param( 'email', '', 'sanitize_email' );
406 -
407 - if ( empty( $email ) || ! is_email( $email ) ) {
408 - wp_send_json_error(
409 - array( 'message' => __( 'Please enter a valid email address.', 'formidable' ) ),
410 - WP_Http::BAD_REQUEST
411 - );
412 - }
413 -
414 - self::$form_template_api = new FrmFormTemplateApi();
415 - self::$form_template_api->reset_cached();
416 -
417 - FrmEmailCollectionHelper::subscribe_to_active_campaign( $email );
418 - self::$form_template_api::set_free_license_code( '1' );
419 -
420 - wp_send_json_success();
421 - }
422 -
423 - /**
424 386 * Fetch and format custom templates.
425 387 *
426 388 * Retrieves the custom templates, formats them, and assigns them to the class property.
427 389 *
@@ -498,9 +460,9 @@
498 460 private static function organize_and_set_categories() {
499 461 // Iterate through templates to assign categories.
500 462 foreach ( self::$templates as $key => &$template ) {
501 463 // Skip the template if the categories are not set.
502 - if ( ! isset( $template['categories'] ) || ! isset( $template['id'] ) ) {
464 + if ( ! isset( $template['categories'] ) ) {
503 465 unset( self::$templates[ $key ] );
504 466 continue;
505 467 }
506 468
@@ -520,21 +482,19 @@
520 482 'count' => 0,
521 483 );
522 484 }
523 485
524 - ++self::$categories[ $category_slug ]['count'];
486 + self::$categories[ $category_slug ]['count']++;
525 487 }
526 488
527 489 // Mark the template as favorite if it's in the favorite templates list.
528 490 $template['is_favorite'] = in_array( $template['id'], self::$favorite_templates['default'], true );
529 - }//end foreach
491 + }
492 + unset( $template ); // Unset the reference `$template` variable.
530 493
531 - // Unset the reference `$template` variable.
532 - unset( $template );
533 -
534 494 // Filter out certain and redundant categories.
535 495 // 'PayPal', 'Stripe', and 'Twilio' are included elsewhere and should be ignored in this context.
536 - $redundant_cats = array_merge( array( 'PayPal', 'Stripe', 'Twilio' ), FrmFormsHelper::get_license_types() );
496 + $redundant_cats = array_merge( array( 'PayPal', 'Stripe', 'Twilio' ), FrmFormsHelper::ignore_template_categories() );
537 497 foreach ( $redundant_cats as $redundant_cat ) {
538 498 $category_slug = sanitize_title( $redundant_cat );
539 499 unset( self::$categories[ $category_slug ] );
540 500 }
@@ -556,16 +516,19 @@
556 516 // Add the 'Available Templates' category for non-elite users.
557 517 if ( 'elite' !== FrmAddonsController::license_type() ) {
558 518 $special_categories['available-templates'] = array(
559 519 'name' => __( 'Available Templates', 'formidable' ),
560 - // Assigned via JavaScript.
561 - 'count' => 0,
520 + 'count' => 0, // Assigned via JavaScript.
562 521 );
563 522 }
564 - $special_categories['all-items'] = array(
523 + $special_categories['all-templates'] = array(
565 524 'name' => __( 'All Templates', 'formidable' ),
566 - 'count' => self::get_template_count(),
525 + 'count' => count( self::$templates ),
567 526 );
527 + $special_categories['free-templates'] = array(
528 + 'name' => __( 'Free Templates', 'formidable' ),
529 + 'count' => 0, // Assigned via JavaScript.
530 + );
568 531
569 532 self::$categories = array_merge(
570 533 $special_categories,
571 534 self::$categories
@@ -574,9 +537,9 @@
574 537
575 538 /**
576 539 * Assign featured templates.
577 540 *
578 - * Iterates through FEATURED_TEMPLATES_IDS and adds matching templates to
541 + * Iterates through FEATURED_TEMPLATES_KEYS and adds matching templates to
579 542 * the `featured_templates` class property.
580 543 *
581 544 * @since 6.7
582 545 *
@@ -582,9 +545,9 @@
582 545 *
583 546 * @return void
584 547 */
585 548 private static function assign_featured_templates() {
586 - foreach ( self::FEATURED_TEMPLATES_IDS as $key ) {
549 + foreach ( self::FEATURED_TEMPLATES_KEYS as $key ) {
587 550 if ( isset( self::$templates[ $key ] ) ) {
588 551 self::$templates[ $key ]['is_featured'] = true;
589 552 self::$featured_templates[] = self::$templates[ $key ];
590 553 }
@@ -680,16 +643,14 @@
680 643 $plugin_url = FrmAppHelper::plugin_url();
681 644 $version = FrmAppHelper::plugin_version();
682 645 $js_dependencies = array(
683 646 'wp-i18n',
684 - // This prevents a console error "wp.hooks is undefined" in WP versions older than 5.7.
685 - 'wp-hooks',
647 + 'wp-hooks', // This prevents a console error "wp.hooks is undefined" in WP versions older than 5.7.
686 648 'formidable_dom',
687 649 );
688 650
689 651 // Enqueue styles that needed.
690 652 wp_enqueue_style( 'formidable-admin' );
691 - wp_enqueue_style( 'formidable-animations' );
692 653 wp_enqueue_style( 'formidable-grids' );
693 654
694 655 // Register and enqueue "Form Templates" style.
695 656 wp_register_style( self::SCRIPT_HANDLE, $plugin_url . '/css/admin/form-templates.css', array(), $version );
@@ -706,9 +667,9 @@
706 667 * @since 6.7
707 668 */
708 669 do_action( 'frm_form_templates_enqueue_assets' );
709 670
710 - FrmAppHelper::dequeue_extra_global_scripts();
671 + self::dequeue_scripts();
711 672 }
712 673
713 674 /**
714 675 * Get "Form Templates" JS variables as an array.
@@ -718,18 +679,17 @@
718 679 * @return array
719 680 */
720 681 private static function get_js_variables() {
721 682 $js_variables = array(
722 - 'FEATURED_TEMPLATES_IDS' => self::FEATURED_TEMPLATES_IDS,
723 - 'FREE_TEMPLATES_IDS' => self::FREE_TEMPLATES_IDS,
724 - 'templatesCount' => self::get_template_count(),
725 - 'favoritesCount' => array(
683 + 'FEATURED_TEMPLATES_KEYS' => self::FEATURED_TEMPLATES_KEYS,
684 + 'templatesCount' => count( self::$templates ),
685 + 'favoritesCount' => array(
726 686 'total' => self::get_favorite_templates_count(),
727 687 'default' => count( self::$favorite_templates['default'] ),
728 688 'custom' => count( self::$favorite_templates['custom'] ),
729 689 ),
730 - 'customCount' => count( self::$custom_templates ),
731 - 'upgradeLink' => self::$upgrade_link,
690 + 'customCount' => count( self::$custom_templates ),
691 + 'upgradeLink' => self::$upgrade_link,
732 692 );
733 693
734 694 /**
735 695 * Filters `js_variables` passed to the "Form Templates".
@@ -741,8 +701,22 @@
741 701 return apply_filters( 'frm_form_templates_js_variables', $js_variables );
742 702 }
743 703
744 704 /**
705 + * Dequeue scripts and styles on "Form Templates".
706 + *
707 + * Avoid extra scripts loading on "Form Templates" page that aren't needed.
708 + *
709 + * @since 6.7
710 + *
711 + * @return void
712 + */
713 + private static function dequeue_scripts() {
714 + wp_dequeue_script( 'frm-surveys-admin' );
715 + wp_dequeue_script( 'frm-quizzes-form-action' );
716 + }
717 +
718 + /**
745 719 * Check if the current page is the form templates page.
746 720 *
747 721 * @since 6.7
748 722 *
@@ -760,23 +734,8 @@
760 734 * @return array A list of templates.
761 735 */
762 736 public static function get_templates() {
763 737 return self::$templates;
764 - }
765 -
766 - /**
767 - * Get the total number of templates.
768 - *
769 - * @since 6.8
770 - *
771 - * @return int
772 - */
773 - public static function get_template_count() {
774 - if ( empty( self::$templates ) ) {
775 - self::$form_template_api = new FrmFormTemplateApi();
776 - self::retrieve_and_set_templates();
777 - }
778 - return count( self::$templates );
779 738 }
780 739
781 740 /**
782 741 * Get the published forms based on applied filters.