PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.28
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.28
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
formidable / classes / controllers / FrmFormTemplatesController.php

FrmFormTemplatesController.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 6.28, at classes/controllers/FrmFormTemplatesController.php

901 lines 24.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Form Templates Controller class.
4 *
5 * @package Formidable
6 */
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 die( 'You are not allowed to call this page directly.' );
10 }
11
12 /**
13 * Class FrmFormTemplatesController.
14 * Handles the Form Templates page in the admin area.
15 *
16 * @since 6.7
17 */
18 class FrmFormTemplatesController {
19
20 /**
21 * The slug of the Form Templates page.
22 *
23 * @var string Unique identifier for the "Form Templates" page.
24 */
25 const PAGE_SLUG = 'formidable-form-templates';
26
27 /**
28 * The script handle.
29 *
30 * @var string Unique handle for the admin script.
31 */
32 const SCRIPT_HANDLE = 'frm-form-templates';
33
34 /**
35 * The required user capability to view form templates.
36 *
37 * @var string Required capability to access the view form templates.
38 */
39 const REQUIRED_CAPABILITY = 'frm_view_forms';
40
41 /**
42 * The IDs of the featured templates.
43 *
44 * Contains the unique IDs for the templates that are considered "featured":
45 * "Contact Us", "Stripe Payment", "User Registration", "Create WordPress Post", "Survey", and "Quiz".
46 *
47 * @var array Unique IDs for the featured templates.
48 */
49 const FEATURED_TEMPLATES_IDS = array( 20872734, 28223640, 20874748, 20882522, 20908981, 28109851 );
50
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 * Option name to store favorite templates.
60 *
61 * @var string Unique identifier for storing favorite templates.
62 */
63 const FAVORITE_TEMPLATES_OPTION = 'frm_favorite_templates';
64
65 /**
66 * Instance of the Form Template API handler.
67 *
68 * @var FrmFormTemplateApi Form Template API handler.
69 */
70 private static $form_template_api;
71
72 /**
73 * Templates fetched from the API.
74 *
75 * @var array Templates information from API.
76 */
77 private static $templates = array();
78
79 /**
80 * Featured templates.
81 *
82 * @var array Associative array with the featured templates' information.
83 */
84 private static $featured_templates = array();
85
86 /**
87 * List of user favorite templates.
88 *
89 * @var array List of templates that the user has marked as favorites.
90 */
91 private static $favorite_templates = array();
92
93 /**
94 * Templates fetched from the published form by user.
95 *
96 * @var array Templates information from published form.
97 */
98 private static $custom_templates = array();
99
100 /**
101 * Categories for organizing templates.
102 *
103 * @var array Categories for organizing templates.
104 */
105 private static $categories = array();
106
107 /**
108 * Status of API request, true if expired.
109 *
110 * @var bool Whether the API request is expired or not.
111 */
112 private static $is_expired = false;
113
114 /**
115 * The type of license received from the API.
116 *
117 * @var string License type received from the API.
118 */
119 private static $license_type = '';
120
121 /**
122 * Path to views.
123 *
124 * @var string Path to form templates views.
125 */
126 private static $view_path = '';
127
128 /**
129 * Upgrade URL.
130 *
131 * @var string URL for upgrading accounts.
132 */
133 private static $upgrade_link = '';
134
135 /**
136 * Renew URL.
137 *
138 * @var string URL for renewing accounts.
139 */
140 private static $renew_link = '';
141
142 /**
143 * Initialize hooks for template page only.
144 *
145 * @since 6.7
146 *
147 * @return void
148 */
149 public static function load_admin_hooks() {
150 self::init_template_resources();
151
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;
159 }
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 }
165
166 /**
167 * Add Form Templates menu item to sidebar and define index page.
168 *
169 * @since 6.7
170 *
171 * @return void
172 */
173 public static function menu() {
174 $label = __( 'Form Templates', 'formidable' );
175
176 add_submenu_page(
177 'formidable',
178 'Formidable | ' . $label,
179 $label,
180 self::REQUIRED_CAPABILITY,
181 self::PAGE_SLUG,
182 array( self::class, 'render' )
183 );
184 }
185
186 /**
187 * Renders the Form Templates page in the WordPress admin area.
188 *
189 * Sets up template data, fetches relevant information, determines which blocks to render,
190 * and includes the view file for displaying the Form Templates page.
191 *
192 * @since 6.7
193 *
194 * @return void
195 */
196 public static function render() {
197 // Include SVG images for icons.
198 FrmAppHelper::include_svg();
199
200 $view_path = self::get_view_path();
201 $upgrade_link = self::get_upgrade_link();
202 $renew_link = self::get_renew_link();
203 $license_type = self::get_license_type();
204 $pricing = FrmAppHelper::admin_upgrade_link( 'form-templates' );
205 $expired = self::is_expired();
206
207 // Get various template types and categories.
208 $templates = self::get_templates();
209 $favorite_templates = self::get_favorite_templates();
210 $featured_templates = self::get_featured_templates();
211 $custom_templates = self::get_custom_templates();
212 $categories = self::get_categories();
213
214 include $view_path . 'index.php';
215 }
216
217 /**
218 * Renders a modal component in the WordPress admin area.
219 *
220 * @since 6.7
221 *
222 * @return void
223 */
224 public static function render_modal() {
225 $view_path = self::$view_path;
226 $view_parts = array();
227
228 // Check if the current page is the form templates page.
229 if ( self::is_templates_page() ) {
230 // User and license-related variables.
231 $user = wp_get_current_user();
232 $expired = self::is_expired();
233 $upgrade_link = self::get_upgrade_link();
234 $renew_link = self::get_renew_link();
235 $published_forms = self::get_published_forms();
236
237 // Add `create-template` modal view.
238 $view_parts[] = 'modals/create-template-modal.php';
239
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';
247 }
248
249 // Add 'upgrade' modal view for non-elite users.
250 if ( 'elite' !== FrmAddonsController::license_type() ) {
251 $view_parts[] = 'modals/upgrade-modal.php';
252 }
253
254 // Add 'renew-account' modal view for expired users.
255 if ( $expired ) {
256 $view_parts[] = 'modals/renew-account-modal.php';
257 }
258 }//end if
259
260 // Check if the current page is the form builder page.
261 if ( FrmAppHelper::is_admin_page( 'formidable' ) ) {
262 $action = FrmAppHelper::simple_get( 'frm_action', 'sanitize_title' );
263
264 if ( 'edit' === $action || 'settings' === $action ) {
265 $view_parts[] = 'modals/name-your-form-modal.php';
266 }
267 }
268
269 include $view_path . 'modal.php';
270 }
271
272 /**
273 * Initializes and organizes form template data by performing the following actions:
274 * - Instantiates the Form Template API class
275 * - Retrieves and sets templates, including featured ones
276 * - Organizes and categorizes templates
277 * - Formats custom templates
278 * - Updates global variables to reflect the current state
279 *
280 * @since 6.7
281 *
282 * @return void
283 */
284 public static function set_form_templates_data() {
285 self::$form_template_api = new FrmFormTemplateApi();
286
287 self::init_favorite_templates();
288 self::fetch_and_format_custom_templates();
289 self::retrieve_and_set_templates();
290 self::organize_and_set_categories();
291 self::assign_featured_templates();
292 }
293
294 /**
295 * Initialize favorite templates from WordPress options.
296 *
297 * @since 6.7
298 *
299 * @return void
300 */
301 private static function init_favorite_templates() {
302 $default_option_structure = array(
303 'default' => array(),
304 'custom' => array(),
305 );
306
307 $favorites = get_option( self::FAVORITE_TEMPLATES_OPTION, $default_option_structure );
308 $favorites = wp_parse_args( $favorites, $default_option_structure );
309
310 // Set the favorite templates property and remove empty values.
311 self::$favorite_templates = array(
312 'default' => array_filter( (array) $favorites['default'] ),
313 'custom' => array_filter( (array) $favorites['custom'] ),
314 );
315 }
316
317 /**
318 * Handle AJAX request to add or remove favorite templates.
319 *
320 * Manages the $favorite_templates by using WordPress options to
321 * add or remove templates from the favorites list.
322 *
323 * @since 6.7
324 *
325 * @return void
326 */
327 public static function ajax_add_or_remove_favorite() {
328 // Check permission and nonce.
329 FrmAppHelper::permission_check( self::REQUIRED_CAPABILITY );
330 check_ajax_referer( 'frm_ajax', 'nonce' );
331
332 // Set up form templates environment, ensuring data is ready for processing.
333 self::set_form_templates_data();
334
335 // Get posted data.
336 $template_id = FrmAppHelper::get_post_param( 'template_id', '', 'absint' );
337 $operation = FrmAppHelper::get_post_param( 'operation', '', 'sanitize_text_field' );
338 $is_custom_template = FrmAppHelper::get_post_param( 'is_custom_template', '', 'rest_sanitize_boolean' );
339
340 // Determine the key based on whether it's a custom template or not.
341 $key = $is_custom_template ? 'custom' : 'default';
342
343 // Perform add or remove operation.
344 if ( 'add' === $operation ) {
345 self::$favorite_templates[ $key ][] = $template_id;
346 } elseif ( 'remove' === $operation ) {
347 $position = array_search( $template_id, self::$favorite_templates[ $key ], true );
348
349 if ( $position !== false ) {
350 unset( self::$favorite_templates[ $key ][ $position ] );
351 }
352 }
353
354 // Update the favorite templates option.
355 update_option( self::FAVORITE_TEMPLATES_OPTION, self::$favorite_templates );
356
357 // Return the updated list of favorite templates.
358 wp_send_json_success( self::$favorite_templates );
359 }
360
361 /**
362 * Create a custom template from a form.
363 *
364 * @since 6.7
365 *
366 * @return void
367 */
368 public static function ajax_create_template() {
369 // Check permission and nonce.
370 FrmAppHelper::permission_check( self::REQUIRED_CAPABILITY );
371 check_ajax_referer( 'frm_ajax', 'nonce' );
372
373 // Set up form templates environment, ensuring data is ready for processing.
374 self::set_form_templates_data();
375
376 // Get posted data.
377 $form_id = FrmAppHelper::get_param( 'xml', '', 'post', 'absint' );
378 $new_form_id = FrmForm::duplicate( $form_id, 1, true );
379
380 if ( ! $new_form_id ) {
381 // Send an error response if form duplication fails.
382 $response = array(
383 'message' => __( 'There was an error creating a template.', 'formidable' ),
384 );
385 } else {
386 FrmForm::update( $new_form_id, FrmFormsController::get_modal_values() );
387
388 // Send a success response with redirect URL.
389 $response = array(
390 'redirect' => admin_url( 'admin.php?page=formidable&frm_action=duplicate&id=' . $new_form_id ) . '&_wpnonce=' . wp_create_nonce(),
391 );
392 }
393
394 // Send response.
395 echo wp_json_encode( $response );
396 wp_die();
397 }
398
399 /**
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 * Fetch and format custom templates.
430 *
431 * Retrieves the custom templates, formats them, and assigns them to the class property.
432 *
433 * @since 6.7
434 *
435 * @return void
436 */
437 private static function fetch_and_format_custom_templates() {
438 // Get all custom templates that are not default templates.
439 $custom_templates = FrmForm::getAll(
440 array(
441 'is_template' => 1,
442 'default_template' => 0,
443 'status' => array( null, '', 'published' ),
444 ),
445 'name'
446 );
447
448 // Extract IDs from the custom templates for matching with favorite templates.
449 $custom_templates_ids = wp_list_pluck( $custom_templates, 'id' );
450
451 // Refine the list of favorite templates to include only those present in custom templates.
452 self::$favorite_templates['custom'] = array_intersect( self::$favorite_templates['custom'], $custom_templates_ids );
453
454 foreach ( $custom_templates as $template ) {
455 $template = array(
456 'id' => absint( $template->id ),
457 'name' => $template->name,
458 'key' => $template->form_key,
459 'description' => $template->description,
460 'link' => FrmForm::get_edit_link( absint( $template->id ) ),
461 'url' => wp_nonce_url( admin_url( 'admin.php?page=formidable&frm_action=duplicate&new_template=true&id=' . absint( $template->id ) ) ),
462 'released' => $template->created_at,
463 'installed' => 1,
464 'is_custom' => true,
465 'created_at' => $template->created_at,
466 );
467
468 // Mark the template as favorite if it's in the favorite templates list.
469 $template['is_favorite'] = in_array( $template['id'], self::$favorite_templates['custom'], true );
470
471 // Add the formatted template to the custom templates list.
472 array_unshift( self::$custom_templates, $template );
473 }
474 }
475
476 /**
477 * Retrieve and set templates.
478 *
479 * Gets the templates from the API and assigns them to the class property.
480 * Also handles any errors returned from the API.
481 *
482 * @since 6.7
483 *
484 * @return void
485 */
486 private static function retrieve_and_set_templates() {
487 self::$templates = self::$form_template_api->get_api_info();
488
489 self::$is_expired = FrmAddonsController::is_license_expired();
490 self::$license_type = FrmAddonsController::license_type();
491 }
492
493 /**
494 * Organize and set categories.
495 *
496 * Iterates through templates to organize categories, performs filtering, sorting,
497 * and adds special categories.
498 *
499 * @since 6.7
500 *
501 * @return void
502 */
503 private static function organize_and_set_categories() {
504 // Iterate through templates to assign categories.
505 foreach ( self::$templates as $key => &$template ) {
506 // Skip the template if the categories are not set.
507 if ( ! isset( $template['categories'] ) || ! isset( $template['id'] ) ) {
508 unset( self::$templates[ $key ] );
509 continue;
510 }
511
512 // Add a new key for category slugs.
513 $template['category_slugs'] = array();
514
515 // Increment the count for each category.
516 foreach ( $template['categories'] as $category ) {
517 $category_slug = sanitize_title( $category );
518
519 // Add the slug to the new array.
520 $template['category_slugs'][] = $category_slug;
521
522 if ( ! isset( self::$categories[ $category_slug ] ) ) {
523 self::$categories[ $category_slug ] = array(
524 'name' => $category,
525 'count' => 0,
526 );
527 }
528
529 ++self::$categories[ $category_slug ]['count'];
530 }
531
532 // Mark the template as favorite if it's in the favorite templates list.
533 $template['is_favorite'] = in_array( $template['id'], self::$favorite_templates['default'], true );
534 }//end foreach
535
536 // Unset the reference `$template` variable.
537 unset( $template );
538
539 // Filter out certain and redundant categories.
540 // '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
543 foreach ( $redundant_cats as $redundant_cat ) {
544 $category_slug = sanitize_title( $redundant_cat );
545 unset( self::$categories[ $category_slug ] );
546 }
547
548 // Sort the categories by keys alphabetically.
549 ksort( self::$categories );
550
551 // Add special categories.
552 $special_categories = array(
553 'favorites' => array(
554 'name' => __( 'Favorites', 'formidable' ),
555 'count' => self::get_favorite_templates_count(),
556 ),
557 'custom' => array(
558 'name' => __( 'Custom', 'formidable' ),
559 'count' => count( self::$custom_templates ),
560 ),
561 );
562
563 // Add the 'Available Templates' category for non-elite users.
564 if ( 'elite' !== FrmAddonsController::license_type() ) {
565 $special_categories['available-templates'] = array(
566 'name' => __( 'Available Templates', 'formidable' ),
567 // Assigned via JavaScript.
568 'count' => 0,
569 );
570 }
571
572 $special_categories['all-items'] = array(
573 'name' => __( 'All Templates', 'formidable' ),
574 'count' => self::get_template_count(),
575 );
576
577 self::$categories = array_merge(
578 $special_categories,
579 self::$categories
580 );
581 }
582
583 /**
584 * Assign featured templates.
585 *
586 * Iterates through FEATURED_TEMPLATES_IDS and adds matching templates to
587 * the `featured_templates` class property.
588 *
589 * @since 6.7
590 *
591 * @return void
592 */
593 private static function assign_featured_templates() {
594 foreach ( self::FEATURED_TEMPLATES_IDS as $key ) {
595 if ( isset( self::$templates[ $key ] ) ) {
596 self::$templates[ $key ]['is_featured'] = true;
597 self::$featured_templates[] = self::$templates[ $key ];
598 }
599 }
600 }
601
602 /**
603 * Get the total count of favorite templates.
604 *
605 * @since 6.7
606 *
607 * @return int
608 */
609 public static function get_favorite_templates_count() {
610 $custom_count = count( self::$favorite_templates['custom'] );
611 $default_count = count( self::$favorite_templates['default'] );
612
613 return $custom_count + $default_count;
614 }
615
616 /**
617 * Initializes essential resources.
618 *
619 * @since 6.7
620 *
621 * @return void
622 */
623 private static function init_template_resources() {
624 self::$view_path = FrmAppHelper::plugin_path() . '/classes/views/form-templates/';
625
626 self::$upgrade_link = FrmAppHelper::admin_upgrade_link(
627 array(
628 'medium' => 'form-templates',
629 'content' => 'upgrade',
630 )
631 );
632
633 self::$renew_link = FrmAppHelper::admin_upgrade_link(
634 array(
635 'medium' => 'form-templates',
636 'content' => 'renew',
637 )
638 );
639 }
640
641 /**
642 * Adds a Cancel button to the header of the Form Templates page.
643 *
644 * It's hidden by default and will show when the user clicks on 'Create Form' from
645 * another place in Formidable Forms.
646 *
647 * @since 6.7
648 *
649 * @return void
650 */
651 public static function get_header_cancel_button() {
652 echo '
653 <a class="button frm-button-secondary frm_hidden" href="' . esc_url( admin_url( 'admin.php?page=formidable' ) ) . '" role="button">
654 ' . esc_html__( 'Cancel', 'formidable' ) . '
655 </a>';
656 }
657
658 /**
659 * Append 'new_template' query parameter to navigation links if it exists in the URL.
660 *
661 * @since 6.7
662 *
663 * @param array $nav_items Navigation items.
664 * @param array $nav_args Additional navigation arguments.
665 *
666 * @return array Modified navigation items with 'new_template' query parameter.
667 */
668 public static function append_new_template_to_nav( $nav_items, $nav_args ) {
669 $is_new_template = FrmAppHelper::simple_get( 'new_template' );
670
671 // Append 'new_template=true' to each nav item's link if 'new_template' exists in the URL.
672 if ( $is_new_template ) {
673 foreach ( $nav_items as &$item ) {
674 $item['link'] .= '&new_template=true';
675 }
676 }
677
678 return $nav_items;
679 }
680
681 /**
682 * Enqueues "Form Templates" scripts and styles.
683 *
684 * @since 6.7
685 *
686 * @return void
687 */
688 public static function enqueue_assets() {
689 $plugin_url = FrmAppHelper::plugin_url();
690 $version = FrmAppHelper::plugin_version();
691 $js_dependencies = array(
692 'wp-i18n',
693 // This prevents a console error "wp.hooks is undefined" in WP versions older than 5.7.
694 'wp-hooks',
695 'formidable_dom',
696 );
697
698 // Enqueue styles that needed.
699 wp_enqueue_style( 'formidable-admin' );
700 wp_enqueue_style( 'formidable-animations' );
701 wp_enqueue_style( 'formidable-grids' );
702
703 // Register and enqueue "Form Templates" style.
704 wp_register_style( self::SCRIPT_HANDLE, $plugin_url . '/css/admin/form-templates.css', array(), $version );
705 wp_enqueue_style( self::SCRIPT_HANDLE );
706
707 // Register and enqueue "Form Templates" script.
708 wp_register_script( self::SCRIPT_HANDLE, $plugin_url . '/js/form-templates.js', $js_dependencies, $version, true );
709 wp_localize_script( self::SCRIPT_HANDLE, 'frmFormTemplatesVars', self::get_js_variables() );
710 wp_enqueue_script( self::SCRIPT_HANDLE );
711
712 /**
713 * Fires after "Form Templates" enqueue assets.
714 *
715 * @since 6.7
716 */
717 do_action( 'frm_form_templates_enqueue_assets' );
718
719 FrmAppHelper::dequeue_extra_global_scripts();
720 }
721
722 /**
723 * Get "Form Templates" JS variables as an array.
724 *
725 * @since 6.7
726 *
727 * @return array
728 */
729 private static function get_js_variables() {
730 $js_variables = array(
731 'FEATURED_TEMPLATES_IDS' => self::FEATURED_TEMPLATES_IDS,
732 'FREE_TEMPLATES_IDS' => self::FREE_TEMPLATES_IDS,
733 'templatesCount' => self::get_template_count(),
734 'favoritesCount' => array(
735 'total' => self::get_favorite_templates_count(),
736 'default' => count( self::$favorite_templates['default'] ),
737 'custom' => count( self::$favorite_templates['custom'] ),
738 ),
739 'customCount' => count( self::$custom_templates ),
740 'upgradeLink' => self::$upgrade_link,
741 );
742
743 /**
744 * Filters `js_variables` passed to the "Form Templates".
745 *
746 * @since 6.7
747 *
748 * @param array $js_variables Array of js_variables passed to "Form Templates".
749 */
750 return apply_filters( 'frm_form_templates_js_variables', $js_variables );
751 }
752
753 /**
754 * Check if the current page is the form templates page.
755 *
756 * @since 6.7
757 *
758 * @return bool True if the current page is the form templates page, false otherwise.
759 */
760 public static function is_templates_page() {
761 return FrmAppHelper::is_admin_page( self::PAGE_SLUG );
762 }
763
764 /**
765 * Get the list of templates.
766 *
767 * @since 6.7
768 *
769 * @return array A list of templates.
770 */
771 public static function get_templates() {
772 return self::$templates;
773 }
774
775 /**
776 * Get the total number of templates.
777 *
778 * @since 6.8
779 *
780 * @return int
781 */
782 public static function get_template_count() {
783 if ( empty( self::$templates ) ) {
784 self::$form_template_api = new FrmFormTemplateApi();
785 self::retrieve_and_set_templates();
786 }
787 return count( self::$templates );
788 }
789
790 /**
791 * Get the published forms based on applied filters.
792 *
793 * @since 6.7
794 *
795 * @return array An array of published forms.
796 */
797 public static function get_published_forms() {
798 $where = apply_filters( 'frm_forms_dropdown', array(), '' );
799 return FrmForm::get_published_forms( $where );
800 }
801
802 /**
803 * Get the list of featured templates.
804 *
805 * @since 6.7
806 *
807 * @return array A list of featured templates.
808 */
809 public static function get_featured_templates() {
810 return self::$featured_templates;
811 }
812
813 /**
814 * Get the list of categories.
815 *
816 * @since 6.7
817 *
818 * @return array A list of categories.
819 */
820 public static function get_categories() {
821 return self::$categories;
822 }
823
824 /**
825 * Get the user's favorite form templates.
826 *
827 * @since 6.7
828 *
829 * @return array The IDs of the user's favorite form templates.
830 */
831 public static function get_favorite_templates() {
832 return self::$favorite_templates;
833 }
834
835 /**
836 * Get the list of custom templates.
837 *
838 * @since 6.7
839 *
840 * @return array A list of custom templates.
841 */
842 public static function get_custom_templates() {
843 return self::$custom_templates;
844 }
845
846 /**
847 * Get the license type.
848 *
849 * @since 6.7
850 *
851 * @return string The license type.
852 */
853 public static function get_license_type() {
854 return self::$license_type;
855 }
856
857 /**
858 * Checks if the API request was expired.
859 *
860 * @since 6.7
861 *
862 * @return bool True if the API request was expired, false otherwise.
863 */
864 public static function is_expired() {
865 return self::$is_expired;
866 }
867
868 /**
869 * Get the path to form templates views.
870 *
871 * @since 6.7
872 *
873 * @return string Path to views.
874 */
875 public static function get_view_path() {
876 return self::$view_path;
877 }
878
879 /**
880 * Get the upgrade link.
881 *
882 * @since 6.7
883 *
884 * @return string URL for upgrading accounts.
885 */
886 public static function get_upgrade_link() {
887 return self::$upgrade_link;
888 }
889
890 /**
891 * Get the renewal link.
892 *
893 * @since 6.7
894 *
895 * @return string URL for renewing accounts.
896 */
897 public static function get_renew_link() {
898 return self::$renew_link;
899 }
900 }
901