| @@ -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 | /** |
| @@ -142,26 +135,19 @@ | ||
| 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 | - 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 ); | |
| 151 | 144 | |
| 152 | - // 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 ); | |
| 156 | - | |
| 157 | - if ( ! self::is_templates_page() ) { | |
| 158 | - return; | |
| 145 | + if ( self::is_templates_page() ) { | |
| 146 | + add_action( 'admin_init', __CLASS__ . '::set_form_templates_data' ); | |
| 147 | + add_action( 'admin_enqueue_scripts', __CLASS__ . '::enqueue_assets', 15 ); | |
| 148 | + add_filter( 'frm_show_footer_links', '__return_false' ); | |
| 159 | 149 | } |
| 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 | 150 | } |
| 165 | 151 | |
| 166 | 152 | /** |
| 167 | 153 | * Add Form Templates menu item to sidebar and define index page. |
| @@ -178,10 +164,12 @@ | ||
| 178 | 164 | 'Formidable | ' . $label, |
| 179 | 165 | $label, |
| 180 | 166 | self::REQUIRED_CAPABILITY, |
| 181 | 167 | self::PAGE_SLUG, |
| 182 | - array( self::class, 'render' ) | |
| 168 | + array( __CLASS__, 'render' ) | |
| 183 | 169 | ); |
| 170 | + | |
| 171 | + self::init_template_resources(); | |
| 184 | 172 | } |
| 185 | 173 | |
| 186 | 174 | /** |
| 187 | 175 | * Renders the Form Templates page in the WordPress admin area. |
| @@ -210,8 +198,9 @@ | ||
| 210 | 198 | $featured_templates = self::get_featured_templates(); |
| 211 | 199 | $custom_templates = self::get_custom_templates(); |
| 212 | 200 | $categories = self::get_categories(); |
| 213 | 201 | |
| 202 | + // Render the view. | |
| 214 | 203 | include $view_path . 'index.php'; |
| 215 | 204 | } |
| 216 | 205 | |
| 217 | 206 | /** |
| @@ -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() ) { |
| @@ -254,9 +240,9 @@ | ||
| 254 | 240 | // Add 'renew-account' modal view for expired users. |
| 255 | 241 | if ( $expired ) { |
| 256 | 242 | $view_parts[] = 'modals/renew-account-modal.php'; |
| 257 | 243 | } |
| 258 | - }//end if | |
| 244 | + } | |
| 259 | 245 | |
| 260 | 246 | // Check if the current page is the form builder page. |
| 261 | 247 | if ( FrmAppHelper::is_admin_page( 'formidable' ) ) { |
| 262 | 248 | $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' ); |
| @@ -265,8 +251,9 @@ | ||
| 265 | 251 | $view_parts[] = 'modals/name-your-form-modal.php'; |
| 266 | 252 | } |
| 267 | 253 | } |
| 268 | 254 | |
| 255 | + // Render the view. | |
| 269 | 256 | include $view_path . 'modal.php'; |
| 270 | 257 | } |
| 271 | 258 | |
| 272 | 259 | /** |
| @@ -344,9 +331,8 @@ | ||
| 344 | 331 | if ( 'add' === $operation ) { |
| 345 | 332 | self::$favorite_templates[ $key ][] = $template_id; |
| 346 | 333 | } elseif ( 'remove' === $operation ) { |
| 347 | 334 | $position = array_search( $template_id, self::$favorite_templates[ $key ], true ); |
| 348 | - | |
| 349 | 335 | if ( $position !== false ) { |
| 350 | 336 | unset( self::$favorite_templates[ $key ][ $position ] ); |
| 351 | 337 | } |
| 352 | 338 | } |
| @@ -351,9 +337,9 @@ | ||
| 351 | 337 | } |
| 352 | 338 | } |
| 353 | 339 | |
| 354 | 340 | // Update the favorite templates option. |
| 355 | - update_option( self::FAVORITE_TEMPLATES_OPTION, self::$favorite_templates, false ); | |
| 341 | + update_option( self::FAVORITE_TEMPLATES_OPTION, self::$favorite_templates ); | |
| 356 | 342 | |
| 357 | 343 | // Return the updated list of favorite templates. |
| 358 | 344 | wp_send_json_success( self::$favorite_templates ); |
| 359 | 345 | } |
| @@ -376,9 +362,14 @@ | ||
| 376 | 362 | // Get posted data. |
| 377 | 363 | $form_id = FrmAppHelper::get_param( 'xml', '', 'post', 'absint' ); |
| 378 | 364 | $new_form_id = FrmForm::duplicate( $form_id, 1, true ); |
| 379 | 365 | |
| 380 | - if ( $new_form_id ) { | |
| 366 | + if ( ! $new_form_id ) { | |
| 367 | + // Send an error response if form duplication fails. | |
| 368 | + $response = array( | |
| 369 | + 'message' => __( 'There was an error creating a template.', 'formidable' ), | |
| 370 | + ); | |
| 371 | + } else { | |
| 381 | 372 | FrmForm::update( $new_form_id, FrmFormsController::get_modal_values() ); |
| 382 | 373 | |
| 383 | 374 | // Send a success response with redirect URL. |
| 384 | 375 | $response = array( |
| @@ -383,13 +374,8 @@ | ||
| 383 | 374 | // Send a success response with redirect URL. |
| 384 | 375 | $response = array( |
| 385 | 376 | 'redirect' => admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . $new_form_id ) . '&_wpnonce=' . wp_create_nonce(), |
| 386 | 377 | ); |
| 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 | 378 | } |
| 393 | 379 | |
| 394 | 380 | // Send response. |
| 395 | 381 | echo wp_json_encode( $response ); |
| @@ -396,37 +382,8 @@ | ||
| 396 | 382 | wp_die(); |
| 397 | 383 | } |
| 398 | 384 | |
| 399 | 385 | /** |
| 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 | 386 | * Fetch and format custom templates. |
| 430 | 387 | * |
| 431 | 388 | * Retrieves the custom templates, formats them, and assigns them to the class property. |
| 432 | 389 | * |
| @@ -503,9 +460,9 @@ | ||
| 503 | 460 | private static function organize_and_set_categories() { |
| 504 | 461 | // Iterate through templates to assign categories. |
| 505 | 462 | foreach ( self::$templates as $key => &$template ) { |
| 506 | 463 | // Skip the template if the categories are not set. |
| 507 | - if ( ! isset( $template['categories'] ) || ! isset( $template['id'] ) ) { | |
| 464 | + if ( ! isset( $template['categories'] ) ) { | |
| 508 | 465 | unset( self::$templates[ $key ] ); |
| 509 | 466 | continue; |
| 510 | 467 | } |
| 511 | 468 | |
| @@ -525,22 +482,19 @@ | ||
| 525 | 482 | 'count' => 0, |
| 526 | 483 | ); |
| 527 | 484 | } |
| 528 | 485 | |
| 529 | - ++self::$categories[ $category_slug ]['count']; | |
| 486 | + self::$categories[ $category_slug ]['count']++; | |
| 530 | 487 | } |
| 531 | 488 | |
| 532 | 489 | // Mark the template as favorite if it's in the favorite templates list. |
| 533 | 490 | $template['is_favorite'] = in_array( $template['id'], self::$favorite_templates['default'], true ); |
| 534 | - }//end foreach | |
| 491 | + } | |
| 492 | + unset( $template ); // Unset the reference `$template` variable. | |
| 535 | 493 | |
| 536 | - // Unset the reference `$template` variable. | |
| 537 | - unset( $template ); | |
| 538 | - | |
| 539 | 494 | // Filter out certain and redundant categories. |
| 540 | 495 | // '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 | - | |
| 496 | + $redundant_cats = array_merge( array( 'PayPal', 'Stripe', 'Twilio' ), FrmFormsHelper::ignore_template_categories() ); | |
| 543 | 497 | foreach ( $redundant_cats as $redundant_cat ) { |
| 544 | 498 | $category_slug = sanitize_title( $redundant_cat ); |
| 545 | 499 | unset( self::$categories[ $category_slug ] ); |
| 546 | 500 | } |
| @@ -558,22 +512,23 @@ | ||
| 558 | 512 | 'name' => __( 'Custom', 'formidable' ), |
| 559 | 513 | 'count' => count( self::$custom_templates ), |
| 560 | 514 | ), |
| 561 | 515 | ); |
| 562 | - | |
| 563 | 516 | // Add the 'Available Templates' category for non-elite users. |
| 564 | 517 | if ( 'elite' !== FrmAddonsController::license_type() ) { |
| 565 | 518 | $special_categories['available-templates'] = array( |
| 566 | 519 | 'name' => __( 'Available Templates', 'formidable' ), |
| 567 | - // Assigned via JavaScript. | |
| 568 | - 'count' => 0, | |
| 520 | + 'count' => 0, // Assigned via JavaScript. | |
| 569 | 521 | ); |
| 570 | 522 | } |
| 571 | - | |
| 572 | - $special_categories['all-items'] = array( | |
| 523 | + $special_categories['all-templates'] = array( | |
| 573 | 524 | 'name' => __( 'All Templates', 'formidable' ), |
| 574 | - 'count' => self::get_template_count(), | |
| 525 | + 'count' => count( self::$templates ), | |
| 575 | 526 | ); |
| 527 | + $special_categories['free-templates'] = array( | |
| 528 | + 'name' => __( 'Free Templates', 'formidable' ), | |
| 529 | + 'count' => 0, // Assigned via JavaScript. | |
| 530 | + ); | |
| 576 | 531 | |
| 577 | 532 | self::$categories = array_merge( |
| 578 | 533 | $special_categories, |
| 579 | 534 | self::$categories |
| @@ -582,9 +537,9 @@ | ||
| 582 | 537 | |
| 583 | 538 | /** |
| 584 | 539 | * Assign featured templates. |
| 585 | 540 | * |
| 586 | - * Iterates through FEATURED_TEMPLATES_IDS and adds matching templates to | |
| 541 | + * Iterates through FEATURED_TEMPLATES_KEYS and adds matching templates to | |
| 587 | 542 | * the `featured_templates` class property. |
| 588 | 543 | * |
| 589 | 544 | * @since 6.7 |
| 590 | 545 | * |
| @@ -590,15 +545,13 @@ | ||
| 590 | 545 | * |
| 591 | 546 | * @return void |
| 592 | 547 | */ |
| 593 | 548 | private static function assign_featured_templates() { |
| 594 | - foreach ( self::FEATURED_TEMPLATES_IDS as $key ) { | |
| 595 | - if ( ! isset( self::$templates[ $key ] ) ) { | |
| 596 | - continue; | |
| 549 | + foreach ( self::FEATURED_TEMPLATES_KEYS as $key ) { | |
| 550 | + if ( isset( self::$templates[ $key ] ) ) { | |
| 551 | + self::$templates[ $key ]['is_featured'] = true; | |
| 552 | + self::$featured_templates[] = self::$templates[ $key ]; | |
| 597 | 553 | } |
| 598 | - | |
| 599 | - self::$templates[ $key ]['is_featured'] = true; | |
| 600 | - self::$featured_templates[] = self::$templates[ $key ]; | |
| 601 | 554 | } |
| 602 | 555 | } |
| 603 | 556 | |
| 604 | 557 | /** |
| @@ -663,9 +616,8 @@ | ||
| 663 | 616 | * @since 6.7 |
| 664 | 617 | * |
| 665 | 618 | * @param array $nav_items Navigation items. |
| 666 | 619 | * @param array $nav_args Additional navigation arguments. |
| 667 | - * | |
| 668 | 620 | * @return array Modified navigation items with 'new_template' query parameter. |
| 669 | 621 | */ |
| 670 | 622 | public static function append_new_template_to_nav( $nav_items, $nav_args ) { |
| 671 | 623 | $is_new_template = FrmAppHelper::simple_get( 'new_template' ); |
| @@ -691,16 +643,14 @@ | ||
| 691 | 643 | $plugin_url = FrmAppHelper::plugin_url(); |
| 692 | 644 | $version = FrmAppHelper::plugin_version(); |
| 693 | 645 | $js_dependencies = array( |
| 694 | 646 | 'wp-i18n', |
| 695 | - // This prevents a console error "wp.hooks is undefined" in WP versions older than 5.7. | |
| 696 | - 'wp-hooks', | |
| 647 | + 'wp-hooks', // This prevents a console error "wp.hooks is undefined" in WP versions older than 5.7. | |
| 697 | 648 | 'formidable_dom', |
| 698 | 649 | ); |
| 699 | 650 | |
| 700 | 651 | // Enqueue styles that needed. |
| 701 | 652 | wp_enqueue_style( 'formidable-admin' ); |
| 702 | - wp_enqueue_style( 'formidable-animations' ); | |
| 703 | 653 | wp_enqueue_style( 'formidable-grids' ); |
| 704 | 654 | |
| 705 | 655 | // Register and enqueue "Form Templates" style. |
| 706 | 656 | wp_register_style( self::SCRIPT_HANDLE, $plugin_url . '/css/admin/form-templates.css', array(), $version ); |
| @@ -717,9 +667,9 @@ | ||
| 717 | 667 | * @since 6.7 |
| 718 | 668 | */ |
| 719 | 669 | do_action( 'frm_form_templates_enqueue_assets' ); |
| 720 | 670 | |
| 721 | - FrmAppHelper::dequeue_extra_global_scripts(); | |
| 671 | + self::dequeue_scripts(); | |
| 722 | 672 | } |
| 723 | 673 | |
| 724 | 674 | /** |
| 725 | 675 | * Get "Form Templates" JS variables as an array. |
| @@ -729,18 +679,17 @@ | ||
| 729 | 679 | * @return array |
| 730 | 680 | */ |
| 731 | 681 | private static function get_js_variables() { |
| 732 | 682 | $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( | |
| 683 | + 'FEATURED_TEMPLATES_KEYS' => self::FEATURED_TEMPLATES_KEYS, | |
| 684 | + 'templatesCount' => count( self::$templates ), | |
| 685 | + 'favoritesCount' => array( | |
| 737 | 686 | 'total' => self::get_favorite_templates_count(), |
| 738 | 687 | 'default' => count( self::$favorite_templates['default'] ), |
| 739 | 688 | 'custom' => count( self::$favorite_templates['custom'] ), |
| 740 | 689 | ), |
| 741 | - 'customCount' => count( self::$custom_templates ), | |
| 742 | - 'upgradeLink' => self::$upgrade_link, | |
| 690 | + 'customCount' => count( self::$custom_templates ), | |
| 691 | + 'upgradeLink' => self::$upgrade_link, | |
| 743 | 692 | ); |
| 744 | 693 | |
| 745 | 694 | /** |
| 746 | 695 | * Filters `js_variables` passed to the "Form Templates". |
| @@ -752,8 +701,22 @@ | ||
| 752 | 701 | return apply_filters( 'frm_form_templates_js_variables', $js_variables ); |
| 753 | 702 | } |
| 754 | 703 | |
| 755 | 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 | + /** | |
| 756 | 719 | * Check if the current page is the form templates page. |
| 757 | 720 | * |
| 758 | 721 | * @since 6.7 |
| 759 | 722 | * |
| @@ -771,23 +734,8 @@ | ||
| 771 | 734 | * @return array A list of templates. |
| 772 | 735 | */ |
| 773 | 736 | public static function get_templates() { |
| 774 | 737 | return self::$templates; |
| 775 | - } | |
| 776 | - | |
| 777 | - /** | |
| 778 | - * Get the total number of templates. | |
| 779 | - * | |
| 780 | - * @since 6.8 | |
| 781 | - * | |
| 782 | - * @return int | |
| 783 | - */ | |
| 784 | - public static function get_template_count() { | |
| 785 | - if ( ! self::$templates ) { | |
| 786 | - self::$form_template_api = new FrmFormTemplateApi(); | |
| 787 | - self::retrieve_and_set_templates(); | |
| 788 | - } | |
| 789 | - return count( self::$templates ); | |
| 790 | 738 | } |
| 791 | 739 | |
| 792 | 740 | /** |
| 793 | 741 | * Get the published forms based on applied filters. |