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

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