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

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

334 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 );
180
181 $icon = array_key_exists( $slug, $icons_map ) ? 'frm_' . $icons_map[ $slug ] . '_icon' : 'frm_logo_icon';
182
183 if ( 'ai' === $slug ) {
184 $icon = str_replace( '_', '-', $icon );
185 }
186
187 FrmAppHelper::icon_by_class( 'frmfont ' . $icon );
188 }
189
190 /**
191 * Echo attributes for a given addon.
192 *
193 * @since 6.15
194 *
195 * @param array $addon
196 *
197 * @return void
198 */
199 public static function add_addon_attributes( $addon ) {
200 self::set_plan_required( $addon );
201
202 $attributes = array(
203 'tabindex' => '0',
204 'frm-search-text' => strtolower( $addon['title'] . ' ' . esc_html( $addon['excerpt'] ) ),
205 );
206
207 // Set 'data-slug' attribute.
208 if ( ! empty( $addon['slug'] ) ) {
209 $attributes['data-slug'] = $addon['slug'];
210 }
211
212 // Set 'data-categories' attribute.
213 if ( ! empty( $addon['category-slugs'] ) ) {
214 $attributes['data-categories'] = implode( ',', $addon['category-slugs'] );
215 }
216
217 $attributes['class'] = self::prepare_single_addon_classes( $addon );
218
219 FrmAppHelper::array_to_html_params( $attributes, true );
220 }
221
222 /**
223 * Add classes for a given addon.
224 *
225 * @since 6.15
226 *
227 * @param array $addon
228 *
229 * @return string
230 */
231 private static function prepare_single_addon_classes( $addon ) {
232 $class_names = array( 'frm-card-item frm-flex-col' );
233 $class_names[] = 'plugin-card-' . $addon['slug'];
234 $class_names[] = 'frm-addon-' . $addon['status']['type'];
235
236 if ( self::is_locked() ) {
237 $class_names[] = 'frm-locked-item';
238 }
239
240 return implode( ' ', $class_names );
241 }
242
243 /**
244 * Check if a given addon is locked.
245 *
246 * @return bool
247 */
248 public static function is_locked() {
249 return self::$plan_required || ! FrmAppHelper::pro_is_installed();
250 }
251
252 /**
253 * Set the required plan for the given addon.
254 *
255 * @note
256 * Because the `FrmFormsHelper::get_plan_required` changes $addon by reference,
257 * we save the result inside a static field called `$plan_required`.
258 *
259 * @since 6.15
260 *
261 * @param array $addon The addon array that will be modified by reference.
262 *
263 * @return void
264 */
265 private static function set_plan_required( $addon ) {
266 self::$plan_required = FrmFormsHelper::get_plan_required( $addon );
267 }
268
269 /**
270 * Get the required plan.
271 *
272 * @since 6.15
273 *
274 * @return false|string
275 */
276 public static function get_plan() {
277 return self::$plan_required;
278 }
279
280 /**
281 * Shows five star rating, used on Views page if only Lite plugins are installed.
282 *
283 * @since 6.17
284 *
285 * @param string $color Star color.
286 *
287 * @return void
288 */
289 public static function show_five_star_rating( $color = 'black' ) {
290 $icon = file_get_contents( FrmAppHelper::plugin_path() . '/images/star.svg' );
291 ?>
292 <span style="color: <?php echo esc_attr( $color ); ?>;">
293 <?php
294 for ( $i = 0; $i < 5; $i++ ) {
295 echo $icon; // phpcs:ignore WordPress.Security.EscapeOutput.OutputNotEscaped
296 }
297 ?>
298 </span>
299 <?php
300 }
301
302 /**
303 * Shows the guarantee icon.
304 *
305 * @since 6.17
306 *
307 * @return void
308 */
309 public static function guarantee_icon() {
310 ?>
311 <img src="<?php echo esc_url( FrmAppHelper::plugin_url() . '/images/guarantee.svg' ); ?>" alt="" />
312 <?php
313 }
314
315 /**
316 * Gets reviews text.
317 *
318 * @since 6.17
319 *
320 * @param string $count Review count.
321 * @param string $site Site name.
322 *
323 * @return string
324 */
325 public static function get_reviews_text( $count, $site ) {
326 return sprintf(
327 // Translators: %1$s is the number of reviews, %2$s is the site name.
328 __( 'Based on %1$s reviews on %2$s', 'formidable' ),
329 $count,
330 $site
331 );
332 }
333 }
334