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

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

464 lines 11.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 die( 'You are not allowed to call this page directly.' );
4 }
5
6 class FrmTipsHelper {
7
8 /**
9 * @param string $callback
10 * @param string $html
11 *
12 * @return void
13 */
14 public static function pro_tip( $callback, $html = '' ) {
15 if ( FrmAppHelper::pro_is_installed() ) {
16 return;
17 }
18
19 $tips = self::$callback();
20 $tip = self::get_random_tip( $tips );
21
22 self::show_tip( $tip, $html );
23 }
24
25 /**
26 * Shows tip.
27 *
28 * @since 6.0
29 *
30 * @param array $tip {
31 * Tip args.
32 *
33 * @type array $link Tip link data. See the first parameter of {@see FrmAppHelper::admin_upgrade_link()} for more details.
34 * @type string $page The based link of the tip. If this is empty, `https://formidableforms.com/lite-upgrade/` will
35 * be used. Otherwise, `https://formidableforms.com/{$page}` will be used.
36 * @type string $tip Tip text.
37 * @type string $call Call to action text.
38 * }
39 *
40 * @param string $html
41 *
42 * @return void
43 */
44 public static function show_tip( $tip, $html = '' ) {
45 $defaults = array(
46 'page' => '',
47 'class' => 'frm-mt-0',
48 );
49 $tip = array_merge( $defaults, $tip );
50
51 if ( isset( $tip['link'] ) && ! isset( $tip['link']['medium'] ) && ! isset( $tip['link']['campaign'] ) ) {
52 $tip['link']['campaign'] = 'tip';
53 }
54
55 if ( 'p' === $html ) {
56 echo '<p class="frmcenter ' . esc_attr( $tip['class'] ) . '">';
57 }
58
59 $link = self::get_tip_link( $tip );
60 // phpcs:disable Generic.WhiteSpace.ScopeIndent
61 ?>
62 <a href="<?php echo esc_url( $link ); ?>" <?php echo ! empty( $tip['link'] ) ? 'target="_blank"' : ''; ?> class="frm_pro_tip frm-gradient">
63 <span class="frm-tip-badge"><?php esc_html_e( 'PRO TIP', 'formidable' ); ?></span>
64
65 <?php if ( isset( $tip['call'] ) ) { ?>
66 <span class="frm-tip-info">
67 <?php echo esc_html( $tip['tip'] ); ?>
68 </span>
69 <?php } ?>
70 <span class="frm-tip-cta">
71 <?php echo esc_html( $tip['call'] ? $tip['call'] : $tip['tip'] ); ?>
72 </span>
73 </a>
74 <?php
75 // phpcs:enable Generic.WhiteSpace.ScopeIndent
76
77 if ( 'p' === $html ) {
78 echo '</p>';
79 }
80 }
81
82 /**
83 * @since 6.21
84 *
85 * @param array $tip
86 *
87 * @return string
88 */
89 private static function get_tip_link( $tip ) {
90 if ( empty( $tip['tip'] ) ) {
91 return $tip['page'];
92 }
93
94 $cta_link = FrmSalesApi::get_best_sale_value( 'pro_tip_cta_link' );
95
96 if ( $cta_link ) {
97 if ( is_array( $tip['link'] ) ) {
98 return FrmAppHelper::maybe_add_missing_utm( $cta_link, $tip['link'] );
99 }
100
101 return $cta_link;
102 }
103
104 return FrmAppHelper::admin_upgrade_link( $tip['link'], $tip['page'] );
105 }
106
107 /**
108 * Use the correct label for the license.
109 *
110 * @since 6.5.1
111 *
112 * @return string
113 */
114 private static function cta_label() {
115 $cta_text = FrmSalesApi::get_best_sale_value( 'pro_tip_cta_text' );
116
117 if ( $cta_text ) {
118 return $cta_text;
119 }
120
121 return FrmAddonsController::is_license_expired() ? __( 'Renew', 'formidable' ) : __( 'Upgrade to Pro.', 'formidable' );
122 }
123
124 /**
125 * @return array
126 */
127 public static function get_builder_tip() {
128 return array(
129 array(
130 'link' => array(
131 'content' => 'conditional-logic',
132 'param' => 'conditional-logic-wordpress-forms',
133 ),
134 'tip' => __( 'Use conditional logic to shorten your forms and increase conversions.', 'formidable' ),
135 'call' => self::cta_label(),
136 ),
137 array(
138 'link' => array(
139 'content' => 'confirmation-fields',
140 'param' => 'confirmation-fields-wordpress-forms',
141 ),
142 'tip' => __( 'Eliminate input errors with email confirmation fields.', 'formidable' ),
143 'call' => self::cta_label(),
144 ),
145 array(
146 'link' => array(
147 'content' => 'page-breaks',
148 'param' => 'wordpress-multi-page-forms',
149 ),
150 'tip' => __( 'Use page breaks for easier forms.', 'formidable' ),
151 'call' => self::cta_label(),
152 ),
153 array(
154 'link' => array(
155 'content' => 'file-uploads',
156 'param' => 'wordpress-multi-file-upload-fields',
157 ),
158 'tip' => __( 'Skip the follow-ups. Let users upload files.', 'formidable' ),
159 'call' => self::cta_label(),
160 ),
161 array(
162 'link' => array(
163 'content' => 'calculations',
164 'param' => 'field-calculations-wordpress-form',
165 ),
166 'tip' => __( 'Need to calculate a total?', 'formidable' ),
167 'call' => self::cta_label(),
168 ),
169 array(
170 'link' => array(
171 'content' => 'prefill-fields',
172 'param' => 'auto-fill-forms',
173 ),
174 'tip' => __( 'Save time with autofill forms.', 'formidable' ),
175 'call' => self::cta_label(),
176 ),
177 );
178 }
179
180 /**
181 * @return array
182 */
183 public static function get_form_settings_tip() {
184 return array(
185 array(
186 'link' => array(
187 'content' => 'front-edit-b',
188 'param' => 'wordpress-front-end-editing',
189 ),
190 'tip' => __( 'Make your site dynamic. Enable front-end editing.', 'formidable' ),
191 'call' => self::cta_label(),
192 ),
193 array(
194 'link' => array(
195 'content' => 'save-drafts',
196 'param' => 'save-drafts-wordpress-form',
197 ),
198 'tip' => __( 'Long form? Let users save and finish later', 'formidable' ),
199 'call' => self::cta_label(),
200 ),
201 array(
202 'link' => array(
203 'content' => 'form-scheduling',
204 'param' => 'schedule-forms-wordpress',
205 ),
206 'tip' => __( 'Limit form access with built-in scheduling.', 'formidable' ),
207 'call' => self::cta_label(),
208 ),
209 );
210 }
211
212 /**
213 * @return array
214 */
215 public static function get_form_action_tip() {
216 return array(
217 array(
218 'link' => array(
219 'content' => 'email-routing',
220 'param' => 'virtually-unlimited-emails',
221 ),
222 'tip' => __( 'Save time — route emails to the right person automatically.', 'formidable' ),
223 'call' => self::cta_label(),
224 ),
225 array(
226 'link' => array(
227 'content' => 'create-posts',
228 'param' => 'create-posts-pages-wordpress-forms',
229 ),
230 'tip' => __( 'Create blog posts or pages from the front-end.', 'formidable' ),
231 'call' => self::cta_label(),
232 ),
233 array(
234 'link' => array(
235 'content' => 'user-submit',
236 'param' => 'create-posts-pages-wordpress-forms',
237 ),
238 'tip' => __( 'Let your users submit posts on the front-end.', 'formidable' ),
239 'call' => self::cta_label(),
240 ),
241 array(
242 'link' => array(
243 'content' => 'mailchimp',
244 'page' => 'mailchimp-tip',
245 ),
246 'tip' => __( 'Send leads to Mailchimp for instant email follow-up.', 'formidable' ),
247 'call' => self::cta_label(),
248 ),
249 array(
250 'link' => array(
251 'content' => 'paypal-revenue',
252 'page' => 'paypal-increase-revenue-tip',
253 ),
254 'tip' => __( 'Accept PayPal payments and grow your sales.', 'formidable' ),
255 'call' => self::cta_label(),
256 ),
257 array(
258 'link' => array(
259 'content' => 'paypal-fast',
260 'page' => 'paypal-save-time-tip',
261 ),
262 'tip' => __( 'Accept payments now with PayPal integration.', 'formidable' ),
263 'call' => self::cta_label(),
264 ),
265 array(
266 'link' => array(
267 'content' => 'registration',
268 'page' => 'registration-tip',
269 ),
270 'tip' => __( 'Automatically create user accounts.', 'formidable' ),
271 'call' => __( 'Upgrade to boost your site membership.', 'formidable' ),
272 ),
273 array(
274 'link' => array(
275 'content' => 'profile',
276 'page' => 'registration-profile-editing-tip',
277 ),
278 'tip' => __( 'Enable front-end profile editing with User Registration.', 'formidable' ),
279 'call' => self::cta_label(),
280 ),
281 array(
282 'link' => array(
283 'content' => 'twilio-payment',
284 'page' => 'twilio-tip',
285 ),
286 'tip' => __( 'Get SMS alerts for form submissions and payments—just add Twilio.', 'formidable' ),
287 'call' => self::cta_label(),
288 ),
289 array(
290 'link' => array(
291 'content' => 'twilio',
292 'page' => 'twilio-send-tip',
293 ),
294 'tip' => __( 'Use Twilio to send SMS when forms are submitted.', 'formidable' ),
295 'call' => self::cta_label(),
296 ),
297 array(
298 'link' => array(
299 'content' => 'acf-tip',
300 'param' => 'acf-tip',
301 ),
302 'tip' => __( 'Fill Advanced Custom Fields automatically with form entries.', 'formidable' ),
303 'call' => self::cta_label(),
304 ),
305 );
306 }
307
308 /**
309 * @return array
310 */
311 public static function get_styling_tip() {
312 return array(
313 array(
314 'link' => array(
315 'content' => 'style',
316 'param' => 'wordpress-visual-form-styler',
317 ),
318 'tip' => __( 'Make your forms stand out with multiple style templates.', 'formidable' ),
319 'call' => self::cta_label(),
320 ),
321 array(
322 'link' => array(
323 'content' => 'style',
324 'param' => 'bg-image-style-settings',
325 ),
326 'tip' => __( 'Want to add a background image?', 'formidable' ),
327 'call' => self::cta_label(),
328 ),
329 array(
330 'link' => array(
331 'content' => 'style',
332 'param' => 'duplicate-style',
333 ),
334 'tip' => __( 'Want to duplicate a style?', 'formidable' ),
335 'call' => self::cta_label(),
336 ),
337 );
338 }
339
340 /**
341 * @return array
342 */
343 public static function get_entries_tip() {
344 $tips = array(
345 array(
346 'link' => array(
347 'content' => 'entries',
348 'param' => 'form-entry-management-wordpress',
349 ),
350 'tip' => __( 'Edit form entries anytime with entry management.', 'formidable' ),
351 'call' => self::cta_label(),
352 ),
353 array(
354 'link' => array(
355 'content' => 'entries-search',
356 'param' => 'form-entry-management-wordpress',
357 ),
358 'tip' => __( 'Want to search submitted entries?', 'formidable' ),
359 'call' => self::cta_label(),
360 ),
361 array(
362 'link' => array(
363 'content' => 'views',
364 'param' => 'views-display-form-data',
365 ),
366 'tip' => __( 'Turn entries into dynamic content — no code needed.', 'formidable' ),
367 'call' => self::cta_label(),
368 ),
369 );
370
371 return array_merge( $tips, self::get_import_tip() );
372 }
373
374 /**
375 * @return array
376 */
377 public static function get_import_tip() {
378 return array(
379 array(
380 'link' => array(
381 'content' => 'import',
382 'param' => 'importing-exporting-wordpress-forms',
383 ),
384 'tip' => __( 'Want to import entries into your forms?', 'formidable' ),
385 'call' => self::cta_label(),
386 ),
387 );
388 }
389
390 /**
391 * @param array $tips
392 *
393 * @return array
394 */
395 public static function get_random_tip( $tips ) {
396 $count = count( $tips );
397
398 if ( $count === 0 ) {
399 return array();
400 }
401
402 $random = random_int( 0, $count - 1 );
403 return $tips[ $random ];
404 }
405
406 /**
407 * Displays a call-to-action section in the admin area.
408 *
409 * @since 6.7
410 *
411 * @param array $args {
412 * An array of arguments to configure the call-to-action section.
413 *
414 * @type string $title The title of the section.
415 * @type string $description The description of the section.
416 * @type string $link_text The text for the link.
417 * @type string $link_url The URL for the link.
418 * @type string $role The required user role to view the section. Default 'administrator'.
419 * }
420 *
421 * @return void
422 */
423 public static function show_admin_cta( $args ) {
424 $role = ! empty( $args['role'] ) ? $args['role'] : 'administrator';
425
426 if ( ! current_user_can( $role ) ) {
427 // Return early if the user doesn't have the required capability.
428 return;
429 }
430
431 $defaults = array(
432 'title' => '',
433 'description' => '',
434 'link_text' => '',
435 'link_url' => '#',
436 'class' => '',
437 'id' => '',
438 'target' => '_blank',
439 );
440
441 $args = wp_parse_args( $args, $defaults );
442
443 $attributes = array(
444 'class' => trim( 'frm-cta frm-flex frm-p-sm ' . $args['class'] ),
445 );
446
447 if ( $args['id'] ) {
448 $attributes['id'] = $args['id'];
449 }
450
451 require FrmAppHelper::plugin_path() . '/classes/views/shared/admin-cta.php';
452 }
453
454 /**
455 * @deprecated 6.21
456 *
457 * @return array
458 */
459 public static function get_banner_tip() {
460 _deprecated_function( __METHOD__, '6.21' );
461 return array();
462 }
463 }
464