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