PluginProbe
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More / 6.27
Formidable Forms – WordPress Form Builder for Contact Forms, Calculators, Quizzes & More v6.27
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 / FrmAddonsHelper.php

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

335 lines 8.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Add-Ons 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 add-ons in the admin area.
14 *
15 * @since 6.15
16 */
17 class FrmAddonsHelper {
18 /**
19 * Stores the result of `FrmFormsHelper::get_plan_required`.
20 *
21 * @var string
22 */
23 private static $plan_required;
24
25 /**
26 * Show the CTA to upgrade or renew.
27 *
28 * @since 6.15
29 *
30 * @return void
31 */
32 public static function show_upgrade_renew_cta() {
33 if ( FrmAddonsController::is_license_expired() ) {
34 self::show_expired_cta();
35 return;
36 }
37
38 if ( ! FrmAppHelper::pro_is_connected() ) {
39 self::show_lite_cta();
40 return;
41 }
42
43 if ( 'elite' !== FrmAddonsController::license_type() ) {
44 self::show_elite_cta();
45 }
46 }
47
48 /**
49 * Show 'Renew' banner for expired users.
50 *
51 * @since 6.15
52 *
53 * @return void
54 */
55 private static function show_expired_cta() {
56 FrmTipsHelper::show_admin_cta(
57 array(
58 'class' => 'frm-gradient',
59 'icon' => 'frmfont frm_speaker_icon',
60 'title' => esc_html__( 'Unlock Add-on library', 'formidable' ),
61 'description' => esc_html__( 'Renew your subscription today and access our library of add-ons to supercharge your forms.', 'formidable' ),
62 'link_text' => esc_html__( 'Renew Now', 'formidable' ),
63 'link_url' => FrmAddonsController::is_license_expired(),
64 'id' => 'frm-renew-subscription-banner',
65 )
66 );
67 }
68
69 /**
70 * Show 'Upgrade to Pro' banner for users not connected to Pro.
71 *
72 * @since 6.15
73 *
74 * @return void
75 */
76 private static function show_lite_cta() {
77 FrmTipsHelper::show_admin_cta(
78 array(
79 'class' => 'frm-gradient',
80 'icon' => 'frmfont frm_speaker_icon',
81 'title' => esc_html__( 'Unlock Add-on library', 'formidable' ),
82 'description' => esc_html__( 'Upgrade to Pro and access our library of add-ons to supercharge your forms.', 'formidable' ),
83 'link_text' => esc_html__( 'Upgrade to PRO', 'formidable' ),
84 'link_url' => FrmAppHelper::admin_upgrade_link(
85 array(
86 'medium' => 'addons',
87 'content' => 'upgrade-cta',
88 )
89 ),
90 'id' => 'frm-upgrade-banner',
91 )
92 );
93 }
94
95 /**
96 * Show 'Upgrade' banner for non-elite users.
97 *
98 * @since 6.15
99 *
100 * @return void
101 */
102 private static function show_elite_cta() {
103 FrmTipsHelper::show_admin_cta(
104 array(
105 'title' => esc_html__( 'Unlock Even More Add-ons', 'formidable' ),
106 'description' => sprintf(
107 /* translators: %1$s: Open span tag, %2$s: Close span tag */
108 esc_html__( 'Your plan includes %1$s%2$s add-ons. Upgrade to take your forms even farther', 'formidable' ),
109 '<span class="frm-addons-available-count">',
110 '</span>'
111 ),
112 'link_text' => esc_html__( 'Upgrade to PRO', 'formidable' ),
113 'link_url' => FrmAppHelper::admin_upgrade_link(
114 array(
115 'medium' => 'addons',
116 'content' => 'upgrade-cta',
117 )
118 ),
119 'id' => 'frm-upgrade-banner',
120 )
121 );
122 }
123
124 /**
125 * Displays a reconnect link for checking add-ons status.
126 *
127 * @since 6.15
128 *
129 * @return void
130 */
131 public static function get_reconnect_link() {
132 if ( ! FrmAppHelper::pro_is_connected() ) {
133 return;
134 }
135 ?>
136 <p class="frm-py-2xs">
137 <span class="frm-font-medium frm-text-grey-700"><?php esc_html_e( 'Missing add-ons?', 'formidable' ); ?></span>
138 <a href="#" id="frm_reconnect_link" class="frm-show-authorized frm-font-semibold" data-refresh="1">
139 <?php esc_html_e( 'Check now for a recent upgrade or renewal', 'formidable' ); ?>
140 </a>
141 </p>
142 <?php
143 }
144
145 /**
146 * Get the icon for a specific addon.
147 *
148 * @since 6.15
149 *
150 * @param string $slug The slug of the addon.
151 *
152 * @return void
153 */
154 public static function get_addon_icon( $slug ) {
155 $icons_map = array(
156 'acf-forms' => 'acfforms',
157 'activecampaign-wordpress-plugin' => 'activecampaign',
158 'ai' => 'ai-form',
159 'authorize-net-aim' => 'authorize',
160 'aweber' => 'aweber',
161 'bootstrap' => 'bootstrap',
162 'bootstrap-modal' => 'bootstrap',
163 'campaign-monitor' => 'campaignmonitor',
164 'constant-contact' => 'constant_contact',
165 'getresponse-wordpress-plugin' => 'getresponse',
166 'google-sheets' => 'googlesheets',
167 'highrise' => 'highrise',
168 'hubspot-wordpress' => 'hubspot',
169 'mailchimp' => 'mailchimp',
170 'mailpoet-newsletters' => 'mailpoet',
171 'paypal-standard' => 'paypal',
172 'polylang' => 'polylang',
173 'salesforce' => 'salesforcealt',
174 'stripe' => 'stripealt',
175 'twilio' => 'twilio',
176 'woocommerce' => 'woocommerce',
177 'zapier' => 'zapier',
178 'convertkit' => 'convertkit',
179 'n8n' => 'n8n',
180 );
181
182 $icon = array_key_exists( $slug, $icons_map ) ? 'frm_' . $icons_map[ $slug ] . '_icon' : 'frm_logo_icon';
183
184 if ( 'ai' === $slug ) {
185 $icon = str_replace( '_', '-', $icon );
186 }
187
188 FrmAppHelper::icon_by_class( 'frmfont ' . $icon );
189 }
190
191 /**
192 * Echo attributes for a given addon.
193 *
194 * @since 6.15
195 *
196 * @param array $addon
197 *
198 * @return void
199 */
200 public static function add_addon_attributes( $addon ) {
201 self::set_plan_required( $addon );
202
203 $attributes = array(
204 'tabindex' => '0',
205 'frm-search-text' => strtolower( $addon['title'] . ' ' . esc_html( $addon['excerpt'] ) ),
206 );
207
208 // Set 'data-slug' attribute.
209 if ( ! empty( $addon['slug'] ) ) {
210 $attributes['data-slug'] = $addon['slug'];
211 }
212
213 // Set 'data-categories' attribute.
214 if ( ! empty( $addon['category-slugs'] ) ) {
215 $attributes['data-categories'] = implode( ',', $addon['category-slugs'] );
216 }
217
218 $attributes['class'] = self::prepare_single_addon_classes( $addon );
219
220 FrmAppHelper::array_to_html_params( $attributes, true );
221 }
222
223 /**
224 * Add classes for a given addon.
225 *
226 * @since 6.15
227 *
228 * @param array $addon
229 *
230 * @return string
231 */
232 private static function prepare_single_addon_classes( $addon ) {
233 $class_names = array( 'frm-card-item frm-flex-col' );
234 $class_names[] = 'plugin-card-' . $addon['slug'];
235 $class_names[] = 'frm-addon-' . $addon['status']['type'];
236
237 if ( self::is_locked() ) {
238 $class_names[] = 'frm-locked-item';
239 }
240
241 return implode( ' ', $class_names );
242 }
243
244 /**
245 * Check if a given addon is locked.
246 *
247 * @return bool
248 */
249 public static function is_locked() {
250 return self::$plan_required || ! FrmAppHelper::pro_is_installed();
251 }
252
253 /**
254 * Set the required plan for the given addon.
255 *
256 * @note
257 * Because the `FrmFormsHelper::get_plan_required` changes $addon by reference,
258 * we save the result inside a static field called `$plan_required`.
259 *
260 * @since 6.15
261 *
262 * @param array $addon The addon array that will be modified by reference.
263 *
264 * @return void
265 */
266 private static function set_plan_required( $addon ) {
267 self::$plan_required = FrmFormsHelper::get_plan_required( $addon );
268 }
269
270 /**
271 * Get the required plan.
272 *
273 * @since 6.15
274 *
275 * @return false|string
276 */
277 public static function get_plan() {
278 return self::$plan_required;
279 }
280
281 /**
282 * Shows five star rating, used on Views page if only Lite plugins are installed.
283 *
284 * @since 6.17
285 *
286 * @param string $color Star color.
287 *
288 * @return void
289 */
290 public static function show_five_star_rating( $color = 'black' ) {
291 $icon = file_get_contents( FrmAppHelper::plugin_path() . '/images/star.svg' );
292 ?>
293 <span style="color: <?php echo esc_attr( $color ); ?>;">
294 <?php
295 for ( $i = 0; $i < 5; $i++ ) {
296 echo $icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
297 }
298 ?>
299 </span>
300 <?php
301 }
302
303 /**
304 * Shows the guarantee icon.
305 *
306 * @since 6.17
307 *
308 * @return void
309 */
310 public static function guarantee_icon() {
311 ?>
312 <img src="<?php echo esc_url( FrmAppHelper::plugin_url() . '/images/guarantee.svg' ); ?>" alt="" />
313 <?php
314 }
315
316 /**
317 * Gets reviews text.
318 *
319 * @since 6.17
320 *
321 * @param string $count Review count.
322 * @param string $site Site name.
323 *
324 * @return string
325 */
326 public static function get_reviews_text( $count, $site ) {
327 return sprintf(
328 // Translators: %1$s is the number of reviews, %2$s is the site name.
329 __( 'Based on %1$s reviews on %2$s', 'formidable' ),
330 $count,
331 $site
332 );
333 }
334 }
335