From 960c5c000f8f83ef2cec923a3d5a8e141f071f53 Mon Sep 17 00:00:00 2001 From: arunshenoy99 Date: Mon, 29 May 2023 14:01:08 +0530 Subject: [PATCH] add enablement query param --- includes/Data/Options.php | 2 ++ includes/ModuleController.php | 24 +++++++++++++++++------- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/includes/Data/Options.php b/includes/Data/Options.php index 085debc80..42e1d971d 100644 --- a/includes/Data/Options.php +++ b/includes/Data/Options.php @@ -20,6 +20,8 @@ final class Options { protected static $options = array( 'redirect' => 'redirect', 'redirect_param' => 'redirect_param', + 'activate' => 'activate', + 'activate_param' => 'activate_param', 'coming_soon' => 'nfd_coming_soon', 'brand' => 'mm_brand', 'close_comments_for_old_posts' => 'close_comments_for_old_posts', diff --git a/includes/ModuleController.php b/includes/ModuleController.php index 93a830e95..b69bc6eca 100644 --- a/includes/ModuleController.php +++ b/includes/ModuleController.php @@ -28,14 +28,11 @@ public static function init() { * Enable/Disable Onboarding based on certain checks. */ public static function module_switcher() { - $module_name = 'onboarding'; - // Set brand context for the module. Brands::set_current_brand( container() ); - $customer_data = Data::customer_data(); - $enable_onboarding = self::verify_onboarding_criteria( $customer_data ); + $enable_onboarding = self::verify_onboarding_criteria(); // Check if he is a Non-Ecommerce Customer and Disable Redirect and Module if ( ! $enable_onboarding ) { @@ -61,12 +58,25 @@ public static function module_switcher() { /** * Verify all the necessary criteria to enable Onboarding for the site. * - * @param array $customer_data The brand customer data. * @return boolean */ - public static function verify_onboarding_criteria( $customer_data ) { - $brand_enabled_flows = Flows::get_flows(); + public static function verify_onboarding_criteria() { + // Check if nfd_module_onboarding_activate query param was passed previously. + $activate_transient_name = Options::get_option_name( 'activate_param' ); + if ( '1' === get_transient( $activate_transient_name ) ) { + return true; + } + + // If the transient does not exist, check if nfd_module_onboarding_activate query param has been passed. + $activate_param_name = Options::get_option_name( 'activate' ); + if ( isset( $_GET[ $activate_param_name ] ) && Permissions::is_authorized_admin() ) { + // Set a 30 day transient that reflects this parameter being passed. + set_transient( $activate_transient_name, '1', 2592000 ); + return true; + } + $customer_data = Data::customer_data(); + $brand_enabled_flows = Flows::get_flows(); foreach ( $brand_enabled_flows as $flow => $enabled ) { if ( ! $enabled ) { continue;