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

340 lines 8.6 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 // phpcs:disable Generic.WhiteSpace.ScopeIndent
136 ?>
137 <p class="frm-py-2xs">
138 <span class="frm-font-medium frm-text-grey-700"><?php esc_html_e( 'Missing add-ons?', 'formidable' ); ?></span>
139 <a href="#" id="frm_reconnect_link" class="frm-show-authorized frm-font-semibold" data-refresh="1">
140 <?php esc_html_e( 'Check now for a recent upgrade or renewal', 'formidable' ); ?>
141 </a>
142 </p>
143 <?php
144 // phpcs:enable Generic.WhiteSpace.ScopeIndent
145 }
146
147 /**
148 * Get the icon for a specific addon.
149 *
150 * @since 6.15
151 *
152 * @param string $slug The slug of the addon.
153 *
154 * @return void
155 */
156 public static function get_addon_icon( $slug ) {
157 $icons_map = array(
158 'acf-forms' => 'acfforms',
159 'activecampaign-wordpress-plugin' => 'activecampaign',
160 'ai' => 'ai-form',
161 'authorize-net-aim' => 'authorize',
162 'aweber' => 'aweber',
163 'bootstrap' => 'bootstrap',
164 'bootstrap-modal' => 'bootstrap',
165 'campaign-monitor' => 'campaignmonitor',
166 'constant-contact' => 'constant_contact',
167 'getresponse-wordpress-plugin' => 'getresponse',
168 'google-sheets' => 'googlesheets',
169 'highrise' => 'highrise',
170 'hubspot-wordpress' => 'hubspot',
171 'mailchimp' => 'mailchimp',
172 'mailpoet-newsletters' => 'mailpoet',
173 'paypal-standard' => 'paypal',
174 'polylang' => 'polylang',
175 'salesforce' => 'salesforcealt',
176 'stripe' => 'stripealt',
177 'twilio' => 'twilio',
178 'woocommerce' => 'woocommerce',
179 'zapier' => 'zapier',
180 'convertkit' => 'convertkit',
181 'n8n' => 'n8n',
182 );
183
184 $icon = array_key_exists( $slug, $icons_map ) ? 'frm_' . $icons_map[ $slug ] . '_icon' : 'frm_logo_icon';
185
186 if ( 'ai' === $slug ) {
187 $icon = str_replace( '_', '-', $icon );
188 }
189
190 FrmAppHelper::icon_by_class( 'frmfont ' . $icon );
191 }
192
193 /**
194 * Echo attributes for a given addon.
195 *
196 * @since 6.15
197 *
198 * @param array $addon
199 *
200 * @return void
201 */
202 public static function add_addon_attributes( $addon ) {
203 self::set_plan_required( $addon );
204
205 $attributes = array(
206 'tabindex' => '0',
207 'frm-search-text' => strtolower( $addon['title'] . ' ' . esc_html( $addon['excerpt'] ) ),
208 );
209
210 // Set 'data-slug' attribute.
211 if ( ! empty( $addon['slug'] ) ) {
212 $attributes['data-slug'] = $addon['slug'];
213 }
214
215 // Set 'data-categories' attribute.
216 if ( ! empty( $addon['category-slugs'] ) ) {
217 $attributes['data-categories'] = implode( ',', $addon['category-slugs'] );
218 }
219
220 $attributes['class'] = self::prepare_single_addon_classes( $addon );
221
222 FrmAppHelper::array_to_html_params( $attributes, true );
223 }
224
225 /**
226 * Add classes for a given addon.
227 *
228 * @since 6.15
229 *
230 * @param array $addon
231 *
232 * @return string
233 */
234 private static function prepare_single_addon_classes( $addon ) {
235 $class_names = array( 'frm-card-item frm-flex-col' );
236 $class_names[] = 'plugin-card-' . $addon['slug'];
237 $class_names[] = 'frm-addon-' . $addon['status']['type'];
238
239 if ( self::is_locked() ) {
240 $class_names[] = 'frm-locked-item';
241 }
242
243 return implode( ' ', $class_names );
244 }
245
246 /**
247 * Check if a given addon is locked.
248 *
249 * @return bool
250 */
251 public static function is_locked() {
252 return self::$plan_required || ! FrmAppHelper::pro_is_installed();
253 }
254
255 /**
256 * Set the required plan for the given addon.
257 *
258 * @note
259 * Because the `FrmFormsHelper::get_plan_required` changes $addon by reference,
260 * we save the result inside a static field called `$plan_required`.
261 *
262 * @since 6.15
263 *
264 * @param array $addon The addon array that will be modified by reference.
265 *
266 * @return void
267 */
268 private static function set_plan_required( $addon ) {
269 self::$plan_required = FrmFormsHelper::get_plan_required( $addon );
270 }
271
272 /**
273 * Get the required plan.
274 *
275 * @since 6.15
276 *
277 * @return false|string
278 */
279 public static function get_plan() {
280 return self::$plan_required;
281 }
282
283 /**
284 * Shows five star rating, used on Views page if only Lite plugins are installed.
285 *
286 * @since 6.17
287 *
288 * @param string $color Star color.
289 *
290 * @return void
291 */
292 public static function show_five_star_rating( $color = 'black' ) {
293 // phpcs:disable Generic.WhiteSpace.ScopeIndent
294 ?>
295 <span style="color: <?php echo esc_attr( $color ); ?>;">
296 <?php
297 for ( $i = 0; $i < 5; $i++ ) {
298 readfile( FrmAppHelper::plugin_path() . '/images/star.svg' );
299 }
300 ?>
301 </span>
302 <?php
303 // phpcs:enable Generic.WhiteSpace.ScopeIndent
304 }
305
306 /**
307 * Shows the guarantee icon.
308 *
309 * @since 6.17
310 *
311 * @return void
312 */
313 public static function guarantee_icon() {
314 // phpcs:disable Generic.WhiteSpace.ScopeIndent
315 ?>
316 <img src="<?php echo esc_url( FrmAppHelper::plugin_url() . '/images/guarantee.svg' ); ?>" alt="" />
317 <?php
318 // phpcs:enable Generic.WhiteSpace.ScopeIndent
319 }
320
321 /**
322 * Gets reviews text.
323 *
324 * @since 6.17
325 *
326 * @param string $count Review count.
327 * @param string $site Site name.
328 *
329 * @return string
330 */
331 public static function get_reviews_text( $count, $site ) {
332 return sprintf(
333 // Translators: %1$s is the number of reviews, %2$s is the site name.
334 __( 'Based on %1$s reviews on %2$s', 'formidable' ),
335 $count,
336 $site
337 );
338 }
339 }
340