PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.8
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.8
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 +62 -82 6.25.16.8 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 /**
@@ -147,15 +140,15 @@
147 140 public static function load_admin_hooks() {
148 141 self::init_template_resources();
149 142
150 143 // 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 );
144 + add_action( 'admin_menu', __CLASS__ . '::menu', 14 );
145 + add_action( 'admin_footer', __CLASS__ . '::render_modal' );
146 + add_filter( 'frm_form_nav_list', __CLASS__ . '::append_new_template_to_nav', 10, 2 );
154 147
155 148 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 );
149 + add_action( 'admin_init', __CLASS__ . '::set_form_templates_data' );
150 + add_action( 'admin_enqueue_scripts', __CLASS__ . '::enqueue_assets', 15 );
158 151 add_filter( 'frm_show_footer_links', '__return_false' );
159 152 }
160 153 }
161 154
@@ -174,9 +167,9 @@
174 167 'Formidable | ' . $label,
175 168 $label,
176 169 self::REQUIRED_CAPABILITY,
177 170 self::PAGE_SLUG,
178 - array( self::class, 'render' )
171 + array( __CLASS__, 'render' )
179 172 );
180 173 }
181 174
182 175 /**
@@ -206,8 +199,9 @@
206 199 $featured_templates = self::get_featured_templates();
207 200 $custom_templates = self::get_custom_templates();
208 201 $categories = self::get_categories();
209 202
203 + // Render the view.
210 204 include $view_path . 'index.php';
211 205 }
212 206
213 207 /**
@@ -232,15 +226,12 @@
232 226
233 227 // Add `create-template` modal view.
234 228 $view_parts[] = 'modals/create-template-modal.php';
235 229
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';
230 + // Add 'leave-email' and 'code-from-email' modals views for users without Pro or free access.
231 + if ( ! FrmAppHelper::pro_is_installed() && ! self::$form_template_api->has_free_access() ) {
232 + $view_parts[] = 'modals/leave-email-modal.php';
233 + $view_parts[] = 'modals/code-from-email-modal.php';
243 234 }
244 235
245 236 // Add 'upgrade' modal view for non-elite users.
246 237 if ( 'elite' !== FrmAddonsController::license_type() ) {
@@ -261,8 +252,9 @@
261 252 $view_parts[] = 'modals/name-your-form-modal.php';
262 253 }
263 254 }
264 255
256 + // Render the view.
265 257 include $view_path . 'modal.php';
266 258 }
267 259
268 260 /**
@@ -391,37 +383,8 @@
391 383 wp_die();
392 384 }
393 385
394 386 /**
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 387 * Fetch and format custom templates.
425 388 *
426 389 * Retrieves the custom templates, formats them, and assigns them to the class property.
427 390 *
@@ -498,9 +461,9 @@
498 461 private static function organize_and_set_categories() {
499 462 // Iterate through templates to assign categories.
500 463 foreach ( self::$templates as $key => &$template ) {
501 464 // Skip the template if the categories are not set.
502 - if ( ! isset( $template['categories'] ) || ! isset( $template['id'] ) ) {
465 + if ( ! isset( $template['categories'] ) ) {
503 466 unset( self::$templates[ $key ] );
504 467 continue;
505 468 }
506 469
@@ -520,9 +483,9 @@
520 483 'count' => 0,
521 484 );
522 485 }
523 486
524 - ++self::$categories[ $category_slug ]['count'];
487 + self::$categories[ $category_slug ]['count']++;
525 488 }
526 489
527 490 // Mark the template as favorite if it's in the favorite templates list.
528 491 $template['is_favorite'] = in_array( $template['id'], self::$favorite_templates['default'], true );
@@ -532,9 +495,9 @@
532 495 unset( $template );
533 496
534 497 // Filter out certain and redundant categories.
535 498 // '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() );
499 + $redundant_cats = array_merge( array( 'PayPal', 'Stripe', 'Twilio' ), FrmFormsHelper::ignore_template_categories() );
537 500 foreach ( $redundant_cats as $redundant_cat ) {
538 501 $category_slug = sanitize_title( $redundant_cat );
539 502 unset( self::$categories[ $category_slug ] );
540 503 }
@@ -560,12 +523,17 @@
560 523 // Assigned via JavaScript.
561 524 'count' => 0,
562 525 );
563 526 }
564 - $special_categories['all-items'] = array(
527 + $special_categories['all-templates'] = array(
565 528 'name' => __( 'All Templates', 'formidable' ),
566 529 'count' => self::get_template_count(),
567 530 );
531 + $special_categories['free-templates'] = array(
532 + 'name' => __( 'Free Templates', 'formidable' ),
533 + // Assigned via JavaScript.
534 + 'count' => 0,
535 + );
568 536
569 537 self::$categories = array_merge(
570 538 $special_categories,
571 539 self::$categories
@@ -574,9 +542,9 @@
574 542
575 543 /**
576 544 * Assign featured templates.
577 545 *
578 - * Iterates through FEATURED_TEMPLATES_IDS and adds matching templates to
546 + * Iterates through FEATURED_TEMPLATES_KEYS and adds matching templates to
579 547 * the `featured_templates` class property.
580 548 *
581 549 * @since 6.7
582 550 *
@@ -582,9 +550,9 @@
582 550 *
583 551 * @return void
584 552 */
585 553 private static function assign_featured_templates() {
586 - foreach ( self::FEATURED_TEMPLATES_IDS as $key ) {
554 + foreach ( self::FEATURED_TEMPLATES_KEYS as $key ) {
587 555 if ( isset( self::$templates[ $key ] ) ) {
588 556 self::$templates[ $key ]['is_featured'] = true;
589 557 self::$featured_templates[] = self::$templates[ $key ];
590 558 }
@@ -687,9 +655,8 @@
687 655 );
688 656
689 657 // Enqueue styles that needed.
690 658 wp_enqueue_style( 'formidable-admin' );
691 - wp_enqueue_style( 'formidable-animations' );
692 659 wp_enqueue_style( 'formidable-grids' );
693 660
694 661 // Register and enqueue "Form Templates" style.
695 662 wp_register_style( self::SCRIPT_HANDLE, $plugin_url . '/css/admin/form-templates.css', array(), $version );
@@ -706,9 +673,9 @@
706 673 * @since 6.7
707 674 */
708 675 do_action( 'frm_form_templates_enqueue_assets' );
709 676
710 - FrmAppHelper::dequeue_extra_global_scripts();
677 + self::dequeue_scripts();
711 678 }
712 679
713 680 /**
714 681 * Get "Form Templates" JS variables as an array.
@@ -718,18 +685,17 @@
718 685 * @return array
719 686 */
720 687 private static function get_js_variables() {
721 688 $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(
689 + 'FEATURED_TEMPLATES_KEYS' => self::FEATURED_TEMPLATES_KEYS,
690 + 'templatesCount' => self::get_template_count(),
691 + 'favoritesCount' => array(
726 692 'total' => self::get_favorite_templates_count(),
727 693 'default' => count( self::$favorite_templates['default'] ),
728 694 'custom' => count( self::$favorite_templates['custom'] ),
729 695 ),
730 - 'customCount' => count( self::$custom_templates ),
731 - 'upgradeLink' => self::$upgrade_link,
696 + 'customCount' => count( self::$custom_templates ),
697 + 'upgradeLink' => self::$upgrade_link,
732 698 );
733 699
734 700 /**
735 701 * Filters `js_variables` passed to the "Form Templates".
@@ -738,8 +704,22 @@
738 704 *
739 705 * @param array $js_variables Array of js_variables passed to "Form Templates".
740 706 */
741 707 return apply_filters( 'frm_form_templates_js_variables', $js_variables );
708 + }
709 +
710 + /**
711 + * Dequeue scripts and styles on "Form Templates".
712 + *
713 + * Avoid extra scripts loading on "Form Templates" page that aren't needed.
714 + *
715 + * @since 6.7
716 + *
717 + * @return void
718 + */
719 + private static function dequeue_scripts() {
720 + wp_dequeue_script( 'frm-surveys-admin' );
721 + wp_dequeue_script( 'frm-quizzes-form-action' );
742 722 }
743 723
744 724 /**
745 725 * Check if the current page is the form templates page.