From 7000edc8f3a92c6ce97ef0c6d0890571799391a6 Mon Sep 17 00:00:00 2001 From: arunshenoy99 Date: Fri, 12 Apr 2024 11:11:49 +0530 Subject: [PATCH 1/2] Use Fresh Installation check before activating Wonder Theme --- .../components/Button/NavCardButton/index.js | 1 + .../SiteBuildHeader/step-navigation.js | 1 + .../StateHandlers/Design/contents.js | 11 +++ .../components/StateHandlers/Design/index.js | 79 +++++++++++-------- src/OnboardingSPA/store/actions.js | 1 - src/OnboardingSPA/store/selectors.js | 4 + 6 files changed, 63 insertions(+), 34 deletions(-) diff --git a/src/OnboardingSPA/components/Button/NavCardButton/index.js b/src/OnboardingSPA/components/Button/NavCardButton/index.js index 406ac39d7..25708bd1e 100644 --- a/src/OnboardingSPA/components/Button/NavCardButton/index.js +++ b/src/OnboardingSPA/components/Button/NavCardButton/index.js @@ -36,6 +36,7 @@ const NavCardButton = ( { text, disabled, className, icon } ) => { async function saveDataAndExit() { if ( currentData ) { currentData.isComplete = new Date().getTime(); + currentData.data.siteOverrideConsent = false; setFlow( currentData ); } diff --git a/src/OnboardingSPA/components/Header/components/SiteBuildHeader/step-navigation.js b/src/OnboardingSPA/components/Header/components/SiteBuildHeader/step-navigation.js index 940c5543e..480b13928 100644 --- a/src/OnboardingSPA/components/Header/components/SiteBuildHeader/step-navigation.js +++ b/src/OnboardingSPA/components/Header/components/SiteBuildHeader/step-navigation.js @@ -78,6 +78,7 @@ const Next = ( { path, showErrorDialog } ) => { async function saveDataAndExit( currentData ) { if ( currentData ) { currentData.isComplete = new Date().getTime(); + currentData.data.siteOverrideConsent = false; setFlow( currentData ); } diff --git a/src/OnboardingSPA/components/StateHandlers/Design/contents.js b/src/OnboardingSPA/components/StateHandlers/Design/contents.js index 83795badf..30f13621b 100644 --- a/src/OnboardingSPA/components/StateHandlers/Design/contents.js +++ b/src/OnboardingSPA/components/StateHandlers/Design/contents.js @@ -28,6 +28,17 @@ const getContents = ( brandName ) => { 'wp-module-onboarding' ), }, + exitModal: { + title: __( + 'It looks like you may have an existing website', + 'wp-module-onboarding' + ), + description: __( + 'Going through this setup will change your active theme, WordPress settings, add content – would you like to continue?', + 'wp-module-onboarding' + ), + buttonText: __( 'Exit to WordPress', 'wp-module-onboarding' ), + }, }; }; diff --git a/src/OnboardingSPA/components/StateHandlers/Design/index.js b/src/OnboardingSPA/components/StateHandlers/Design/index.js index 58edd5683..e19a85e8b 100644 --- a/src/OnboardingSPA/components/StateHandlers/Design/index.js +++ b/src/OnboardingSPA/components/StateHandlers/Design/index.js @@ -1,7 +1,6 @@ import { useSelect, useDispatch } from '@wordpress/data'; import { Fragment, useEffect } from '@wordpress/element'; import { useViewportMatch } from '@wordpress/compose'; -import { __ } from '@wordpress/i18n'; import { StepLoader } from '../../Loaders'; import { store as nfdOnboardingStore } from '../../../store'; @@ -21,6 +20,7 @@ import { import { StepErrorState } from '../../ErrorState'; import getContents from './contents'; import ExitToWordPress from '../../ExitToWordPress'; +import { setFlow } from '../../../utils/api/flow'; const DesignStateHandler = ( { children, @@ -30,12 +30,18 @@ const DesignStateHandler = ( { } ) => { const isLargeViewport = useViewportMatch( 'medium' ); - const { storedThemeStatus, brandName } = useSelect( ( select ) => { - return { - storedThemeStatus: select( nfdOnboardingStore ).getThemeStatus(), - brandName: select( nfdOnboardingStore ).getNewfoldBrandName(), - }; - }, [] ); + const { storedThemeStatus, brandName, isFreshInstallation, currentData } = + useSelect( ( select ) => { + return { + storedThemeStatus: + select( nfdOnboardingStore ).getThemeStatus(), + brandName: select( nfdOnboardingStore ).getNewfoldBrandName(), + isFreshInstallation: + select( nfdOnboardingStore ).getIsFreshInstallation(), + currentData: + select( nfdOnboardingStore ).getCurrentOnboardingData(), + }; + }, [] ); const contents = getContents( brandName ); @@ -44,6 +50,7 @@ const DesignStateHandler = ( { setIsDrawerOpened, setIsDrawerSuppressed, setIsHeaderNavigationEnabled, + setCurrentOnboardingData, } = useDispatch( nfdOnboardingStore ); const checkThemeStatus = async () => { @@ -107,11 +114,7 @@ const DesignStateHandler = ( { } break; case THEME_STATUS_NOT_ACTIVE: - if ( false === render ) { - // When render is false add this condition because - // handleRender() func does not run here and theme is not activated. - expediteInstall(); - } + installThemeManually(); break; default: updateThemeStatus( themeStatus ); @@ -121,10 +124,18 @@ const DesignStateHandler = ( { useEffect( () => { handleNavigationState(); + if ( + true === render && + ! isFreshInstallation && + currentData.data.siteOverrideConsent === false + ) { + return; + } + if ( storedThemeStatus === THEME_STATUS_INIT ) { handleThemeStatus( storedThemeStatus ); } - }, [ storedThemeStatus ] ); + }, [ storedThemeStatus, isFreshInstallation, currentData ] ); const installThemeManually = async () => { updateThemeStatus( THEME_STATUS_INSTALLING ); @@ -133,6 +144,7 @@ const DesignStateHandler = ( { true, false ); + if ( themeInstallStatus.error ) { return updateThemeStatus( THEME_STATUS_FAILURE ); } @@ -142,28 +154,29 @@ const DesignStateHandler = ( { } }; + const handleModalClose = () => { + currentData.data.siteOverrideConsent = true; + setCurrentOnboardingData( currentData ); + setFlow( currentData ); + }; + const handleRender = () => { + if ( + ! isFreshInstallation && + currentData.data.siteOverrideConsent === false + ) { + return ( + + ); + } switch ( storedThemeStatus ) { - case THEME_STATUS_NOT_ACTIVE: - return ( - - ); case THEME_STATUS_FAILURE: return ( Date: Fri, 12 Apr 2024 11:25:13 +0530 Subject: [PATCH 2/2] Remove install checker, use onboarding-data function --- composer.json | 1 - composer.lock | 67 ++++++++------------------------------ includes/LoginRedirect.php | 8 ++--- 3 files changed, 16 insertions(+), 60 deletions(-) diff --git a/composer.json b/composer.json index b03b5aa42..3d8d59323 100644 --- a/composer.json +++ b/composer.json @@ -36,7 +36,6 @@ "wp-cli/wp-config-transformer": "^1.3", "newfold-labs/wp-module-onboarding-data": "^1.1", "newfold-labs/wp-module-patterns": "^0.1", - "newfold-labs/wp-module-install-checker": "^1.0", "newfold-labs/wp-module-facebook": "^1.0", "wp-forge/helpers": "^2.0" }, diff --git a/composer.lock b/composer.lock index 01a433d4a..40933dc28 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "20b284eff5efb73cc65dc0588be55399", + "content-hash": "1af02b460b4e6e823da2c59d4e41c9e7", "packages": [ { "name": "doctrine/inflector", @@ -345,16 +345,16 @@ }, { "name": "newfold-labs/wp-module-data", - "version": "2.4.21", + "version": "2.4.23", "source": { "type": "git", "url": "https://github.com/newfold-labs/wp-module-data.git", - "reference": "efee98ff57154cf862ea8c2791ed514a0765fc88" + "reference": "386157fa9d6ac00dac28a79c7b6d26b40434d047" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/newfold-labs/wp-module-data/zipball/efee98ff57154cf862ea8c2791ed514a0765fc88", - "reference": "efee98ff57154cf862ea8c2791ed514a0765fc88", + "url": "https://api.github.com/repos/newfold-labs/wp-module-data/zipball/386157fa9d6ac00dac28a79c7b6d26b40434d047", + "reference": "386157fa9d6ac00dac28a79c7b6d26b40434d047", "shasum": "" }, "require": { @@ -395,10 +395,10 @@ ], "description": "Newfold Data Module", "support": { - "source": "https://github.com/newfold-labs/wp-module-data/tree/2.4.21", + "source": "https://github.com/newfold-labs/wp-module-data/tree/2.4.23", "issues": "https://github.com/newfold-labs/wp-module-data/issues" }, - "time": "2024-03-29T20:20:11+00:00" + "time": "2024-04-10T15:02:13+00:00" }, { "name": "newfold-labs/wp-module-facebook", @@ -442,45 +442,6 @@ }, "time": "2024-02-12T08:48:41+00:00" }, - { - "name": "newfold-labs/wp-module-install-checker", - "version": "1.0.3", - "source": { - "type": "git", - "url": "https://github.com/newfold-labs/wp-module-install-checker.git", - "reference": "9d43e916b8c4e752b45c868b41340b84bcb686a6" - }, - "dist": { - "type": "zip", - "url": "https://api.github.com/repos/newfold-labs/wp-module-install-checker/zipball/9d43e916b8c4e752b45c868b41340b84bcb686a6", - "reference": "9d43e916b8c4e752b45c868b41340b84bcb686a6", - "shasum": "" - }, - "type": "library", - "autoload": { - "files": [ - "bootstrap.php" - ], - "psr-4": { - "NewfoldLabs\\WP\\Module\\InstallChecker\\": "includes/" - } - }, - "license": [ - "GPL-2.0-or-later" - ], - "authors": [ - { - "name": "Micah Wood", - "homepage": "https://wpscholar.com" - } - ], - "description": "A module that handles checking a WordPress installation to see if it is a fresh install and to fetch the estimated installation date.", - "support": { - "source": "https://github.com/newfold-labs/wp-module-install-checker/tree/1.0.3", - "issues": "https://github.com/newfold-labs/wp-module-install-checker/issues" - }, - "time": "2024-01-31T18:12:34+00:00" - }, { "name": "newfold-labs/wp-module-installer", "version": "1.1.4", @@ -617,16 +578,16 @@ }, { "name": "newfold-labs/wp-module-patterns", - "version": "0.1.16", + "version": "0.1.17", "source": { "type": "git", "url": "https://github.com/newfold-labs/wp-module-patterns.git", - "reference": "0ab410ea66231f2694d4f9d0aafa2e2874000cf2" + "reference": "92fde7daaf5d86a2567b22c9d31db4060b346933" }, "dist": { "type": "zip", - "url": "https://api.github.com/repos/newfold-labs/wp-module-patterns/zipball/0ab410ea66231f2694d4f9d0aafa2e2874000cf2", - "reference": "0ab410ea66231f2694d4f9d0aafa2e2874000cf2", + "url": "https://api.github.com/repos/newfold-labs/wp-module-patterns/zipball/92fde7daaf5d86a2567b22c9d31db4060b346933", + "reference": "92fde7daaf5d86a2567b22c9d31db4060b346933", "shasum": "" }, "require-dev": { @@ -660,10 +621,10 @@ ], "description": "WordPress Cloud Patterns", "support": { - "source": "https://github.com/newfold-labs/wp-module-patterns/tree/0.1.16", + "source": "https://github.com/newfold-labs/wp-module-patterns/tree/0.1.17", "issues": "https://github.com/newfold-labs/wp-module-patterns/issues" }, - "time": "2024-04-08T19:51:29+00:00" + "time": "2024-04-10T19:48:10+00:00" }, { "name": "newfold-labs/wp-module-performance", @@ -3877,7 +3838,7 @@ }, { "name": "wp-phpunit/wp-phpunit", - "version": "6.5.0", + "version": "6.5.2", "source": { "type": "git", "url": "https://github.com/wp-phpunit/wp-phpunit.git", diff --git a/includes/LoginRedirect.php b/includes/LoginRedirect.php index a608a26c1..a9b2f994b 100644 --- a/includes/LoginRedirect.php +++ b/includes/LoginRedirect.php @@ -4,7 +4,6 @@ use NewfoldLabs\WP\Module\Onboarding\Data\Data; use NewfoldLabs\WP\Module\Onboarding\Data\Options; -use function NewfoldLabs\WP\ModuleLoader\container; use function WP_Forge\Helpers\dataGet; /** @@ -72,11 +71,8 @@ public static function filter_redirect( $original_redirect, $user ) { } // Don't redirect to onboarding if the site is not a fresh installation. - if ( container()->has( 'isFreshInstallation' ) ) { - $is_fresh_installation = container()->get( 'isFreshInstallation' ); - if ( false === $is_fresh_installation ) { - return $original_redirect; - } + if ( false === Data::is_fresh_installation() ) { + return $original_redirect; } // Don't redirect to onboarding if the 'coming_soon' mode is off. The user has launched their site.