PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.13
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.13
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 +45 -91 6.296.13 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 /**
@@ -142,26 +135,22 @@
142 135 /**
143 136 * Initialize hooks for template page only.
144 137 *
145 138 * @since 6.7
146 - *
147 - * @return void
148 139 */
149 140 public static function load_admin_hooks() {
150 141 self::init_template_resources();
151 142
152 143 // Use the same priority as Applications so Form Templates appear directly under Applications.
153 - add_action( 'admin_menu', self::class . '::menu', 14 );
154 - add_action( 'admin_footer', self::class . '::render_modal' );
155 - 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 );
156 147
157 - if ( ! self::is_templates_page() ) {
158 - return;
148 + if ( self::is_templates_page() ) {
149 + add_action( 'admin_init', __CLASS__ . '::set_form_templates_data' );
150 + add_action( 'admin_enqueue_scripts', __CLASS__ . '::enqueue_assets', 15 );
151 + add_filter( 'frm_show_footer_links', '__return_false' );
159 152 }
160 -
161 - add_action( 'admin_init', self::class . '::set_form_templates_data' );
162 - add_action( 'admin_enqueue_scripts', self::class . '::enqueue_assets', 15 );
163 - add_filter( 'frm_show_footer_links', '__return_false' );
164 153 }
165 154
166 155 /**
167 156 * Add Form Templates menu item to sidebar and define index page.
@@ -178,9 +167,9 @@
178 167 'Formidable | ' . $label,
179 168 $label,
180 169 self::REQUIRED_CAPABILITY,
181 170 self::PAGE_SLUG,
182 - array( self::class, 'render' )
171 + array( __CLASS__, 'render' )
183 172 );
184 173 }
185 174
186 175 /**
@@ -236,15 +225,12 @@
236 225
237 226 // Add `create-template` modal view.
238 227 $view_parts[] = 'modals/create-template-modal.php';
239 228
240 - if ( FrmFormTemplatesHelper::needs_get_free_templates_banner() ) {
241 - $leave_email_args = array(
242 - 'title' => esc_html__( 'Get 30+ Free Form Templates', 'formidable' ),
243 - 'description' => esc_html__( 'Just add your email address and you\'ll get 30+ free form templates to your account.', 'formidable' ),
244 - 'submit_button_text' => esc_html_x( 'Get Templates', 'get free templates modal submit button text', 'formidable' ),
245 - );
246 - $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';
247 233 }
248 234
249 235 // Add 'upgrade' modal view for non-elite users.
250 236 if ( 'elite' !== FrmAddonsController::license_type() ) {
@@ -344,9 +330,8 @@
344 330 if ( 'add' === $operation ) {
345 331 self::$favorite_templates[ $key ][] = $template_id;
346 332 } elseif ( 'remove' === $operation ) {
347 333 $position = array_search( $template_id, self::$favorite_templates[ $key ], true );
348 -
349 334 if ( $position !== false ) {
350 335 unset( self::$favorite_templates[ $key ][ $position ] );
351 336 }
352 337 }
@@ -376,9 +361,14 @@
376 361 // Get posted data.
377 362 $form_id = FrmAppHelper::get_param( 'xml', '', 'post', 'absint' );
378 363 $new_form_id = FrmForm::duplicate( $form_id, 1, true );
379 364
380 - if ( $new_form_id ) {
365 + if ( ! $new_form_id ) {
366 + // Send an error response if form duplication fails.
367 + $response = array(
368 + 'message' => __( 'There was an error creating a template.', 'formidable' ),
369 + );
370 + } else {
381 371 FrmForm::update( $new_form_id, FrmFormsController::get_modal_values() );
382 372
383 373 // Send a success response with redirect URL.
384 374 $response = array(
@@ -383,13 +373,8 @@
383 373 // Send a success response with redirect URL.
384 374 $response = array(
385 375 'redirect' => admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . $new_form_id ) . '&_wpnonce=' . wp_create_nonce(),
386 376 );
387 - } else {
388 - // Send an error response if form duplication fails.
389 - $response = array(
390 - 'message' => __( 'There was an error creating a template.', 'formidable' ),
391 - );
392 377 }
393 378
394 379 // Send response.
395 380 echo wp_json_encode( $response );
@@ -396,37 +381,8 @@
396 381 wp_die();
397 382 }
398 383
399 384 /**
400 - * Handle AJAX request to subscribe the user to ActiveCampaign.
401 - *
402 - * @since 6.25
403 - *
404 - * @return void
405 - */
406 - public static function ajax_get_free_templates() {
407 - FrmAppHelper::permission_check( self::REQUIRED_CAPABILITY );
408 - check_ajax_referer( 'frm_ajax', 'nonce' );
409 -
410 - $email = FrmAppHelper::get_post_param( 'email', '', 'sanitize_email' );
411 -
412 - if ( ! $email || ! is_email( $email ) ) {
413 - wp_send_json_error(
414 - array( 'message' => __( 'Please enter a valid email address.', 'formidable' ) ),
415 - WP_Http::BAD_REQUEST
416 - );
417 - }
418 -
419 - self::$form_template_api = new FrmFormTemplateApi();
420 - self::$form_template_api->reset_cached();
421 -
422 - FrmEmailCollectionHelper::subscribe_to_active_campaign( $email );
423 - self::$form_template_api::set_free_license_code( '1' );
424 -
425 - wp_send_json_success();
426 - }
427 -
428 - /**
429 385 * Fetch and format custom templates.
430 386 *
431 387 * Retrieves the custom templates, formats them, and assigns them to the class property.
432 388 *
@@ -503,9 +459,9 @@
503 459 private static function organize_and_set_categories() {
504 460 // Iterate through templates to assign categories.
505 461 foreach ( self::$templates as $key => &$template ) {
506 462 // Skip the template if the categories are not set.
507 - if ( ! isset( $template['categories'] ) || ! isset( $template['id'] ) ) {
463 + if ( ! isset( $template['categories'] ) ) {
508 464 unset( self::$templates[ $key ] );
509 465 continue;
510 466 }
511 467
@@ -537,10 +493,9 @@
537 493 unset( $template );
538 494
539 495 // Filter out certain and redundant categories.
540 496 // 'PayPal', 'Stripe', and 'Twilio' are included elsewhere and should be ignored in this context.
541 - $redundant_cats = array_merge( array( 'PayPal', 'Stripe', 'Twilio' ), FrmFormsHelper::get_license_types() );
542 -
497 + $redundant_cats = array_merge( array( 'PayPal', 'Stripe', 'Twilio' ), FrmFormsHelper::ignore_template_categories() );
543 498 foreach ( $redundant_cats as $redundant_cat ) {
544 499 $category_slug = sanitize_title( $redundant_cat );
545 500 unset( self::$categories[ $category_slug ] );
546 501 }
@@ -558,9 +513,8 @@
558 513 'name' => __( 'Custom', 'formidable' ),
559 514 'count' => count( self::$custom_templates ),
560 515 ),
561 516 );
562 -
563 517 // Add the 'Available Templates' category for non-elite users.
564 518 if ( 'elite' !== FrmAddonsController::license_type() ) {
565 519 $special_categories['available-templates'] = array(
566 520 'name' => __( 'Available Templates', 'formidable' ),
@@ -567,13 +521,17 @@
567 521 // Assigned via JavaScript.
568 522 'count' => 0,
569 523 );
570 524 }
571 -
572 - $special_categories['all-items'] = array(
525 + $special_categories['all-templates'] = array(
573 526 'name' => __( 'All Templates', 'formidable' ),
574 527 'count' => self::get_template_count(),
575 528 );
529 + $special_categories['free-templates'] = array(
530 + 'name' => __( 'Free Templates', 'formidable' ),
531 + // Assigned via JavaScript.
532 + 'count' => 0,
533 + );
576 534
577 535 self::$categories = array_merge(
578 536 $special_categories,
579 537 self::$categories
@@ -582,9 +540,9 @@
582 540
583 541 /**
584 542 * Assign featured templates.
585 543 *
586 - * Iterates through FEATURED_TEMPLATES_IDS and adds matching templates to
544 + * Iterates through FEATURED_TEMPLATES_KEYS and adds matching templates to
587 545 * the `featured_templates` class property.
588 546 *
589 547 * @since 6.7
590 548 *
@@ -590,15 +548,13 @@
590 548 *
591 549 * @return void
592 550 */
593 551 private static function assign_featured_templates() {
594 - foreach ( self::FEATURED_TEMPLATES_IDS as $key ) {
595 - if ( ! isset( self::$templates[ $key ] ) ) {
596 - continue;
552 + foreach ( self::FEATURED_TEMPLATES_KEYS as $key ) {
553 + if ( isset( self::$templates[ $key ] ) ) {
554 + self::$templates[ $key ]['is_featured'] = true;
555 + self::$featured_templates[] = self::$templates[ $key ];
597 556 }
598 -
599 - self::$templates[ $key ]['is_featured'] = true;
600 - self::$featured_templates[] = self::$templates[ $key ];
601 557 }
602 558 }
603 559
604 560 /**
@@ -663,9 +619,8 @@
663 619 * @since 6.7
664 620 *
665 621 * @param array $nav_items Navigation items.
666 622 * @param array $nav_args Additional navigation arguments.
667 - *
668 623 * @return array Modified navigation items with 'new_template' query parameter.
669 624 */
670 625 public static function append_new_template_to_nav( $nav_items, $nav_args ) {
671 626 $is_new_template = FrmAppHelper::simple_get( 'new_template' );
@@ -729,18 +684,17 @@
729 684 * @return array
730 685 */
731 686 private static function get_js_variables() {
732 687 $js_variables = array(
733 - 'FEATURED_TEMPLATES_IDS' => self::FEATURED_TEMPLATES_IDS,
734 - 'FREE_TEMPLATES_IDS' => self::FREE_TEMPLATES_IDS,
735 - 'templatesCount' => self::get_template_count(),
736 - 'favoritesCount' => array(
688 + 'FEATURED_TEMPLATES_KEYS' => self::FEATURED_TEMPLATES_KEYS,
689 + 'templatesCount' => self::get_template_count(),
690 + 'favoritesCount' => array(
737 691 'total' => self::get_favorite_templates_count(),
738 692 'default' => count( self::$favorite_templates['default'] ),
739 693 'custom' => count( self::$favorite_templates['custom'] ),
740 694 ),
741 - 'customCount' => count( self::$custom_templates ),
742 - 'upgradeLink' => self::$upgrade_link,
695 + 'customCount' => count( self::$custom_templates ),
696 + 'upgradeLink' => self::$upgrade_link,
743 697 );
744 698
745 699 /**
746 700 * Filters `js_variables` passed to the "Form Templates".
@@ -781,9 +735,9 @@
781 735 *
782 736 * @return int
783 737 */
784 738 public static function get_template_count() {
785 - if ( ! self::$templates ) {
739 + if ( empty( self::$templates ) ) {
786 740 self::$form_template_api = new FrmFormTemplateApi();
787 741 self::retrieve_and_set_templates();
788 742 }
789 743 return count( self::$templates );