PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.15
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.15
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 / helpers / FrmFormTemplatesHelper.php

FrmFormTemplatesHelper.php in Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More 6.15, at classes/helpers/FrmFormTemplatesHelper.php

202 lines 6.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Form Templates Helper 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 * Provides helper functions for managing form templates in the admin area.
14 *
15 * @since 6.7
16 */
17 class FrmFormTemplatesHelper {
18
19 /**
20 * Updates template array with additional details and URL.
21 *
22 * @param array $template Template data.
23 * @param string $pricing Upgrade link URL.
24 * @param string $license_type License type.
25 */
26 public static function prepare_template_details( &$template, $pricing, $license_type ) {
27 $template['is_featured'] = ! empty( $template['is_featured'] );
28 $template['is_favorite'] = ! empty( $template['is_favorite'] );
29 $template['is_custom'] = ! empty( $template['is_custom'] );
30 $template['plan_required'] = FrmFormsHelper::get_plan_required( $template );
31
32 if ( ! empty( $template['name'] ) ) {
33 $template['name'] = $template['is_custom'] ? $template['name'] : preg_replace( '/(\sForm)?(\sTemplate)?$/', '', $template['name'] );
34 } else {
35 $template['name'] = '';
36 }
37
38 $template['use_template'] = '#';
39 if ( $template['is_custom'] ) {
40 $template['use_template'] = $template['url'];
41 } elseif ( ! $template['plan_required'] ) {
42 $link = FrmFormsHelper::get_template_install_link( $template, compact( 'pricing', 'license_type' ) );
43
44 $template['use_template'] = esc_url( $link['url'] );
45 }
46 }
47
48 /**
49 * Echo attributes for a given template.
50 *
51 * @since 6.7
52 *
53 * @param array $template The template data.
54 * @param bool $expired Whether the API request is expired or not.
55 * @return void
56 */
57 public static function add_template_attributes( $template, $expired ) {
58 $attributes = array(
59 'tabindex' => '0',
60 'data-id' => $template['id'],
61 'frm-search-text' => strtolower( $template['name'] ),
62 );
63
64 // Set 'data-slug' attribute.
65 if ( ! empty( $template['slug'] ) ) {
66 $attributes['data-slug'] = $template['slug'];
67 }
68
69 // Set 'data-categories' attribute.
70 if ( ! empty( $template['category_slugs'] ) ) {
71 $attributes['data-categories'] = implode( ',', $template['category_slugs'] );
72 }
73
74 $attributes['class'] = self::prepare_single_template_classes( $template );
75 self::prepare_single_template_plan( $template, $expired, $attributes );
76
77 FrmAppHelper::array_to_html_params( $attributes, true );
78 }
79
80 /**
81 * Add classes for a given template.
82 *
83 * @since 6.7
84 *
85 * @param array $template The template data.
86 * @return string
87 */
88 private static function prepare_single_template_classes( $template ) {
89 $class_names = array( 'frm-card-item' );
90 if ( $template['is_featured'] ) {
91 $class_names[] = 'frm-form-templates-featured-item';
92 }
93 if ( $template['is_favorite'] ) {
94 $class_names[] = 'frm-form-templates-favorite-item';
95 }
96 if ( $template['is_custom'] ) {
97 $class_names[] = 'frm-form-templates-custom-item';
98 }
99
100 return implode( ' ', $class_names );
101 }
102
103 /**
104 * Add info about the required plan for this template.
105 *
106 * @since 6.7
107 *
108 * @param array $template The template data.
109 * @param bool $expired Whether the license is expired.
110 * @param array $attributes The template attributes.
111 * @return void
112 */
113 private static function prepare_single_template_plan( $template, $expired, &$attributes ) {
114 if ( ! $template['plan_required'] ) {
115 return;
116 }
117
118 $required_plan_slug = sanitize_title( $template['plan_required'] );
119 $attributes['data-required-plan'] = $expired && 'free' !== $required_plan_slug ? 'renew' : $required_plan_slug;
120 if ( 'free' === $required_plan_slug ) {
121 $attributes['data-key'] = $template['key'];
122 }
123
124 $attributes['class'] .= ' frm-form-templates-locked-item frm-' . esc_attr( $required_plan_slug ) . '-template';
125 }
126
127 /**
128 * Echo attributes for the link to view a template.
129 *
130 * @since 6.7
131 *
132 * @param array $template The template data.
133 * @return void
134 */
135 public static function add_template_link_attributes( $template ) {
136 $attributes = array(
137 'class' => 'button button-secondary frm-button-secondary frm-small',
138 'role' => 'button',
139 'href' => $template['link'],
140 );
141
142 if ( ! $template['is_custom'] ) {
143 $utm = array(
144 'medium' => 'form-templates',
145 'content' => $template['slug'],
146 );
147
148 $attributes['href'] = FrmAppHelper::admin_upgrade_link( $utm, $attributes['href'] );
149 $attributes['target'] = '_blank';
150 }
151
152 FrmAppHelper::array_to_html_params( $attributes, true );
153 }
154
155 /**
156 * Show the CTA to upgrade or renew.
157 *
158 * @since 6.7
159 *
160 * @param array $args {
161 * Arguments for the CTA.
162 *
163 * @type string $upgrade_link Upgrade link URL.
164 * @type string $renew_link Renew link URL.
165 * }
166 * @return void
167 */
168 public static function show_upgrade_renew_cta( $args ) {
169 // Show 'renew' banner for expired users.
170 if ( $args['expired'] ) {
171 FrmTipsHelper::show_admin_cta(
172 array(
173 'title' => esc_html__( 'Get Super Powers with Pre-built Forms', 'formidable' ),
174 'description' => esc_html__( 'Unleash the potential of hundreds of form templates and save precious time. Renew today for unparalleled form-building speed.', 'formidable' ),
175 'link_text' => esc_html__( 'Renew Now', 'formidable' ),
176 'link_url' => $args['renew_link'],
177 'id' => 'frm-renew-subscription-banner',
178 )
179 );
180 return;
181 }
182
183 // Show 'upgrade' banner for non-elite users.
184 if ( ! in_array( FrmAddonsController::license_type(), array( 'elite', 'business' ), true ) ) {
185 FrmTipsHelper::show_admin_cta(
186 array(
187 'title' => sprintf(
188 /* translators: %1$s: Open span tag, %2$s: Close span tag */
189 esc_html__( 'Get Super Powers with %1$s%2$s More Pre-built Forms', 'formidable' ) . ' 🦸',
190 '<span class="frm-form-templates-extra-templates-count">',
191 '</span>'
192 ),
193 'description' => esc_html__( 'Unleash the potential of hundreds of additional form templates and save precious time. Upgrade today for unparalleled form-building capabilities.', 'formidable' ),
194 'link_text' => esc_html__( 'Upgrade to PRO', 'formidable' ),
195 'link_url' => $args['upgrade_link'],
196 'id' => 'frm-upgrade-banner',
197 )
198 );
199 }
200 }
201 }
202