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

265 lines 7.0 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 * @return void
30 */
31 public static function show_upgrade_renew_cta() {
32 if ( FrmAddonsController::is_license_expired() ) {
33 self::show_expired_cta();
34 return;
35 }
36
37 if ( ! FrmAppHelper::pro_is_connected() ) {
38 self::show_lite_cta();
39 return;
40 }
41
42 if ( 'elite' !== FrmAddonsController::license_type() ) {
43 self::show_elite_cta();
44 }
45 }
46
47 /**
48 * Show 'Renew' banner for expired users.
49 *
50 * @since 6.15
51 * @return void
52 */
53 private static function show_expired_cta() {
54 FrmTipsHelper::show_admin_cta(
55 array(
56 'title' => esc_html__( 'Unlock Add-on library', 'formidable' ),
57 'description' => esc_html__( 'Renew your subscription today and access our library of add-ons to supercharge your forms.', 'formidable' ),
58 'link_text' => esc_html__( 'Renew Now', 'formidable' ),
59 'link_url' => FrmAddonsController::is_license_expired(),
60 'id' => 'frm-renew-subscription-banner',
61 )
62 );
63 }
64
65 /**
66 * Show 'Upgrade to Pro' banner for users not connected to Pro.
67 *
68 * @since 6.15
69 * @return void
70 */
71 private static function show_lite_cta() {
72 FrmTipsHelper::show_admin_cta(
73 array(
74 'title' => esc_html__( 'Unlock Add-on library', 'formidable' ),
75 'description' => esc_html__( 'Upgrade to Pro and access our library of add-ons to supercharge your forms.', 'formidable' ),
76 'link_text' => esc_html__( 'Upgrade to PRO', 'formidable' ),
77 'link_url' => FrmAppHelper::admin_upgrade_link(
78 array(
79 'medium' => 'addons',
80 'content' => 'upgrade-cta',
81 )
82 ),
83 'id' => 'frm-upgrade-banner',
84 )
85 );
86 }
87
88 /**
89 * Show 'Upgrade' banner for non-elite users.
90 *
91 * @since 6.15
92 * @return void
93 */
94 private static function show_elite_cta() {
95 FrmTipsHelper::show_admin_cta(
96 array(
97 'title' => esc_html__( 'Unlock Even More Add-ons', 'formidable' ),
98 'description' => sprintf(
99 /* translators: %1$s: Open span tag, %2$s: Close span tag */
100 esc_html__( 'Your plan includes %1$s%2$s add-ons. Upgrade to take your forms even farther', 'formidable' ),
101 '<span class="frm-addons-available-count">',
102 '</span>'
103 ),
104 'link_text' => esc_html__( 'Upgrade to PRO', 'formidable' ),
105 'link_url' => FrmAppHelper::admin_upgrade_link(
106 array(
107 'medium' => 'addons',
108 'content' => 'upgrade-cta',
109 )
110 ),
111 'id' => 'frm-upgrade-banner',
112 )
113 );
114 }
115
116 /**
117 * Displays a reconnect link for checking add-ons status.
118 *
119 * @since 6.15
120 * @return void
121 */
122 public static function get_reconnect_link() {
123 if ( ! FrmAppHelper::pro_is_connected() ) {
124 return;
125 }
126 ?>
127 <p class="frm-py-2xs">
128 <span class="frm-font-medium frm-text-grey-700"><?php esc_html_e( 'Missing add-ons?', 'formidable' ); ?></span>
129 <a href="#" id="frm_reconnect_link" class="frm-show-authorized frm-font-semibold" data-refresh="1">
130 <?php esc_html_e( 'Check now for a recent upgrade or renewal', 'formidable' ); ?>
131 </a>
132 </p>
133 <?php
134 }
135
136 /**
137 * Get the icon for a specific addon.
138 *
139 * @since 6.15
140 * @param string $slug The slug of the addon.
141 * @return void
142 */
143 public static function get_addon_icon( $slug ) {
144 $icons_map = array(
145 'acf-forms' => 'acfforms',
146 'activecampaign-wordpress-plugin' => 'activecampaign',
147 'ai' => 'ai-form',
148 'authorize-net-aim' => 'authorize',
149 'aweber' => 'aweber',
150 'bootstrap' => 'bootstrap',
151 'bootstrap-modal' => 'bootstrap',
152 'campaign-monitor' => 'campaignmonitor',
153 'constant-contact' => 'constant_contact',
154 'getresponse-wordpress-plugin' => 'getresponse',
155 'google-sheets' => 'googlesheets',
156 'highrise' => 'highrise',
157 'hubspot-wordpress' => 'hubspot',
158 'mailchimp' => 'mailchimp',
159 'mailpoet-newsletters' => 'mailpoet',
160 'paypal-standard' => 'paypal',
161 'polylang' => 'polylang',
162 'salesforce' => 'salesforcealt',
163 'stripe' => 'stripealt',
164 'twilio' => 'twilio',
165 'woocommerce' => 'woocommerce',
166 'zapier' => 'zapier',
167 'convertkit' => 'convertkit',
168 );
169
170 $icon = array_key_exists( $slug, $icons_map ) ? 'frm_' . $icons_map[ $slug ] . '_icon' : 'frm_logo_icon';
171 if ( 'ai' === $slug ) {
172 $icon = str_replace( '_', '-', $icon );
173 }
174
175 FrmAppHelper::icon_by_class( 'frmfont ' . $icon );
176 }
177
178 /**
179 * Echo attributes for a given addon.
180 *
181 * @since 6.15
182 *
183 * @param array $addon
184 * @return void
185 */
186 public static function add_addon_attributes( $addon ) {
187 self::set_plan_required( $addon );
188
189 $attributes = array(
190 'tabindex' => '0',
191 'frm-search-text' => strtolower( $addon['title'] . ' ' . esc_html( $addon['excerpt'] ) ),
192 );
193
194 // Set 'data-slug' attribute.
195 if ( ! empty( $addon['slug'] ) ) {
196 $attributes['data-slug'] = $addon['slug'];
197 }
198
199 // Set 'data-categories' attribute.
200 if ( ! empty( $addon['category-slugs'] ) ) {
201 $attributes['data-categories'] = implode( ',', $addon['category-slugs'] );
202 }
203
204 $attributes['class'] = self::prepare_single_addon_classes( $addon );
205
206 FrmAppHelper::array_to_html_params( $attributes, true );
207 }
208
209 /**
210 * Add classes for a given addon.
211 *
212 * @since 6.15
213 *
214 * @param array $addon
215 * @return string
216 */
217 private static function prepare_single_addon_classes( $addon ) {
218 $class_names = array( 'frm-card-item frm-flex-col' );
219 $class_names[] = 'plugin-card-' . $addon['slug'];
220 $class_names[] = 'frm-addon-' . $addon['status']['type'];
221
222 if ( self::is_locked() ) {
223 $class_names[] = 'frm-locked-item';
224 }
225
226 return implode( ' ', $class_names );
227 }
228
229 /**
230 * Check if a given addon is locked.
231 *
232 * @return bool
233 */
234 public static function is_locked() {
235 return self::$plan_required || ! FrmAppHelper::pro_is_installed();
236 }
237
238 /**
239 * Set the required plan for the given addon.
240 *
241 * @note
242 * Because the `FrmFormsHelper::get_plan_required` changes $addon by reference,
243 * we save the result inside a static field called `$plan_required`.
244 *
245 * @since 6.15
246 *
247 * @param array $addon The addon array that will be modified by reference.
248 * @return void
249 */
250 private static function set_plan_required( $addon ) {
251 self::$plan_required = FrmFormsHelper::get_plan_required( $addon );
252 }
253
254 /**
255 * Get the required plan.
256 *
257 * @since 6.15
258 *
259 * @return false|string
260 */
261 public static function get_plan() {
262 return self::$plan_required;
263 }
264 }
265