Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 45 additions & 13 deletions classes/controllers/FrmOnboardingWizardController.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,20 @@ class FrmOnboardingWizardController {

/**
* Transient value associated with the redirection to the Onboarding Wizard page.
* Used when activating a single plugin.
*
* @var string
*/
const TRANSIENT_VALUE = 'formidable-welcome';

/**
* Transient value associated with the redirection to the Onboarding Wizard page.
* Used when activating multiple plugins at once.
*
* @var string
*/
const TRANSIENT_MULTI_VALUE = 'formidable-welcome-multi';

/**
* Option name for storing the redirect status for the Onboarding Wizard page.
*
Expand Down Expand Up @@ -126,6 +135,8 @@ public static function load_admin_hooks() {

/**
* Performs a safe redirect to the welcome screen when the plugin is activated.
* On single activation, we will redirect immediately.
* When activating multiple plugins, the redirect is delayed until a Formidable page is loaded.
*
* @return void
*/
Expand All @@ -143,8 +154,27 @@ public static function do_admin_redirects() {
return;
}

// Check if we should consider redirection.
if ( ! FrmAppHelper::is_formidable_admin() || ! self::is_onboarding_wizard_displayed() || self::has_onboarding_been_skipped() || FrmAppHelper::pro_is_connected() ) {
if ( self::has_onboarding_been_skipped() || FrmAppHelper::pro_is_connected() ) {
return;
}

$transient_value = get_transient( self::TRANSIENT_NAME );
if ( ! in_array( $transient_value, array( self::TRANSIENT_VALUE, self::TRANSIENT_MULTI_VALUE ), true ) ) {
self::mark_onboarding_as_skipped();
return;
}

if ( isset( $_GET['activate-multi'] ) ) {
/**
* $_GET['activate-multi'] is set after activating multiple plugins.
* In this case, change the transient value so we know for future checks.
*/
set_transient( self::TRANSIENT_NAME, self::TRANSIENT_MULTI_VALUE, 60 );
return;
}
Comment thread
Crabcyborg marked this conversation as resolved.

if ( self::TRANSIENT_MULTI_VALUE === $transient_value && ! FrmAppHelper::is_formidable_admin() ) {
// For multi-activations we want to only redirect when a user loads a Formidable page.
return;
}

Expand Down Expand Up @@ -462,17 +492,6 @@ public static function is_onboarding_wizard_page() {
return FrmAppHelper::is_admin_page( self::PAGE_SLUG );
}

/**
* Validates if the Onboarding Wizard page is being displayed.
*
* @since 6.9
*
* @return bool True if the Onboarding Wizard page is displayed, false otherwise.
*/
public static function is_onboarding_wizard_displayed() {
return get_transient( self::TRANSIENT_NAME ) === self::TRANSIENT_VALUE;
}

/**
* Checks if the plugin has already performed a redirect to avoid repeated redirections.
*
Expand Down Expand Up @@ -663,4 +682,17 @@ public static function get_upgrade_link() {
public static function get_usage_data() {
return get_option( self::USAGE_DATA_OPTION, array() );
}

/**
* Validates if the Onboarding Wizard page is being displayed.
*
* @since 6.9
* @deprecated x.x
*
* @return bool True if the Onboarding Wizard page is displayed, false otherwise.
*/
public static function is_onboarding_wizard_displayed() {
_deprecated_function( __METHOD__, 'x.x' );
return get_transient( self::TRANSIENT_NAME ) === self::TRANSIENT_VALUE;
}
Comment thread
Crabcyborg marked this conversation as resolved.
}