| 1 |
<?php |
| 2 |
/** |
| 3 |
* Onboarding Wizard Controller 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 |
* Handles the Onboarding Wizard page in the admin area. |
| 14 |
* |
| 15 |
* @since 6.9 |
| 16 |
*/ |
| 17 |
class FrmOnboardingWizardController { |
| 18 |
|
| 19 |
/** |
| 20 |
* The slug of the Onboarding Wizard page. |
| 21 |
* |
| 22 |
* @var string |
| 23 |
*/ |
| 24 |
const PAGE_SLUG = 'formidable-onboarding-wizard'; |
| 25 |
|
| 26 |
/** |
| 27 |
* The script handle. |
| 28 |
* |
| 29 |
* @var string |
| 30 |
*/ |
| 31 |
const SCRIPT_HANDLE = 'frm-onboarding-wizard'; |
| 32 |
|
| 33 |
/** |
| 34 |
* The required user capability to view the Onboarding Wizard page. |
| 35 |
* |
| 36 |
* @var string |
| 37 |
*/ |
| 38 |
const REQUIRED_CAPABILITY = 'frm_view_forms'; |
| 39 |
|
| 40 |
/** |
| 41 |
* Transient name used for managing redirection to the Onboarding Wizard page. |
| 42 |
* |
| 43 |
* @var string |
| 44 |
*/ |
| 45 |
const TRANSIENT_NAME = 'frm_activation_redirect'; |
| 46 |
|
| 47 |
/** |
| 48 |
* Transient value associated with the redirection to the Onboarding Wizard page. |
| 49 |
* Used when activating a single plugin. |
| 50 |
* |
| 51 |
* @var string |
| 52 |
*/ |
| 53 |
const TRANSIENT_VALUE = 'formidable-welcome'; |
| 54 |
|
| 55 |
/** |
| 56 |
* Transient value associated with the redirection to the Onboarding Wizard page. |
| 57 |
* Used when activating multiple plugins at once. |
| 58 |
* |
| 59 |
* @var string |
| 60 |
*/ |
| 61 |
const TRANSIENT_MULTI_VALUE = 'formidable-welcome-multi'; |
| 62 |
|
| 63 |
/** |
| 64 |
* Option name for storing the redirect status for the Onboarding Wizard page. |
| 65 |
* |
| 66 |
* @var string |
| 67 |
*/ |
| 68 |
const REDIRECT_STATUS_OPTION = 'frm_welcome_redirect'; |
| 69 |
|
| 70 |
/** |
| 71 |
* Option name for tracking if the onboarding wizard was skipped. |
| 72 |
* |
| 73 |
* @var string |
| 74 |
*/ |
| 75 |
const ONBOARDING_SKIPPED_OPTION = 'frm_onboarding_skipped'; |
| 76 |
|
| 77 |
/** |
| 78 |
* Defines the initial step for redirection within the application flow. |
| 79 |
* |
| 80 |
* @var string |
| 81 |
*/ |
| 82 |
const INITIAL_STEP = 'consent-tracking'; |
| 83 |
|
| 84 |
/** |
| 85 |
* Option name to store usage data. |
| 86 |
* |
| 87 |
* @var string |
| 88 |
*/ |
| 89 |
const USAGE_DATA_OPTION = 'frm_onboarding_usage_data'; |
| 90 |
|
| 91 |
/** |
| 92 |
* Holds the URL to access the Onboarding Wizard's page. |
| 93 |
* |
| 94 |
* @var string |
| 95 |
*/ |
| 96 |
private static $page_url = ''; |
| 97 |
|
| 98 |
/** |
| 99 |
* Holds a list of add-ons available for installation. |
| 100 |
* |
| 101 |
* @var array |
| 102 |
*/ |
| 103 |
private static $available_addons = array(); |
| 104 |
|
| 105 |
/** |
| 106 |
* Path to views. |
| 107 |
* |
| 108 |
* @var string |
| 109 |
*/ |
| 110 |
private static $view_path = ''; |
| 111 |
|
| 112 |
/** |
| 113 |
* Upgrade URL. |
| 114 |
* |
| 115 |
* @var string |
| 116 |
*/ |
| 117 |
private static $upgrade_link = ''; |
| 118 |
|
| 119 |
/** |
| 120 |
* Initialize hooks for template page only. |
| 121 |
* |
| 122 |
* @since 6.9 |
| 123 |
*/ |
| 124 |
public static function load_admin_hooks() { |
| 125 |
self::set_page_url(); |
| 126 |
add_action( 'admin_init', __CLASS__ . '::do_admin_redirects' ); |
| 127 |
|
| 128 |
if ( self::has_onboarding_been_skipped() ) { |
| 129 |
add_filter( 'option_frm_inbox', __CLASS__ . '::add_wizard_to_floating_links' ); |
| 130 |
} |
| 131 |
|
| 132 |
// Load page if admin page is Onboarding Wizard. |
| 133 |
self::maybe_load_page(); |
| 134 |
} |
| 135 |
|
| 136 |
/** |
| 137 |
* Performs a safe redirect to the welcome screen when the plugin is activated. |
| 138 |
* On single activation, we will redirect immediately. |
| 139 |
* When activating multiple plugins, the redirect is delayed until a Formidable page is loaded. |
| 140 |
* |
| 141 |
* @return void |
| 142 |
*/ |
| 143 |
public static function do_admin_redirects() { |
| 144 |
$current_page = FrmAppHelper::simple_get( 'page', 'sanitize_title' ); |
| 145 |
|
| 146 |
// Prevent endless loop. |
| 147 |
if ( $current_page === self::PAGE_SLUG ) { |
| 148 |
return; |
| 149 |
} |
| 150 |
|
| 151 |
// Only do this for single site installs. |
| 152 |
if ( is_network_admin() ) { // phpcs:ignore WordPress.Security.NonceVerification.Missing |
| 153 |
self::mark_onboarding_as_skipped(); |
| 154 |
return; |
| 155 |
} |
| 156 |
|
| 157 |
if ( self::has_onboarding_been_skipped() || FrmAppHelper::pro_is_connected() ) { |
| 158 |
return; |
| 159 |
} |
| 160 |
|
| 161 |
$transient_value = get_transient( self::TRANSIENT_NAME ); |
| 162 |
if ( ! in_array( $transient_value, array( self::TRANSIENT_VALUE, self::TRANSIENT_MULTI_VALUE ), true ) ) { |
| 163 |
return; |
| 164 |
} |
| 165 |
|
| 166 |
if ( isset( $_GET['activate-multi'] ) ) { |
| 167 |
/** |
| 168 |
* $_GET['activate-multi'] is set after activating multiple plugins. |
| 169 |
* In this case, change the transient value so we know for future checks. |
| 170 |
*/ |
| 171 |
set_transient( self::TRANSIENT_NAME, self::TRANSIENT_MULTI_VALUE, 60 ); |
| 172 |
return; |
| 173 |
} |
| 174 |
|
| 175 |
if ( self::TRANSIENT_MULTI_VALUE === $transient_value && ! FrmAppHelper::is_formidable_admin() ) { |
| 176 |
// For multi-activations we want to only redirect when a user loads a Formidable page. |
| 177 |
return; |
| 178 |
} |
| 179 |
|
| 180 |
set_transient( self::TRANSIENT_NAME, 'no', 60 ); |
| 181 |
|
| 182 |
// Prevent redirect with every activation. |
| 183 |
if ( self::has_already_redirected() ) { |
| 184 |
return; |
| 185 |
} |
| 186 |
|
| 187 |
// Redirect to the onboarding wizard's initial step. |
| 188 |
$page_url = add_query_arg( 'step', self::INITIAL_STEP, self::$page_url ); |
| 189 |
if ( wp_safe_redirect( esc_url_raw( $page_url ) ) ) { |
| 190 |
exit; |
| 191 |
} |
| 192 |
} |
| 193 |
|
| 194 |
/** |
| 195 |
* Initializes the Onboarding Wizard setup if on its designated admin page. |
| 196 |
* |
| 197 |
* @since 6.9 |
| 198 |
* |
| 199 |
* @return void |
| 200 |
*/ |
| 201 |
public static function maybe_load_page() { |
| 202 |
if ( self::is_onboarding_wizard_page() ) { |
| 203 |
// Dismiss the onboarding wizard message so it stops appearing after it is clicked. |
| 204 |
$message = new FrmInbox(); |
| 205 |
$message->dismiss( 'onboarding_wizard' ); |
| 206 |
|
| 207 |
add_action( 'admin_menu', __CLASS__ . '::menu', 99 ); |
| 208 |
add_action( 'admin_init', __CLASS__ . '::assign_properties' ); |
| 209 |
add_action( 'admin_enqueue_scripts', __CLASS__ . '::enqueue_assets', 15 ); |
| 210 |
add_action( 'admin_head', __CLASS__ . '::remove_menu' ); |
| 211 |
|
| 212 |
add_filter( 'admin_body_class', __CLASS__ . '::add_admin_body_classes', 999 ); |
| 213 |
add_filter( 'frm_show_footer_links', '__return_false' ); |
| 214 |
} |
| 215 |
} |
| 216 |
|
| 217 |
/** |
| 218 |
* Initializes class properties with essential values for operation. |
| 219 |
* |
| 220 |
* @since 6.9 |
| 221 |
* |
| 222 |
* @return void |
| 223 |
*/ |
| 224 |
public static function assign_properties() { |
| 225 |
self::$view_path = FrmAppHelper::plugin_path() . '/classes/views/onboarding-wizard/'; |
| 226 |
|
| 227 |
self::$upgrade_link = FrmAppHelper::admin_upgrade_link( |
| 228 |
array( |
| 229 |
'medium' => 'onboarding-wizard', |
| 230 |
'content' => 'upgrade', |
| 231 |
) |
| 232 |
); |
| 233 |
|
| 234 |
self::set_available_addons(); |
| 235 |
} |
| 236 |
|
| 237 |
/** |
| 238 |
* Add Onboarding Wizard menu item to sidebar and define index page. |
| 239 |
* |
| 240 |
* @since 6.9 |
| 241 |
* |
| 242 |
* @return void |
| 243 |
*/ |
| 244 |
public static function menu() { |
| 245 |
if ( ! current_user_can( 'activate_plugins' ) ) { |
| 246 |
return; |
| 247 |
} |
| 248 |
|
| 249 |
$label = __( 'Onboarding Wizard', 'formidable' ); |
| 250 |
|
| 251 |
add_submenu_page( |
| 252 |
'formidable', |
| 253 |
'Formidable | ' . $label, |
| 254 |
$label, |
| 255 |
self::REQUIRED_CAPABILITY, |
| 256 |
self::PAGE_SLUG, |
| 257 |
array( __CLASS__, 'render' ) |
| 258 |
); |
| 259 |
} |
| 260 |
|
| 261 |
/** |
| 262 |
* Renders the Onboarding Wizard page in the WordPress admin area. |
| 263 |
* |
| 264 |
* @since 6.9 |
| 265 |
* |
| 266 |
* @return void |
| 267 |
*/ |
| 268 |
public static function render() { |
| 269 |
if ( self::has_onboarding_been_skipped() ) { |
| 270 |
delete_option( self::ONBOARDING_SKIPPED_OPTION ); |
| 271 |
self::has_already_redirected(); |
| 272 |
} |
| 273 |
|
| 274 |
// Include SVG images for icons. |
| 275 |
FrmAppHelper::include_svg(); |
| 276 |
|
| 277 |
$view_path = self::get_view_path(); |
| 278 |
$available_addons = self::get_available_addons(); |
| 279 |
$upgrade_link = self::get_upgrade_link(); |
| 280 |
$addons_count = FrmAddonsController::get_addons_count(); |
| 281 |
$license_key = base64_decode( rawurldecode( FrmAppHelper::get_param( 'key', '', 'request', 'sanitize_text_field' ) ) ); |
| 282 |
$pro_is_installed = FrmAppHelper::pro_is_installed(); |
| 283 |
|
| 284 |
// Note: Add step parts in order. |
| 285 |
$step_parts = array( |
| 286 |
'consent-tracking' => 'steps/consent-tracking-step.php', |
| 287 |
'install-addons' => 'steps/install-addons-step.php', |
| 288 |
'success' => 'steps/success-step.php', |
| 289 |
'unsuccessful' => 'steps/unsuccessful-step.php', |
| 290 |
); |
| 291 |
|
| 292 |
include $view_path . 'index.php'; |
| 293 |
} |
| 294 |
|
| 295 |
/** |
| 296 |
* Handle AJAX request to setup the "Never miss an important update" step. |
| 297 |
* |
| 298 |
* @since 6.9 |
| 299 |
* |
| 300 |
* @return void |
| 301 |
*/ |
| 302 |
public static function ajax_consent_tracking() { |
| 303 |
// Check permission and nonce. |
| 304 |
FrmAppHelper::permission_check( self::REQUIRED_CAPABILITY ); |
| 305 |
check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 306 |
|
| 307 |
// Update Settings. |
| 308 |
$frm_settings = FrmAppHelper::get_settings(); |
| 309 |
$frm_settings->update_setting( 'tracking', true, 'rest_sanitize_boolean' ); |
| 310 |
|
| 311 |
// Remove the 'FrmProSettingsController::store' action to avoid PHP errors during AJAX call. |
| 312 |
remove_action( 'frm_store_settings', 'FrmProSettingsController::store' ); |
| 313 |
$frm_settings->store(); |
| 314 |
|
| 315 |
self::subscribe_to_active_campaign(); |
| 316 |
|
| 317 |
// Send response. |
| 318 |
wp_send_json_success(); |
| 319 |
} |
| 320 |
|
| 321 |
/** |
| 322 |
* When the user consents to receiving news of updates, subscribe their email to ActiveCampaign. |
| 323 |
* |
| 324 |
* @since 6.16 |
| 325 |
* |
| 326 |
* @return void |
| 327 |
*/ |
| 328 |
private static function subscribe_to_active_campaign() { |
| 329 |
$user = wp_get_current_user(); |
| 330 |
if ( empty( $user->user_email ) ) { |
| 331 |
return; |
| 332 |
} |
| 333 |
|
| 334 |
if ( ! self::should_send_email_to_active_campaign( $user->user_email ) ) { |
| 335 |
return; |
| 336 |
} |
| 337 |
|
| 338 |
$user_id = $user->ID; |
| 339 |
$first_name = get_user_meta( $user_id, 'first_name', true ); |
| 340 |
$last_name = get_user_meta( $user_id, 'last_name', true ); |
| 341 |
|
| 342 |
wp_remote_post( |
| 343 |
'https://sandbox.formidableforms.com/api/wp-admin/admin-ajax.php?action=frm_forms_preview&form=subscribe-onboarding', |
| 344 |
array( |
| 345 |
'body' => http_build_query( |
| 346 |
array( |
| 347 |
'form_key' => 'subscribe-onboarding', |
| 348 |
'frm_action' => 'create', |
| 349 |
'form_id' => 5, |
| 350 |
'item_key' => '', |
| 351 |
'item_meta[0]' => '', |
| 352 |
'item_meta[15]' => $user->user_email, |
| 353 |
'item_meta[17]' => 'Source - FF Lite Plugin Onboarding', |
| 354 |
'item_meta[18]' => is_string( $first_name ) ? $first_name : '', |
| 355 |
'item_meta[19]' => is_string( $last_name ) ? $last_name : '', |
| 356 |
) |
| 357 |
), |
| 358 |
) |
| 359 |
); |
| 360 |
} |
| 361 |
|
| 362 |
/** |
| 363 |
* Try to skip any fake emails. |
| 364 |
* |
| 365 |
* @since 6.16 |
| 366 |
* |
| 367 |
* @param string $email |
| 368 |
* @return bool |
| 369 |
*/ |
| 370 |
private static function should_send_email_to_active_campaign( $email ) { |
| 371 |
$substrings = array( |
| 372 |
'@wpengine.local', |
| 373 |
'@example.com', |
| 374 |
'@localhost', |
| 375 |
'@local.dev', |
| 376 |
'@local.test', |
| 377 |
'test@gmail.com', |
| 378 |
'admin@gmail.com', |
| 379 |
|
| 380 |
); |
| 381 |
foreach ( $substrings as $substring ) { |
| 382 |
if ( false !== strpos( $email, $substring ) ) { |
| 383 |
return false; |
| 384 |
} |
| 385 |
} |
| 386 |
return true; |
| 387 |
} |
| 388 |
|
| 389 |
/** |
| 390 |
* Handle AJAX request to set up usage data for the Onboarding Wizard. |
| 391 |
* |
| 392 |
* @since 6.9 |
| 393 |
* |
| 394 |
* @return void |
| 395 |
*/ |
| 396 |
public static function setup_usage_data() { |
| 397 |
// Check permission and nonce. |
| 398 |
FrmAppHelper::permission_check( self::REQUIRED_CAPABILITY ); |
| 399 |
check_ajax_referer( 'frm_ajax', 'nonce' ); |
| 400 |
|
| 401 |
// Retrieve the current usage data. |
| 402 |
$usage_data = self::get_usage_data(); |
| 403 |
|
| 404 |
$fields_to_update = array( |
| 405 |
'allows_tracking' => 'rest_sanitize_boolean', |
| 406 |
'installed_addons' => 'sanitize_text_field', |
| 407 |
'processed_steps' => 'sanitize_text_field', |
| 408 |
'completed_steps' => 'rest_sanitize_boolean', |
| 409 |
); |
| 410 |
|
| 411 |
foreach ( $fields_to_update as $field => $sanitize_callback ) { |
| 412 |
if ( isset( $_POST[ $field ] ) ) { |
| 413 |
$usage_data[ $field ] = FrmAppHelper::get_post_param( $field, '', $sanitize_callback ); |
| 414 |
} |
| 415 |
} |
| 416 |
|
| 417 |
update_option( self::USAGE_DATA_OPTION, $usage_data ); |
| 418 |
wp_send_json_success(); |
| 419 |
} |
| 420 |
|
| 421 |
/** |
| 422 |
* Enqueues the Onboarding Wizard page scripts and styles. |
| 423 |
* |
| 424 |
* @since 6.9 |
| 425 |
* |
| 426 |
* @return void |
| 427 |
*/ |
| 428 |
public static function enqueue_assets() { |
| 429 |
$plugin_url = FrmAppHelper::plugin_url(); |
| 430 |
$version = FrmAppHelper::plugin_version(); |
| 431 |
$js_dependencies = array( |
| 432 |
'wp-i18n', |
| 433 |
// This prevents a console error "wp.hooks is undefined" in WP versions older than 5.7. |
| 434 |
'wp-hooks', |
| 435 |
'formidable_dom', |
| 436 |
); |
| 437 |
|
| 438 |
// Enqueue styles that needed. |
| 439 |
wp_enqueue_style( 'formidable-admin' ); |
| 440 |
wp_enqueue_style( 'formidable-grids' ); |
| 441 |
|
| 442 |
// Register and enqueue Onboarding Wizard style. |
| 443 |
wp_register_style( self::SCRIPT_HANDLE, $plugin_url . '/css/admin/onboarding-wizard.css', array(), $version ); |
| 444 |
wp_enqueue_style( self::SCRIPT_HANDLE ); |
| 445 |
|
| 446 |
// Register and enqueue Onboarding Wizard script. |
| 447 |
wp_register_script( self::SCRIPT_HANDLE, $plugin_url . '/js/onboarding-wizard.js', $js_dependencies, $version, true ); |
| 448 |
wp_localize_script( self::SCRIPT_HANDLE, 'frmOnboardingWizardVars', self::get_js_variables() ); |
| 449 |
wp_enqueue_script( self::SCRIPT_HANDLE ); |
| 450 |
|
| 451 |
/** |
| 452 |
* Fires after the Onboarding Wizard enqueue assets. |
| 453 |
* |
| 454 |
* @since 6.9 |
| 455 |
*/ |
| 456 |
do_action( 'frm_onboarding_wizard_enqueue_assets' ); |
| 457 |
|
| 458 |
FrmAppHelper::dequeue_extra_global_scripts(); |
| 459 |
} |
| 460 |
|
| 461 |
/** |
| 462 |
* Get the Onboarding Wizard JS variables as an array. |
| 463 |
* |
| 464 |
* @since 6.9 |
| 465 |
* |
| 466 |
* @return array |
| 467 |
*/ |
| 468 |
private static function get_js_variables() { |
| 469 |
return array( |
| 470 |
'INITIAL_STEP' => self::INITIAL_STEP, |
| 471 |
); |
| 472 |
} |
| 473 |
|
| 474 |
/** |
| 475 |
* Remove the Onboarding Wizard submenu page from the formidable parent menu |
| 476 |
* since it is not necessary to show that link there. |
| 477 |
* |
| 478 |
* @since 6.9 |
| 479 |
* |
| 480 |
* @return void |
| 481 |
*/ |
| 482 |
public static function remove_menu() { |
| 483 |
remove_submenu_page( 'formidable', self::PAGE_SLUG ); |
| 484 |
} |
| 485 |
|
| 486 |
/** |
| 487 |
* Adds custom classes to the existing string of admin body classes. |
| 488 |
* |
| 489 |
* The function appends a custom class to the existing admin body classes, enabling full-screen mode for the admin interface. |
| 490 |
* |
| 491 |
* @since 6.9 |
| 492 |
* |
| 493 |
* @param string $classes Existing body classes. |
| 494 |
* @return string Updated list of body classes, including the newly added classes. |
| 495 |
*/ |
| 496 |
public static function add_admin_body_classes( $classes ) { |
| 497 |
return $classes . ' frm-admin-full-screen'; |
| 498 |
} |
| 499 |
|
| 500 |
/** |
| 501 |
* Checks if the Onboarding Wizard was skipped during the plugin's installation. |
| 502 |
* |
| 503 |
* @since 6.9 |
| 504 |
* @return bool True if the Onboarding Wizard was skipped, false otherwise. |
| 505 |
*/ |
| 506 |
public static function has_onboarding_been_skipped() { |
| 507 |
return get_option( self::ONBOARDING_SKIPPED_OPTION, false ); |
| 508 |
} |
| 509 |
|
| 510 |
/** |
| 511 |
* Marks the Onboarding Wizard as skipped to prevent automatic redirects to the wizard. |
| 512 |
* |
| 513 |
* @since 6.9 |
| 514 |
* @return void |
| 515 |
*/ |
| 516 |
public static function mark_onboarding_as_skipped() { |
| 517 |
update_option( self::ONBOARDING_SKIPPED_OPTION, true, 'no' ); |
| 518 |
} |
| 519 |
|
| 520 |
/** |
| 521 |
* Adds an Onboarding Wizard welcome message to the floating notifications. |
| 522 |
* |
| 523 |
* @since 6.9 |
| 524 |
* |
| 525 |
* @param array $inbox_messages The array of existing inbox messages. |
| 526 |
* @return array Configuration for the onboarding wizard slide-in notification. |
| 527 |
*/ |
| 528 |
public static function add_wizard_to_floating_links( $inbox_messages ) { |
| 529 |
$message = __( 'Welcome to Formidable Forms! Click here to run the Onboarding Wizard and it will guide you through the basic settings and get you started in 2 minutes.', 'formidable' ); |
| 530 |
|
| 531 |
return array( |
| 532 |
'onboarding_wizard' => array( |
| 533 |
'subject' => esc_html__( 'Begin With Ease!', 'formidable' ), |
| 534 |
'message' => esc_html( $message ), |
| 535 |
'slidein' => esc_html( $message ), |
| 536 |
'cta' => '<a href="' . esc_url( self::$page_url ) . '" class="button-primary frm-button-primary" target="_blank" rel="noopener noreferrer">' . esc_html__( 'Begin Setup', 'formidable' ) . '</a>', |
| 537 |
'created' => time(), |
| 538 |
'key' => 'onboarding_wizard', |
| 539 |
), |
| 540 |
); |
| 541 |
} |
| 542 |
|
| 543 |
/** |
| 544 |
* Check if the current page is the Onboarding Wizard page. |
| 545 |
* |
| 546 |
* @since 6.9 |
| 547 |
* |
| 548 |
* @return bool True if the current page is the Onboarding Wizard page, false otherwise. |
| 549 |
*/ |
| 550 |
public static function is_onboarding_wizard_page() { |
| 551 |
return FrmAppHelper::is_admin_page( self::PAGE_SLUG ); |
| 552 |
} |
| 553 |
|
| 554 |
/** |
| 555 |
* Checks if the plugin has already performed a redirect to avoid repeated redirections. |
| 556 |
* |
| 557 |
* @return bool Returns true if already redirected, otherwise false. |
| 558 |
*/ |
| 559 |
private static function has_already_redirected() { |
| 560 |
if ( get_option( self::REDIRECT_STATUS_OPTION ) ) { |
| 561 |
return true; |
| 562 |
} |
| 563 |
|
| 564 |
update_option( self::REDIRECT_STATUS_OPTION, FrmAppHelper::plugin_version(), 'no' ); |
| 565 |
return false; |
| 566 |
} |
| 567 |
|
| 568 |
/** |
| 569 |
* Get the path to the Onboarding Wizard views. |
| 570 |
* |
| 571 |
* @since 6.9 |
| 572 |
* |
| 573 |
* @return string Path to views. |
| 574 |
*/ |
| 575 |
public static function get_page_url() { |
| 576 |
return self::$page_url; |
| 577 |
} |
| 578 |
|
| 579 |
/** |
| 580 |
* Set the URL to access the Onboarding Wizard's page. |
| 581 |
* |
| 582 |
* @return void |
| 583 |
*/ |
| 584 |
private static function set_page_url() { |
| 585 |
self::$page_url = admin_url( 'admin.php?page=' . self::PAGE_SLUG ); |
| 586 |
} |
| 587 |
|
| 588 |
/** |
| 589 |
* Get the list of add-ons available for installation. |
| 590 |
* |
| 591 |
* @since 6.9 |
| 592 |
* |
| 593 |
* @return array A list of add-ons. |
| 594 |
*/ |
| 595 |
public static function get_available_addons() { |
| 596 |
return self::$available_addons; |
| 597 |
} |
| 598 |
|
| 599 |
/** |
| 600 |
* Set the list of add-ons available for installation. |
| 601 |
* |
| 602 |
* @since 6.9 |
| 603 |
* |
| 604 |
* @return void |
| 605 |
*/ |
| 606 |
private static function set_available_addons() { |
| 607 |
$pro_is_installed = FrmAppHelper::pro_is_installed(); |
| 608 |
$plugins = get_plugins(); |
| 609 |
|
| 610 |
// Base add-ons always included. |
| 611 |
self::$available_addons['spam-protection'] = array( |
| 612 |
'title' => esc_html__( 'Spam Protection', 'formidable' ), |
| 613 |
'is-checked' => true, |
| 614 |
'is-disabled' => true, |
| 615 |
'help-text' => esc_html__( 'Get anti-spam options like reCAPTCHA, hCaptcha, Akismet, Turnstile and the blocklist.', 'formidable' ), |
| 616 |
); |
| 617 |
self::$available_addons['stripe-payments'] = array( |
| 618 |
'title' => esc_html__( 'Stripe Payments', 'formidable' ), |
| 619 |
'is-checked' => true, |
| 620 |
'is-disabled' => true, |
| 621 |
'help-text' => esc_html__( 'Collect donations and payments with your forms. Offer physical products, digital goods, services, and more.', 'formidable' ), |
| 622 |
); |
| 623 |
|
| 624 |
// Add-ons included when Pro is not installed. |
| 625 |
if ( ! $pro_is_installed ) { |
| 626 |
self::$available_addons['visual-styler'] = array( |
| 627 |
'title' => esc_html__( 'Visual Styler', 'formidable' ), |
| 628 |
'is-checked' => true, |
| 629 |
'is-disabled' => true, |
| 630 |
'help-text' => esc_html__( 'Customize form appearance with an intuitive styling interface.', 'formidable' ), |
| 631 |
); |
| 632 |
self::$available_addons['save-entries'] = array( |
| 633 |
'title' => esc_html__( 'Save Entries', 'formidable' ), |
| 634 |
'is-checked' => true, |
| 635 |
'is-disabled' => true, |
| 636 |
'help-text' => esc_html__( 'Save form submissions to your database for future reference and analysis.', 'formidable' ), |
| 637 |
); |
| 638 |
} |
| 639 |
|
| 640 |
// SMTP add-on if wp_mail_smtp is not installed. |
| 641 |
if ( ! function_exists( 'wp_mail_smtp' ) ) { |
| 642 |
$wp_mail_smtp_plugin = 'wp-mail-smtp/wp_mail_smtp.php'; |
| 643 |
$is_installed_wp_mail_smtp = array_key_exists( $wp_mail_smtp_plugin, $plugins ); |
| 644 |
|
| 645 |
self::$available_addons['wp-mail-smtp'] = array( |
| 646 |
'title' => esc_html__( 'SMTP', 'formidable' ), |
| 647 |
'rel' => $is_installed_wp_mail_smtp ? $wp_mail_smtp_plugin : 'wp-mail-smtp', |
| 648 |
'is-checked' => false, |
| 649 |
'is-vendor' => true, |
| 650 |
'is-installed' => $is_installed_wp_mail_smtp, |
| 651 |
'help-text' => esc_html__( 'Improve email deliverability by routing WordPress emails through SMTP.', 'formidable' ), |
| 652 |
); |
| 653 |
} |
| 654 |
|
| 655 |
// Add-ons available when Pro is installed. |
| 656 |
if ( $pro_is_installed ) { |
| 657 |
$available_pro_addons = array( |
| 658 |
'formidable-views' => array( |
| 659 |
'addon_key' => 'views', |
| 660 |
'title' => __( 'Views', 'formidable' ), |
| 661 |
'plugin_file' => 'formidable-views/formidable-views.php', |
| 662 |
), |
| 663 |
'formidable-mailchimp' => array( |
| 664 |
'addon_key' => 'mailchimp', |
| 665 |
'title' => __( 'Mailchimp', 'formidable' ), |
| 666 |
'plugin_file' => 'formidable-mailchimp/formidable-mailchimp.php', |
| 667 |
), |
| 668 |
'formidable-registration' => array( |
| 669 |
'addon_key' => 'registration', |
| 670 |
'title' => __( 'User Registration', 'formidable' ), |
| 671 |
'plugin_file' => 'formidable-registration/formidable-registration.php', |
| 672 |
), |
| 673 |
'formidable-api' => array( |
| 674 |
'addon_key' => 'api', |
| 675 |
'title' => __( 'Form Rest API', 'formidable' ), |
| 676 |
'plugin_file' => 'formidable-api/formidable-api.php', |
| 677 |
), |
| 678 |
'formidable-signature' => array( |
| 679 |
'addon_key' => 'signature', |
| 680 |
'title' => __( 'Signature Forms', 'formidable' ), |
| 681 |
'plugin_file' => 'formidable-signature/signature.php', |
| 682 |
), |
| 683 |
); |
| 684 |
|
| 685 |
// Include ACF Forms add-on if ACF is installed. |
| 686 |
if ( class_exists( 'ACF' ) ) { |
| 687 |
$available_pro_addons['formidable-acf'] = array( |
| 688 |
'addon_key' => 'acf', |
| 689 |
'title' => __( 'ACF Forms', 'formidable' ), |
| 690 |
'plugin_file' => 'formidable-acf/formidable-acf.php', |
| 691 |
); |
| 692 |
} |
| 693 |
|
| 694 |
foreach ( $available_pro_addons as $key => $data ) { |
| 695 |
$addon = FrmAddonsController::get_addon( $data['addon_key'] ); |
| 696 |
$plugin_file = $data['plugin_file']; |
| 697 |
|
| 698 |
if ( ! is_plugin_active( $plugin_file ) && isset( $addon['url'] ) ) { |
| 699 |
$is_installed = array_key_exists( $plugin_file, $plugins ); |
| 700 |
|
| 701 |
self::$available_addons[ $key ] = array( |
| 702 |
'title' => $data['title'], |
| 703 |
'rel' => $is_installed ? $plugin_file : $addon['url'], |
| 704 |
'is-checked' => false, |
| 705 |
'is-installed' => $is_installed, |
| 706 |
'help-text' => $addon['excerpt'], |
| 707 |
); |
| 708 |
} |
| 709 |
} |
| 710 |
}//end if |
| 711 |
|
| 712 |
// Gravity Forms Migrator add-on. |
| 713 |
$gravity_forms_plugin = 'formidable-gravity-forms-importer/formidable-gravity-forms-importer.php'; |
| 714 |
if ( class_exists( 'GFForms' ) && ! is_plugin_active( $gravity_forms_plugin ) ) { |
| 715 |
$is_installed_gravity_forms = array_key_exists( $gravity_forms_plugin, $plugins ); |
| 716 |
|
| 717 |
self::$available_addons['formidable-gravity-forms-importer'] = array( |
| 718 |
'title' => esc_html__( 'Gravity Forms Migrator', 'formidable' ), |
| 719 |
'rel' => $is_installed_gravity_forms ? $gravity_forms_plugin : 'formidable-gravity-forms-importer', |
| 720 |
'is-checked' => false, |
| 721 |
'is-vendor' => true, |
| 722 |
'is-installed' => $is_installed_gravity_forms, |
| 723 |
'help-text' => esc_html__( 'Easily migrate your forms from Gravity Forms to Formidable.', 'formidable' ), |
| 724 |
); |
| 725 |
} |
| 726 |
} |
| 727 |
|
| 728 |
/** |
| 729 |
* Get the path to the Onboarding Wizard views. |
| 730 |
* |
| 731 |
* @since 6.9 |
| 732 |
* |
| 733 |
* @return string Path to views. |
| 734 |
*/ |
| 735 |
public static function get_view_path() { |
| 736 |
return self::$view_path; |
| 737 |
} |
| 738 |
|
| 739 |
/** |
| 740 |
* Get the upgrade link. |
| 741 |
* |
| 742 |
* @since 6.9 |
| 743 |
* |
| 744 |
* @return string URL for upgrading accounts. |
| 745 |
*/ |
| 746 |
public static function get_upgrade_link() { |
| 747 |
return self::$upgrade_link; |
| 748 |
} |
| 749 |
|
| 750 |
/** |
| 751 |
* Retrieves the current Onboarding Wizard usage data, returning an empty array if none exists. |
| 752 |
* |
| 753 |
* @since 6.9 |
| 754 |
* |
| 755 |
* @return array Current usage data. |
| 756 |
*/ |
| 757 |
public static function get_usage_data() { |
| 758 |
return get_option( self::USAGE_DATA_OPTION, array() ); |
| 759 |
} |
| 760 |
|
| 761 |
/** |
| 762 |
* Validates if the Onboarding Wizard page is being displayed. |
| 763 |
* |
| 764 |
* @since 6.9 |
| 765 |
* @deprecated 6.16 |
| 766 |
* |
| 767 |
* @return bool True if the Onboarding Wizard page is displayed, false otherwise. |
| 768 |
*/ |
| 769 |
public static function is_onboarding_wizard_displayed() { |
| 770 |
_deprecated_function( __METHOD__, '6.16' ); |
| 771 |
return get_transient( self::TRANSIENT_NAME ) === self::TRANSIENT_VALUE; |
| 772 |
} |
| 773 |
} |
| 774 |
|