| @@ -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,22 +135,20 @@ | ||
| 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 | 148 | if ( self::is_templates_page() ) { |
| 158 | - add_action( 'admin_init', self::class . '::set_form_templates_data' ); | |
| 159 | - 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 ); | |
| 160 | 151 | add_filter( 'frm_show_footer_links', '__return_false' ); |
| 161 | 152 | } |
| 162 | 153 | } |
| 163 | 154 | |
| @@ -176,9 +167,9 @@ | ||
| 176 | 167 | 'Formidable | ' . $label, |
| 177 | 168 | $label, |
| 178 | 169 | self::REQUIRED_CAPABILITY, |
| 179 | 170 | self::PAGE_SLUG, |
| 180 | - array( self::class, 'render' ) | |
| 171 | + array( __CLASS__, 'render' ) | |
| 181 | 172 | ); |
| 182 | 173 | } |
| 183 | 174 | |
| 184 | 175 | /** |
| @@ -234,15 +225,12 @@ | ||
| 234 | 225 | |
| 235 | 226 | // Add `create-template` modal view. |
| 236 | 227 | $view_parts[] = 'modals/create-template-modal.php'; |
| 237 | 228 | |
| 238 | - if ( FrmFormTemplatesHelper::needs_get_free_templates_banner() ) { | |
| 239 | - $leave_email_args = array( | |
| 240 | - 'title' => esc_html__( 'Get 30+ Free Form Templates', 'formidable' ), | |
| 241 | - 'description' => esc_html__( 'Just add your email address and you\'ll get 30+ free form templates to your account.', 'formidable' ), | |
| 242 | - 'submit_button_text' => esc_html_x( 'Get Templates', 'get free templates modal submit button text', 'formidable' ), | |
| 243 | - ); | |
| 244 | - $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'; | |
| 245 | 233 | } |
| 246 | 234 | |
| 247 | 235 | // Add 'upgrade' modal view for non-elite users. |
| 248 | 236 | if ( 'elite' !== FrmAddonsController::license_type() ) { |
| @@ -342,9 +330,8 @@ | ||
| 342 | 330 | if ( 'add' === $operation ) { |
| 343 | 331 | self::$favorite_templates[ $key ][] = $template_id; |
| 344 | 332 | } elseif ( 'remove' === $operation ) { |
| 345 | 333 | $position = array_search( $template_id, self::$favorite_templates[ $key ], true ); |
| 346 | - | |
| 347 | 334 | if ( $position !== false ) { |
| 348 | 335 | unset( self::$favorite_templates[ $key ][ $position ] ); |
| 349 | 336 | } |
| 350 | 337 | } |
| @@ -394,37 +381,8 @@ | ||
| 394 | 381 | wp_die(); |
| 395 | 382 | } |
| 396 | 383 | |
| 397 | 384 | /** |
| 398 | - * Handle AJAX request to subscribe the user to ActiveCampaign. | |
| 399 | - * | |
| 400 | - * @since 6.25 | |
| 401 | - * | |
| 402 | - * @return void | |
| 403 | - */ | |
| 404 | - public static function ajax_get_free_templates() { | |
| 405 | - FrmAppHelper::permission_check( self::REQUIRED_CAPABILITY ); | |
| 406 | - check_ajax_referer( 'frm_ajax', 'nonce' ); | |
| 407 | - | |
| 408 | - $email = FrmAppHelper::get_post_param( 'email', '', 'sanitize_email' ); | |
| 409 | - | |
| 410 | - if ( empty( $email ) || ! is_email( $email ) ) { | |
| 411 | - wp_send_json_error( | |
| 412 | - array( 'message' => __( 'Please enter a valid email address.', 'formidable' ) ), | |
| 413 | - WP_Http::BAD_REQUEST | |
| 414 | - ); | |
| 415 | - } | |
| 416 | - | |
| 417 | - self::$form_template_api = new FrmFormTemplateApi(); | |
| 418 | - self::$form_template_api->reset_cached(); | |
| 419 | - | |
| 420 | - FrmEmailCollectionHelper::subscribe_to_active_campaign( $email ); | |
| 421 | - self::$form_template_api::set_free_license_code( '1' ); | |
| 422 | - | |
| 423 | - wp_send_json_success(); | |
| 424 | - } | |
| 425 | - | |
| 426 | - /** | |
| 427 | 385 | * Fetch and format custom templates. |
| 428 | 386 | * |
| 429 | 387 | * Retrieves the custom templates, formats them, and assigns them to the class property. |
| 430 | 388 | * |
| @@ -501,9 +459,9 @@ | ||
| 501 | 459 | private static function organize_and_set_categories() { |
| 502 | 460 | // Iterate through templates to assign categories. |
| 503 | 461 | foreach ( self::$templates as $key => &$template ) { |
| 504 | 462 | // Skip the template if the categories are not set. |
| 505 | - if ( ! isset( $template['categories'] ) || ! isset( $template['id'] ) ) { | |
| 463 | + if ( ! isset( $template['categories'] ) ) { | |
| 506 | 464 | unset( self::$templates[ $key ] ); |
| 507 | 465 | continue; |
| 508 | 466 | } |
| 509 | 467 | |
| @@ -535,10 +493,9 @@ | ||
| 535 | 493 | unset( $template ); |
| 536 | 494 | |
| 537 | 495 | // Filter out certain and redundant categories. |
| 538 | 496 | // 'PayPal', 'Stripe', and 'Twilio' are included elsewhere and should be ignored in this context. |
| 539 | - $redundant_cats = array_merge( array( 'PayPal', 'Stripe', 'Twilio' ), FrmFormsHelper::get_license_types() ); | |
| 540 | - | |
| 497 | + $redundant_cats = array_merge( array( 'PayPal', 'Stripe', 'Twilio' ), FrmFormsHelper::ignore_template_categories() ); | |
| 541 | 498 | foreach ( $redundant_cats as $redundant_cat ) { |
| 542 | 499 | $category_slug = sanitize_title( $redundant_cat ); |
| 543 | 500 | unset( self::$categories[ $category_slug ] ); |
| 544 | 501 | } |
| @@ -556,9 +513,8 @@ | ||
| 556 | 513 | 'name' => __( 'Custom', 'formidable' ), |
| 557 | 514 | 'count' => count( self::$custom_templates ), |
| 558 | 515 | ), |
| 559 | 516 | ); |
| 560 | - | |
| 561 | 517 | // Add the 'Available Templates' category for non-elite users. |
| 562 | 518 | if ( 'elite' !== FrmAddonsController::license_type() ) { |
| 563 | 519 | $special_categories['available-templates'] = array( |
| 564 | 520 | 'name' => __( 'Available Templates', 'formidable' ), |
| @@ -565,12 +521,17 @@ | ||
| 565 | 521 | // Assigned via JavaScript. |
| 566 | 522 | 'count' => 0, |
| 567 | 523 | ); |
| 568 | 524 | } |
| 569 | - $special_categories['all-items'] = array( | |
| 525 | + $special_categories['all-templates'] = array( | |
| 570 | 526 | 'name' => __( 'All Templates', 'formidable' ), |
| 571 | 527 | 'count' => self::get_template_count(), |
| 572 | 528 | ); |
| 529 | + $special_categories['free-templates'] = array( | |
| 530 | + 'name' => __( 'Free Templates', 'formidable' ), | |
| 531 | + // Assigned via JavaScript. | |
| 532 | + 'count' => 0, | |
| 533 | + ); | |
| 573 | 534 | |
| 574 | 535 | self::$categories = array_merge( |
| 575 | 536 | $special_categories, |
| 576 | 537 | self::$categories |
| @@ -579,9 +540,9 @@ | ||
| 579 | 540 | |
| 580 | 541 | /** |
| 581 | 542 | * Assign featured templates. |
| 582 | 543 | * |
| 583 | - * Iterates through FEATURED_TEMPLATES_IDS and adds matching templates to | |
| 544 | + * Iterates through FEATURED_TEMPLATES_KEYS and adds matching templates to | |
| 584 | 545 | * the `featured_templates` class property. |
| 585 | 546 | * |
| 586 | 547 | * @since 6.7 |
| 587 | 548 | * |
| @@ -587,9 +548,9 @@ | ||
| 587 | 548 | * |
| 588 | 549 | * @return void |
| 589 | 550 | */ |
| 590 | 551 | private static function assign_featured_templates() { |
| 591 | - foreach ( self::FEATURED_TEMPLATES_IDS as $key ) { | |
| 552 | + foreach ( self::FEATURED_TEMPLATES_KEYS as $key ) { | |
| 592 | 553 | if ( isset( self::$templates[ $key ] ) ) { |
| 593 | 554 | self::$templates[ $key ]['is_featured'] = true; |
| 594 | 555 | self::$featured_templates[] = self::$templates[ $key ]; |
| 595 | 556 | } |
| @@ -658,9 +619,8 @@ | ||
| 658 | 619 | * @since 6.7 |
| 659 | 620 | * |
| 660 | 621 | * @param array $nav_items Navigation items. |
| 661 | 622 | * @param array $nav_args Additional navigation arguments. |
| 662 | - * | |
| 663 | 623 | * @return array Modified navigation items with 'new_template' query parameter. |
| 664 | 624 | */ |
| 665 | 625 | public static function append_new_template_to_nav( $nav_items, $nav_args ) { |
| 666 | 626 | $is_new_template = FrmAppHelper::simple_get( 'new_template' ); |
| @@ -724,18 +684,17 @@ | ||
| 724 | 684 | * @return array |
| 725 | 685 | */ |
| 726 | 686 | private static function get_js_variables() { |
| 727 | 687 | $js_variables = array( |
| 728 | - 'FEATURED_TEMPLATES_IDS' => self::FEATURED_TEMPLATES_IDS, | |
| 729 | - 'FREE_TEMPLATES_IDS' => self::FREE_TEMPLATES_IDS, | |
| 730 | - 'templatesCount' => self::get_template_count(), | |
| 731 | - 'favoritesCount' => array( | |
| 688 | + 'FEATURED_TEMPLATES_KEYS' => self::FEATURED_TEMPLATES_KEYS, | |
| 689 | + 'templatesCount' => self::get_template_count(), | |
| 690 | + 'favoritesCount' => array( | |
| 732 | 691 | 'total' => self::get_favorite_templates_count(), |
| 733 | 692 | 'default' => count( self::$favorite_templates['default'] ), |
| 734 | 693 | 'custom' => count( self::$favorite_templates['custom'] ), |
| 735 | 694 | ), |
| 736 | - 'customCount' => count( self::$custom_templates ), | |
| 737 | - 'upgradeLink' => self::$upgrade_link, | |
| 695 | + 'customCount' => count( self::$custom_templates ), | |
| 696 | + 'upgradeLink' => self::$upgrade_link, | |
| 738 | 697 | ); |
| 739 | 698 | |
| 740 | 699 | /** |
| 741 | 700 | * Filters `js_variables` passed to the "Form Templates". |