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

903 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 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 } 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 }
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 continue;
597 }
598
599 self::$templates[ $key ]['is_featured'] = true;
600 self::$featured_templates[] = self::$templates[ $key ];
601 }
602 }
603
604 /**
605 * Get the total count of favorite templates.
606 *
607 * @since 6.7
608 *
609 * @return int
610 */
611 public static function get_favorite_templates_count() {
612 $custom_count = count( self::$favorite_templates['custom'] );
613 $default_count = count( self::$favorite_templates['default'] );
614
615 return $custom_count + $default_count;
616 }
617
618 /**
619 * Initializes essential resources.
620 *
621 * @since 6.7
622 *
623 * @return void
624 */
625 private static function init_template_resources() {
626 self::$view_path = FrmAppHelper::plugin_path() . '/classes/views/form-templates/';
627
628 self::$upgrade_link = FrmAppHelper::admin_upgrade_link(
629 array(
630 'medium' => 'form-templates',
631 'content' => 'upgrade',
632 )
633 );
634
635 self::$renew_link = FrmAppHelper::admin_upgrade_link(
636 array(
637 'medium' => 'form-templates',
638 'content' => 'renew',
639 )
640 );
641 }
642
643 /**
644 * Adds a Cancel button to the header of the Form Templates page.
645 *
646 * It's hidden by default and will show when the user clicks on 'Create Form' from
647 * another place in Formidable Forms.
648 *
649 * @since 6.7
650 *
651 * @return void
652 */
653 public static function get_header_cancel_button() {
654 echo '
655 <a class="button frm-button-secondary frm_hidden" href="' . esc_url( admin_url( 'admin.php?page=formidable' ) ) . '" role="button">
656 ' . esc_html__( 'Cancel', 'formidable' ) . '
657 </a>';
658 }
659
660 /**
661 * Append 'new_template' query parameter to navigation links if it exists in the URL.
662 *
663 * @since 6.7
664 *
665 * @param array $nav_items Navigation items.
666 * @param array $nav_args Additional navigation arguments.
667 *
668 * @return array Modified navigation items with 'new_template' query parameter.
669 */
670 public static function append_new_template_to_nav( $nav_items, $nav_args ) {
671 $is_new_template = FrmAppHelper::simple_get( 'new_template' );
672
673 // Append 'new_template=true' to each nav item's link if 'new_template' exists in the URL.
674 if ( $is_new_template ) {
675 foreach ( $nav_items as &$item ) {
676 $item['link'] .= '&new_template=true';
677 }
678 }
679
680 return $nav_items;
681 }
682
683 /**
684 * Enqueues "Form Templates" scripts and styles.
685 *
686 * @since 6.7
687 *
688 * @return void
689 */
690 public static function enqueue_assets() {
691 $plugin_url = FrmAppHelper::plugin_url();
692 $version = FrmAppHelper::plugin_version();
693 $js_dependencies = array(
694 'wp-i18n',
695 // This prevents a console error "wp.hooks is undefined" in WP versions older than 5.7.
696 'wp-hooks',
697 'formidable_dom',
698 );
699
700 // Enqueue styles that needed.
701 wp_enqueue_style( 'formidable-admin' );
702 wp_enqueue_style( 'formidable-animations' );
703 wp_enqueue_style( 'formidable-grids' );
704
705 // Register and enqueue "Form Templates" style.
706 wp_register_style( self::SCRIPT_HANDLE, $plugin_url . '/css/admin/form-templates.css', array(), $version );
707 wp_enqueue_style( self::SCRIPT_HANDLE );
708
709 // Register and enqueue "Form Templates" script.
710 wp_register_script( self::SCRIPT_HANDLE, $plugin_url . '/js/form-templates.js', $js_dependencies, $version, true );
711 wp_localize_script( self::SCRIPT_HANDLE, 'frmFormTemplatesVars', self::get_js_variables() );
712 wp_enqueue_script( self::SCRIPT_HANDLE );
713
714 /**
715 * Fires after "Form Templates" enqueue assets.
716 *
717 * @since 6.7
718 */
719 do_action( 'frm_form_templates_enqueue_assets' );
720
721 FrmAppHelper::dequeue_extra_global_scripts();
722 }
723
724 /**
725 * Get "Form Templates" JS variables as an array.
726 *
727 * @since 6.7
728 *
729 * @return array
730 */
731 private static function get_js_variables() {
732 $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(
737 'total' => self::get_favorite_templates_count(),
738 'default' => count( self::$favorite_templates['default'] ),
739 'custom' => count( self::$favorite_templates['custom'] ),
740 ),
741 'customCount' => count( self::$custom_templates ),
742 'upgradeLink' => self::$upgrade_link,
743 );
744
745 /**
746 * Filters `js_variables` passed to the "Form Templates".
747 *
748 * @since 6.7
749 *
750 * @param array $js_variables Array of js_variables passed to "Form Templates".
751 */
752 return apply_filters( 'frm_form_templates_js_variables', $js_variables );
753 }
754
755 /**
756 * Check if the current page is the form templates page.
757 *
758 * @since 6.7
759 *
760 * @return bool True if the current page is the form templates page, false otherwise.
761 */
762 public static function is_templates_page() {
763 return FrmAppHelper::is_admin_page( self::PAGE_SLUG );
764 }
765
766 /**
767 * Get the list of templates.
768 *
769 * @since 6.7
770 *
771 * @return array A list of templates.
772 */
773 public static function get_templates() {
774 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 }
791
792 /**
793 * Get the published forms based on applied filters.
794 *
795 * @since 6.7
796 *
797 * @return array An array of published forms.
798 */
799 public static function get_published_forms() {
800 $where = apply_filters( 'frm_forms_dropdown', array(), '' );
801 return FrmForm::get_published_forms( $where );
802 }
803
804 /**
805 * Get the list of featured templates.
806 *
807 * @since 6.7
808 *
809 * @return array A list of featured templates.
810 */
811 public static function get_featured_templates() {
812 return self::$featured_templates;
813 }
814
815 /**
816 * Get the list of categories.
817 *
818 * @since 6.7
819 *
820 * @return array A list of categories.
821 */
822 public static function get_categories() {
823 return self::$categories;
824 }
825
826 /**
827 * Get the user's favorite form templates.
828 *
829 * @since 6.7
830 *
831 * @return array The IDs of the user's favorite form templates.
832 */
833 public static function get_favorite_templates() {
834 return self::$favorite_templates;
835 }
836
837 /**
838 * Get the list of custom templates.
839 *
840 * @since 6.7
841 *
842 * @return array A list of custom templates.
843 */
844 public static function get_custom_templates() {
845 return self::$custom_templates;
846 }
847
848 /**
849 * Get the license type.
850 *
851 * @since 6.7
852 *
853 * @return string The license type.
854 */
855 public static function get_license_type() {
856 return self::$license_type;
857 }
858
859 /**
860 * Checks if the API request was expired.
861 *
862 * @since 6.7
863 *
864 * @return bool True if the API request was expired, false otherwise.
865 */
866 public static function is_expired() {
867 return self::$is_expired;
868 }
869
870 /**
871 * Get the path to form templates views.
872 *
873 * @since 6.7
874 *
875 * @return string Path to views.
876 */
877 public static function get_view_path() {
878 return self::$view_path;
879 }
880
881 /**
882 * Get the upgrade link.
883 *
884 * @since 6.7
885 *
886 * @return string URL for upgrading accounts.
887 */
888 public static function get_upgrade_link() {
889 return self::$upgrade_link;
890 }
891
892 /**
893 * Get the renewal link.
894 *
895 * @since 6.7
896 *
897 * @return string URL for renewing accounts.
898 */
899 public static function get_renew_link() {
900 return self::$renew_link;
901 }
902 }
903