From 78b277abde0e53c9ab9107309ca8bea76685e9a0 Mon Sep 17 00:00:00 2001 From: arunshenoy99 Date: Fri, 28 Apr 2023 10:29:24 +0530 Subject: [PATCH 01/20] add site classification controller --- includes/RestApi/RestApi.php | 1 + .../RestApi/SiteClassificationController.php | 51 +++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100644 includes/RestApi/SiteClassificationController.php diff --git a/includes/RestApi/RestApi.php b/includes/RestApi/RestApi.php index 2b1c620e7..c9f5eeae8 100644 --- a/includes/RestApi/RestApi.php +++ b/includes/RestApi/RestApi.php @@ -28,6 +28,7 @@ final class RestApi { 'NewfoldLabs\WP\\Module\\Onboarding\\RestApi\\Themes\\ThemeInstallerController', 'NewfoldLabs\WP\\Module\\Onboarding\\RestApi\\Themes\\ThemeFontsController', 'NewfoldLabs\WP\\Module\\Onboarding\\RestApi\\Themes\\ThemeColorsController', + 'NewfoldLabs\\WP\\Module\\Onboarding\\RestApi\\SiteClassificationController' ); /** diff --git a/includes/RestApi/SiteClassificationController.php b/includes/RestApi/SiteClassificationController.php new file mode 100644 index 000000000..60f8724b9 --- /dev/null +++ b/includes/RestApi/SiteClassificationController.php @@ -0,0 +1,51 @@ +namespace, + $this->rest_base, + array( + 'methods' => \WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_site_classification' ), + 'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), + ) + ); + } + + public function get_site_classification() { + if ( ! class_exists( 'NewfoldLabs\WP\Module\Data\SiteClassification' ) ) { + return array(); + } + $classification = new SiteClassification(); + return $classification->get(); + } +} From 7b46fe90c28296f3f51471dc81a6d95e24c9ac2d Mon Sep 17 00:00:00 2001 From: arunshenoy99 Date: Fri, 28 Apr 2023 10:49:50 +0530 Subject: [PATCH 02/20] fix lint --- includes/RestApi/RestApi.php | 2 +- includes/RestApi/SiteClassificationController.php | 15 ++++++++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/includes/RestApi/RestApi.php b/includes/RestApi/RestApi.php index c9f5eeae8..8c2fba99b 100644 --- a/includes/RestApi/RestApi.php +++ b/includes/RestApi/RestApi.php @@ -28,7 +28,7 @@ final class RestApi { 'NewfoldLabs\WP\\Module\\Onboarding\\RestApi\\Themes\\ThemeInstallerController', 'NewfoldLabs\WP\\Module\\Onboarding\\RestApi\\Themes\\ThemeFontsController', 'NewfoldLabs\WP\\Module\\Onboarding\\RestApi\\Themes\\ThemeColorsController', - 'NewfoldLabs\\WP\\Module\\Onboarding\\RestApi\\SiteClassificationController' + 'NewfoldLabs\\WP\\Module\\Onboarding\\RestApi\\SiteClassificationController', ); /** diff --git a/includes/RestApi/SiteClassificationController.php b/includes/RestApi/SiteClassificationController.php index 60f8724b9..77820fb49 100644 --- a/includes/RestApi/SiteClassificationController.php +++ b/includes/RestApi/SiteClassificationController.php @@ -41,11 +41,16 @@ public function register_routes() { ); } - public function get_site_classification() { - if ( ! class_exists( 'NewfoldLabs\WP\Module\Data\SiteClassification' ) ) { + /** + * Fetch the Site Classification data using the data module helper. + * + * @return array + */ + public function get_site_classification() { + if ( ! class_exists( 'NewfoldLabs\WP\Module\Data\SiteClassification' ) ) { return array(); } - $classification = new SiteClassification(); - return $classification->get(); - } + $classification = new SiteClassification(); + return $classification->get(); + } } From fb640a9210bb54bfaca924a094623fc11ce61fc2 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Fri, 28 Apr 2023 18:36:10 +0530 Subject: [PATCH 03/20] Initial Commit --- .../components/HeadingWithSubHeading/index.js | 27 +++--- src/OnboardingSPA/data/routes/default-flow.js | 2 +- .../Steps/DesignThemeStyles/Menu/index.js | 47 ++++++++++- .../DesignThemeStyles/Menu/stylesheet.scss | 10 +++ .../Steps/DesignThemeStyles/Preview/index.js | 84 ++++--------------- .../pages/Steps/DesignThemeStyles/utils.js | 69 +++++++++++++++ 6 files changed, 157 insertions(+), 82 deletions(-) create mode 100644 src/OnboardingSPA/pages/Steps/DesignThemeStyles/utils.js diff --git a/src/OnboardingSPA/components/HeadingWithSubHeading/index.js b/src/OnboardingSPA/components/HeadingWithSubHeading/index.js index 54e01bb5e..fb00afc72 100644 --- a/src/OnboardingSPA/components/HeadingWithSubHeading/index.js +++ b/src/OnboardingSPA/components/HeadingWithSubHeading/index.js @@ -3,20 +3,25 @@ import { __ } from '@wordpress/i18n'; /** * Interface Cards with standard design. * - * @returns + * @param {Object} root0 + * @param {string} root0.title + * @param {string} root0.subtitle + * @param {Object} root0.children */ -const HeadingWithSubHeading = ({ title, subtitle }) => { - +const HeadingWithSubHeading = ( { title, subtitle, children } ) => { return (
-

{__( - title, - "wp-module-onboarding" - )}

-

{__( - subtitle, - "wp-module-onboarding" - )}

+

+ { /* eslint-disable-next-line @wordpress/i18n-no-variables */ } + { __( title, 'wp-module-onboarding' ) } +

+ { subtitle && ( +

+ { /* eslint-disable-next-line @wordpress/i18n-no-variables */ } + { __( subtitle, 'wp-module-onboarding' ) } +

+ ) } + { children }
); }; diff --git a/src/OnboardingSPA/data/routes/default-flow.js b/src/OnboardingSPA/data/routes/default-flow.js index bfe85280a..490706510 100644 --- a/src/OnboardingSPA/data/routes/default-flow.js +++ b/src/OnboardingSPA/data/routes/default-flow.js @@ -391,7 +391,7 @@ export const steps = [ 'wp-module-onboarding' ), subheading: __( - "Use these styles or bring your own. You're always free to remix them.", + 'Start with a style preset or ', 'wp-module-onboarding' ), description: __( diff --git a/src/OnboardingSPA/pages/Steps/DesignThemeStyles/Menu/index.js b/src/OnboardingSPA/pages/Steps/DesignThemeStyles/Menu/index.js index 3b63da683..aeceed969 100644 --- a/src/OnboardingSPA/pages/Steps/DesignThemeStyles/Menu/index.js +++ b/src/OnboardingSPA/pages/Steps/DesignThemeStyles/Menu/index.js @@ -8,6 +8,7 @@ import HeadingWithSubHeading from '../../../../components/HeadingWithSubHeading' import { useGlobalStylesOutput } from '../../../../utils/global-styles/use-global-styles-output'; import { getPatterns } from '../../../../utils/api/patterns'; import { getGlobalStyles } from '../../../../utils/api/themes'; +import { conditionalSteps } from '../../../../data/routes/'; import { VIEW_NAV_DESIGN, THEME_STATUS_ACTIVE, @@ -19,6 +20,7 @@ import { LivePreviewSelectableCard, LivePreviewSkeleton, } from '../../../../components/LivePreview'; +import { addColorAndTypographyRoutes } from '../utils'; const StepDesignThemeStylesMenu = () => { const location = useLocation(); @@ -32,6 +34,9 @@ const StepDesignThemeStylesMenu = () => { nextStep, currentData, storedPreviewSettings, + routes, + allSteps, + designSteps, themeStatus, themeVariations, } = useSelect( ( select ) => { @@ -44,6 +49,9 @@ const StepDesignThemeStylesMenu = () => { select( nfdOnboardingStore ).getCurrentOnboardingData(), storedPreviewSettings: select( nfdOnboardingStore ).getPreviewSettings(), + routes: select( nfdOnboardingStore ).getRoutes(), + allSteps: select( nfdOnboardingStore ).getAllSteps(), + designSteps: select( nfdOnboardingStore ).getDesignSteps(), themeStatus: select( nfdOnboardingStore ).getThemeStatus(), themeVariations: select( nfdOnboardingStore ).getStepPreviewData(), }; @@ -55,6 +63,9 @@ const StepDesignThemeStylesMenu = () => { updatePreviewSettings, setCurrentOnboardingData, updateThemeStatus, + updateRoutes, + updateDesignSteps, + updateAllSteps, } = useDispatch( nfdOnboardingStore ); useEffect( () => { @@ -86,6 +97,7 @@ const StepDesignThemeStylesMenu = () => { const handleClick = ( idx ) => { const selectedGlobalStyle = globalStyles[ idx ]; updatePreviewSettings( + // eslint-disable-next-line react-hooks/rules-of-hooks useGlobalStylesOutput( selectedGlobalStyle, storedPreviewSettings ) ); setSelectedStyle( selectedGlobalStyle.title ); @@ -94,6 +106,26 @@ const StepDesignThemeStylesMenu = () => { navigate( nextStep.path ); }; + const skiptoCustomPage = () => { + // Add Custom Steps into the Flow + const updates = addColorAndTypographyRoutes( + routes, + allSteps, + designSteps + ); + updateRoutes( updates.routes ); + updateDesignSteps( updates.designSteps ); + updateAllSteps( updates.allSteps ); + + currentData.data.customDesign = true; + setCurrentOnboardingData( currentData ); + + // Find the first Custom Conditional Step and navigate there + navigate( + conditionalSteps[ Object.keys( conditionalSteps )[ 0 ] ].path + ); + }; + const buildPreviews = () => { return globalStyles?.map( ( globalStyle, idx ) => { return ( @@ -116,10 +148,17 @@ const StepDesignThemeStylesMenu = () => {
- + +

+ { currentStep?.subheading }{ ' ' } + +

+
{ @@ -74,73 +76,23 @@ const StepDesignThemeStylesPreview = () => { setPattern( patternsResponse?.body ); }; - const addColorAndTypographyRoutes = () => { - const updates = removeColorAndTypographyRoutes(); - const steps = [ - conditionalSteps.designColors, - conditionalSteps.designTypography, - ]; - return { - routes: orderBy( - updates.routes.concat( steps ), - [ 'priority' ], - [ 'asc' ] - ), - allSteps: orderBy( - updates.allSteps.concat( steps ), - [ 'priority' ], - [ 'asc' ] - ), - designSteps: orderBy( - updates.designSteps.concat( steps ), - [ 'priority' ], - [ 'asc' ] - ), - }; - }; - - const removeColorAndTypographyRoutes = () => { - return { - routes: filter( + const handleCheckbox = ( + customizeSelection, + updateOnboardingData = true + ) => { + let updates; + if ( customizeSelection ) { + updates = addColorAndTypographyRoutes( routes, - ( route ) => - ! route.path.includes( - conditionalSteps.designColors.path - ) && - ! route.path.includes( - conditionalSteps.designTypography.path - ) - ), - allSteps: filter( allSteps, - ( allStep ) => - ! allStep.path.includes( - conditionalSteps.designColors.path - ) && - ! allStep.path.includes( - conditionalSteps.designTypography.path - ) - ), - designSteps: filter( - designSteps, - ( designStep ) => - ! designStep.path.includes( - conditionalSteps.designColors.path - ) && - ! designStep.path.includes( - conditionalSteps.designTypography.path - ) - ), - }; - }; - - const handleCheckbox = ( customize, updateOnboardingData = true ) => { - let updates; - - if ( customize ) { - updates = addColorAndTypographyRoutes(); + designSteps + ); } else { - updates = removeColorAndTypographyRoutes(); + updates = removeColorAndTypographyRoutes( + routes, + allSteps, + designSteps + ); } updateRoutes( updates.routes ); diff --git a/src/OnboardingSPA/pages/Steps/DesignThemeStyles/utils.js b/src/OnboardingSPA/pages/Steps/DesignThemeStyles/utils.js new file mode 100644 index 000000000..0ae846c42 --- /dev/null +++ b/src/OnboardingSPA/pages/Steps/DesignThemeStyles/utils.js @@ -0,0 +1,69 @@ +// eslint-disable-next-line import/no-extraneous-dependencies +import { orderBy, filter } from 'lodash'; +import { conditionalSteps } from '../../../data/routes/'; + +export const addColorAndTypographyRoutes = ( + routes, + allSteps, + designSteps +) => { + const updates = removeColorAndTypographyRoutes( + routes, + allSteps, + designSteps + ); + const steps = [ + conditionalSteps.designColors, + conditionalSteps.designTypography, + ]; + return { + routes: orderBy( + updates.routes.concat( steps ), + [ 'priority' ], + [ 'asc' ] + ), + allSteps: orderBy( + updates.allSteps.concat( steps ), + [ 'priority' ], + [ 'asc' ] + ), + designSteps: orderBy( + updates.designSteps.concat( steps ), + [ 'priority' ], + [ 'asc' ] + ), + }; +}; + +export const removeColorAndTypographyRoutes = ( + routes, + allSteps, + designSteps +) => { + return { + routes: filter( + routes, + ( route ) => + ! route.path.includes( conditionalSteps.designColors.path ) && + ! route.path.includes( conditionalSteps.designTypography.path ) + ), + allSteps: filter( + allSteps, + ( allStep ) => + ! allStep.path.includes( conditionalSteps.designColors.path ) && + ! allStep.path.includes( + conditionalSteps.designTypography.path + ) + ), + designSteps: filter( + designSteps, + ( designStep ) => + ! designStep.path.includes( + conditionalSteps.designColors.path + ) && + ! designStep.path.includes( + conditionalSteps.designTypography.path + ) + ), + }; +}; From b88517f178688c90380dd2d75001a5e603ede528 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Fri, 28 Apr 2023 19:05:42 +0530 Subject: [PATCH 04/20] Fixed Lint --- src/OnboardingSPA/data/routes/default-flow.js | 35 ++++++++----------- 1 file changed, 15 insertions(+), 20 deletions(-) diff --git a/src/OnboardingSPA/data/routes/default-flow.js b/src/OnboardingSPA/data/routes/default-flow.js index 490706510..665ff48d0 100644 --- a/src/OnboardingSPA/data/routes/default-flow.js +++ b/src/OnboardingSPA/data/routes/default-flow.js @@ -1,5 +1,6 @@ import { __, sprintf } from '@wordpress/i18n'; import { lazy } from '@wordpress/element'; +// eslint-disable-next-line import/no-extraneous-dependencies import { filter, orderBy } from 'lodash'; import IndexPage from '../../pages/index'; import { translations } from '../../utils/locales/translations'; @@ -22,8 +23,6 @@ import { import { VIEW_DESIGN_COLORS, VIEW_DESIGN_HEADER_MENU, - VIEW_DESIGN_HOMEPAGE_MENU, - VIEW_DESIGN_THEME_STYLES_MENU, VIEW_DESIGN_THEME_STYLES_PREVIEW, VIEW_DESIGN_TYPOGRAPHY, VIEW_NAV_GET_STARTED, @@ -84,10 +83,6 @@ const StepBasicInfoLearnMoreSidebar = lazy( () => import( '../../pages/Steps/BasicInfo/Sidebar/LearnMore' ) ); -const StepDesignThemes = lazy( () => - import( '../../pages/Steps/DesignThemes' ) -); - const StepDesignThemeStylesMenu = lazy( () => import( '../../pages/Steps/DesignThemeStyles/Menu' ) ); @@ -194,8 +189,8 @@ export const steps = [ { path: '/wp-setup/step/get-started/welcome', title: __( 'Welcome', 'wp-module-onboarding' ), - /* translators: %s: website or store */ heading: sprintf( + /* translators: %s: website or store */ __( 'Make your %s dreams a reality!', 'wp-module-onboarding' ), translations( 'website' ) ), @@ -217,8 +212,8 @@ export const steps = [ { path: '/wp-setup/step/get-started/experience', title: __( 'WordPress Experience', 'wp-module-onboarding' ), - /* translators: %s: website or store */ heading: sprintf( + /* translators: %s: website or store */ __( 'Help us tailor this setup to your %s', 'wp-module-onboarding' @@ -245,26 +240,26 @@ export const steps = [ }, { path: '/wp-setup/step/get-started/site-primary', - /* translators: %s: website or store */ title: sprintf( + /* translators: %s: website or store */ __( 'Primary %s Setup', 'wp-module-onboarding' ), translations( 'Site' ) ), - /* translators: %s: website or store */ heading: sprintf( + /* translators: %s: website or store */ __( 'Help us tailor this setup to your %s', 'wp-module-onboarding' ), translations( 'site' ) ), - /* translators: %s: website or store */ subheading: sprintf( + /* translators: %s: website or store */ __( 'What type of %s is it?', 'wp-module-onboarding' ), translations( 'site' ) ), - /* translators: %s: website or store */ description: sprintf( + /* translators: %s: website or store */ __( "Setup more of your %s, show you around WordPress or share secrets to success -- we'll follow your lead on how you'd like to proceed.", 'wp-module-onboarding' @@ -284,26 +279,26 @@ export const steps = [ }, { path: '/wp-setup/step/get-started/site-secondary', - /* translators: %s: website or store */ title: sprintf( + /* translators: %s: website or store */ __( 'Secondary %s Setup', 'wp-module-onboarding' ), translations( 'Site' ) ), - /* translators: %s: website or store */ heading: sprintf( + /* translators: %s: website or store */ __( 'Help us tailor this setup to your %s', 'wp-module-onboarding' ), translations( 'site' ) ), - /* translators: %s: website or store */ subheading: sprintf( + /* translators: %s: website or store */ __( 'What type of %s is it?', 'wp-module-onboarding' ), translations( 'site' ) ), - /* translators: %s: website or store */ description: sprintf( + /* translators: %s: website or store */ __( "Setup more of your %s, show you around WordPress or share secrets to success -- we'll follow your lead on how you'd like to proceed.", 'wp-module-onboarding' @@ -340,8 +335,8 @@ export const steps = [ { path: '/wp-setup/step/basic-info', title: __( 'Basic Info', 'wp-module-onboarding' ), - /* translators: %s: website or store */ heading: sprintf( + /* translators: %s: website or store */ __( 'Introduce us to this %s', 'wp-module-onboarding' ), translations( 'website' ) ), @@ -349,8 +344,8 @@ export const steps = [ 'So we can introduce it to the web', 'wp-module-onboarding' ), - /* translators: %s: website or store */ description: sprintf( + /* translators: %s: website or store */ __( 'Help visitors, search results and social media identify your %s.', 'wp-module-onboarding' @@ -628,7 +623,7 @@ export const routes = [ ...pages, ...steps ]; /** * Filter-out the design steps and register a fake step in their place. * - * @return + * @return {Array} steps */ export const initialTopSteps = () => { const topSteps = filter( steps, ( step ) => { @@ -669,7 +664,7 @@ export const initialTopSteps = () => { /** * Filter out all non-design steps. * - * @return + * @return {Array} steps */ export const initialDesignSteps = () => { const designSteps = filter( steps, ( step ) => { From 7b1e224becc2aed39056c69c16d1630b0fa15deb Mon Sep 17 00:00:00 2001 From: arunshenoy99 Date: Fri, 28 Apr 2023 20:55:11 +0530 Subject: [PATCH 05/20] rename the function to reduce redundant naming --- includes/RestApi/SiteClassificationController.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/RestApi/SiteClassificationController.php b/includes/RestApi/SiteClassificationController.php index 77820fb49..863e764b3 100644 --- a/includes/RestApi/SiteClassificationController.php +++ b/includes/RestApi/SiteClassificationController.php @@ -35,18 +35,18 @@ public function register_routes() { $this->rest_base, array( 'methods' => \WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_site_classification' ), + 'callback' => array( $this, 'get' ), 'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), ) ); } /** - * Fetch the Site Classification data using the data module helper. + * Get site classification data. * * @return array */ - public function get_site_classification() { + public function get() { if ( ! class_exists( 'NewfoldLabs\WP\Module\Data\SiteClassification' ) ) { return array(); } From 2d7ef3795811950a9bcd63bc16f95cabd6ab6ba3 Mon Sep 17 00:00:00 2001 From: arunshenoy99 Date: Mon, 1 May 2023 10:00:14 +0530 Subject: [PATCH 06/20] fix redirect transient updating on every page load whenever the module is disabled --- includes/ModuleController.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/includes/ModuleController.php b/includes/ModuleController.php index 5ec609efd..8df4b8afc 100644 --- a/includes/ModuleController.php +++ b/includes/ModuleController.php @@ -41,9 +41,6 @@ public static function module_switcher() { // Check if the Module Does Exist if ( ModuleRegistry::get( $module_name ) ) { - // Disable the Redirect for Onboarding SPA - LoginRedirect::disable_redirect(); - // Deactivate the Module deactivate( $module_name ); } From 34dae7523891a5ce53cb2a19b5c5c48740793c00 Mon Sep 17 00:00:00 2001 From: arunshenoy99 Date: Mon, 1 May 2023 14:40:28 +0530 Subject: [PATCH 07/20] fix typography live preview not reflecting selections on refresh --- .../Drawer/DrawerPanel/DesignTypography.js | 105 +++++------------- 1 file changed, 28 insertions(+), 77 deletions(-) diff --git a/src/OnboardingSPA/components/Drawer/DrawerPanel/DesignTypography.js b/src/OnboardingSPA/components/Drawer/DrawerPanel/DesignTypography.js index 2db46bd5e..8f5813473 100644 --- a/src/OnboardingSPA/components/Drawer/DrawerPanel/DesignTypography.js +++ b/src/OnboardingSPA/components/Drawer/DrawerPanel/DesignTypography.js @@ -3,7 +3,7 @@ import { useSelect, useDispatch } from '@wordpress/data'; import { useState, useEffect, useRef } from '@wordpress/element'; import { store as nfdOnboardingStore } from '../../../store'; -import { getGlobalStyles, getThemeFonts } from '../../../utils/api/themes'; +import { getThemeFonts } from '../../../utils/api/themes'; import { useGlobalStylesOutput } from '../../../utils/global-styles/use-global-styles-output'; import { THEME_STATUS_ACTIVE, THEME_STATUS_INIT } from '../../../../constants'; @@ -12,7 +12,6 @@ const DesignTypography = () => { const [ isLoaded, setIsLoaded ] = useState( false ); const [ selectedFont, setSelectedFont ] = useState(); const [ fontPalettes, setFontPalettes ] = useState(); - const [ isAccordionClosed, setIsAccordionClosed ] = useState( true ); const { storedPreviewSettings, currentData, themeStatus } = useSelect( ( select ) => { @@ -34,19 +33,12 @@ const DesignTypography = () => { } = useDispatch( nfdOnboardingStore ); const getFontStylesAndPatterns = async () => { - const fontPalettes = await getThemeFonts(); - if ( fontPalettes?.error ) { + const fonts = await getThemeFonts(); + if ( fonts?.error ) { return updateThemeStatus( THEME_STATUS_INIT ); } - setFontPalettes( fontPalettes?.body ); + setFontPalettes( fonts?.body ); - if ( currentData?.data?.typography?.slug !== '' ) { - handleClick( - currentData?.data?.typography?.slug, - storedPreviewSettings, - fontPalettes?.body - ); - } const stylesCustom = storedPreviewSettings?.settings?.styles[ 0 ]?.css; if ( stylesCustom ) { // Loads in all CSS variables related to fontFamily @@ -59,20 +51,27 @@ const DesignTypography = () => { setIsLoaded( true ); }; + useEffect( () => { + if ( + currentData?.data?.typography?.slug !== '' && + fontPalettes !== undefined + ) { + setSelectedFont( currentData?.data?.typography?.slug ); + handleClick( currentData?.data?.typography?.slug ); + } + }, [ fontPalettes, storedPreviewSettings ] ); + useEffect( () => { if ( ! isLoaded && THEME_STATUS_ACTIVE === themeStatus ) getFontStylesAndPatterns(); }, [ isLoaded, themeStatus ] ); - const handleClick = async ( - fontStyle, - selectedGlobalStyle = storedPreviewSettings, - fontPalettesCopy = fontPalettes - ) => { + const handleClick = async ( fontStyle ) => { setSelectedFont( fontStyle ); // Changes the Global Styles to Recompute css properties - const globalStylesCopy = selectedGlobalStyle; + const globalStylesCopy = storedPreviewSettings; + const fontPalettesCopy = fontPalettes; if ( globalStylesCopy?.styles?.typography?.fontFamily && @@ -118,45 +117,28 @@ const DesignTypography = () => { currentData.data.typography.data = fontPalettesCopy[ fontStyle ]; updatePreviewSettings( + // eslint-disable-next-line react-hooks/rules-of-hooks useGlobalStylesOutput( globalStylesCopy, storedPreviewSettings ) ); setCurrentOnboardingData( currentData ); }; - async function resetFonts() { - setSelectedFont( '' ); - const globalStyles = await getGlobalStyles(); - let selectedGlobalStyle; - if ( currentData?.data?.theme?.variation ) { - selectedGlobalStyle = globalStyles.body.filter( - ( globalStyle ) => - globalStyle.title === currentData.data.theme.variation - )[ 0 ]; - } else if ( globalStyles.body[ 0 ]?.id === 0 ) { - selectedGlobalStyle = globalStyles.body[ 0 ]; - } - updatePreviewSettings( - useGlobalStylesOutput( selectedGlobalStyle, storedPreviewSettings ) - ); - - currentData.data.typography.slug = ''; - currentData.data.typography.data = []; - setCurrentOnboardingData( currentData ); - } - function buildPalettes() { - const paletteRenderedList = []; - for ( const fontStyle in fontPalettes ) { + return Object.keys( fontPalettes ).map( ( fontStyle, idx ) => { const splitLabel = fontPalettes[ fontStyle ]?.label.split( '&', 2 ); - if ( splitLabel.length === 0 ) continue; - paletteRenderedList.push( + if ( splitLabel.length === 0 ) return null; + return (
handleClick( fontStyle ) } + onClick={ () => handleClick( fontStyle ) } + onKeyDown={ () => handleClick( fontStyle ) } >
{
); - } - - return paletteRenderedList; - } - - function buildCustomPalette() { - return ( -
-
- setIsAccordionClosed( ! isAccordionClosed ) - } - > -
- SELECT CUSTOM FONTS -
- { isAccordionClosed && ( -
+
- ) } - { ! isAccordionClosed && ( -
-
- ) } -
-
- ); + } ); } return (

{ __( 'Font Palettes', 'wp-module-onboarding' ) }

- { /* { selectedFont && -
-
Reset Button
-
- } */ } { fontPalettes && buildPalettes() } - { /* { fontPalettes && buildCustomPalette() } */ }
); }; From 12b8f948cab7bb03ae5373125899f2d3ebca8541 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Tue, 2 May 2023 11:07:31 +0530 Subject: [PATCH 08/20] Update index.js --- src/OnboardingSPA/pages/Steps/DesignThemeStyles/Menu/index.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/OnboardingSPA/pages/Steps/DesignThemeStyles/Menu/index.js b/src/OnboardingSPA/pages/Steps/DesignThemeStyles/Menu/index.js index aeceed969..1a7342da8 100644 --- a/src/OnboardingSPA/pages/Steps/DesignThemeStyles/Menu/index.js +++ b/src/OnboardingSPA/pages/Steps/DesignThemeStyles/Menu/index.js @@ -121,9 +121,7 @@ const StepDesignThemeStylesMenu = () => { setCurrentOnboardingData( currentData ); // Find the first Custom Conditional Step and navigate there - navigate( - conditionalSteps[ Object.keys( conditionalSteps )[ 0 ] ].path - ); + navigate( conditionalSteps.designColors.path ); }; const buildPreviews = () => { From 9389e5d29014cf269fe192b1ef455f2da7af4901 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Tue, 2 May 2023 14:09:10 +0530 Subject: [PATCH 09/20] Update index.js --- .../pages/Steps/DesignThemeStyles/Preview/index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OnboardingSPA/pages/Steps/DesignThemeStyles/Preview/index.js b/src/OnboardingSPA/pages/Steps/DesignThemeStyles/Preview/index.js index 5549bfa33..eb5e050c5 100644 --- a/src/OnboardingSPA/pages/Steps/DesignThemeStyles/Preview/index.js +++ b/src/OnboardingSPA/pages/Steps/DesignThemeStyles/Preview/index.js @@ -98,10 +98,10 @@ const StepDesignThemeStylesPreview = () => { updateRoutes( updates.routes ); updateDesignSteps( updates.designSteps ); updateAllSteps( updates.allSteps ); - setCustomize( customize ); + setCustomize( customizeSelection ); if ( updateOnboardingData ) { - currentData.data.customDesign = customize; + currentData.data.customDesign = customizeSelection; setCurrentOnboardingData( currentData ); } }; From 0333ab8d78ce823ffcfea17aa1b6e4a7b9104c48 Mon Sep 17 00:00:00 2001 From: William Earnhardt Date: Tue, 2 May 2023 18:02:29 -0400 Subject: [PATCH 10/20] Clean up redirect handler logic --- includes/LoginRedirect.php | 43 +++++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 19 deletions(-) diff --git a/includes/LoginRedirect.php b/includes/LoginRedirect.php index 65c18f3fa..297120ce0 100644 --- a/includes/LoginRedirect.php +++ b/includes/LoginRedirect.php @@ -12,49 +12,54 @@ class LoginRedirect { /** * Handles the redirect to onboarding * - * @param [type] $redirect The requested redirect URL. - * @param [type] $redirect_to The requested redirect URL via param. - * @param [type] $user The logged in user object. + * @param string $redirect The requested redirect URL * @return string */ - public static function handle_redirect( $redirect, $redirect_to, $user ) { + public static function handle_redirect( $redirect ) { $redirect_option_name = Options::get_option_name( 'redirect' ); + // If request has ?nfd_module_onboarding_redirect=false then temporarily disable the redirect if ( isset( $_GET[ $redirect_option_name ] ) && 'false' === $_GET[ $redirect_option_name ] ) { self::disable_redirect(); } - $flow_exited = false; - $flow_completed = false; - $flow_data = \get_option( Options::get_option_name( 'flow' ), false ); - if ( ! empty( $flow_data ) ) { - $flow_exited = ( ! empty( $flow_data['hasExited'] ) ); - $flow_completed = ( ! empty( $flow_data['isComplete'] ) ); + // Redirect was temporarily disabled via transient + if ( \get_transient( Options::get_option_name( 'redirect_param' ) ) === '1' ) { + return $redirect; + } + + // Don't redirect if coming soon is off. User has launched their site + if ( \get_option( Options::get_option_name( 'coming_soon', false ), 'true' ) !== 'true' ) { + return $redirect; } - if ( \get_transient( Options::get_option_name( 'redirect_param' ) ) === '1' - || $flow_exited - || $flow_completed - ) { + // Don't redirect if they have intentionally exited or completed onboarding + $flow_data = \get_option( Options::get_option_name( 'flow' ), false ); + if ( data_get( $flow_data, 'hasExited' ) || data_get( $flow_data, 'isComplete' ) ) { return $redirect; } + // Check for disabled redirect database option: nfd_module_onboarding_redirect $redirect_option = \get_option( $redirect_option_name, null ); + // If not set, then set it to true if ( empty( $redirect_option ) ) { $redirect_option = \update_option( $redirect_option_name, true ); } + if (! $redirect_option) { + return $redirect; + } + + // If site was created more than 72 hours ago, don't redirect to onboarding $install_date = new DateTime( \get_option( Options::get_option_name( 'install_date', false ), gmdate( 'M d, Y' ) ) ); $current_date = new DateTime( gmdate( 'M d, Y' ) ); $interval = $current_date->diff( $install_date ); $interval_in_hours = ( $interval->days * 24 ) + $interval->h; - - if ( ! ( $redirect_option - && \get_option( Options::get_option_name( 'coming_soon', false ), 'true' ) === 'true' - && ( $interval_in_hours <= 72 ) ) ) { + if ( $interval_in_hours >= 72 ) { return $redirect; } - if ( self::is_administrator( $user ) ) { + // Finally, if we made it this far, then set the redirect URL to point to onboarding if the user is an admin + if ( ! current_user_can( 'manage_options' ) ) { return \admin_url( '/index.php?page=nfd-onboarding' ); } From 014454bfd24f2215d40e7bc3e24a308ec0fe4dff Mon Sep 17 00:00:00 2001 From: William Earnhardt Date: Tue, 2 May 2023 18:02:54 -0400 Subject: [PATCH 11/20] Remove unnecessary capability check code --- includes/LoginRedirect.php | 22 ---------------------- 1 file changed, 22 deletions(-) diff --git a/includes/LoginRedirect.php b/includes/LoginRedirect.php index 297120ce0..e5f836134 100644 --- a/includes/LoginRedirect.php +++ b/includes/LoginRedirect.php @@ -66,28 +66,6 @@ public static function handle_redirect( $redirect ) { return $redirect; } - /** - * Check if we have a valid user. - * - * @param \WP_User $user The WordPress user object. - * - * @return bool - */ - public static function is_user( $user ) { - return $user && is_object( $user ) && is_a( $user, 'WP_User' ); - } - - /** - * Check if a user is an administrator. - * - * @param \WP_User $user WordPress user. - * - * @return bool - */ - public static function is_administrator( $user ) { - return self::is_user( $user ) && $user->has_cap( Permissions::ADMIN ); - } - /** * Sets a transient that disables redirect to onboarding on login. * From d9d6fe748697960184f986ff439aac5e579aae02 Mon Sep 17 00:00:00 2001 From: William Earnhardt Date: Tue, 2 May 2023 18:03:20 -0400 Subject: [PATCH 12/20] Add sso filter hook --- includes/Application.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/Application.php b/includes/Application.php index 9a98be82c..9561cccea 100644 --- a/includes/Application.php +++ b/includes/Application.php @@ -55,7 +55,8 @@ public function __construct( Container $container ) { // Reset the stored Compatibility Status every time WP Core is updated. \add_action( '_core_updated_successfully', array( Status::class, 'reset' ) ); - \add_action( 'login_redirect', array( LoginRedirect::class, 'handle_redirect' ), 10, 3 ); + \add_filter( 'login_redirect', array( LoginRedirect::class, 'handle_redirect' ), 10 ); + \add_filter( 'newfold_sso_success_url', array( LoginRedirect::class, 'handle_redirect' ), 10 ); \add_filter( Options::get_option_name( 'redirect' ) . '_disable', array( LoginRedirect::class, 'remove_handle_redirect_action' ) From af7560a846b25b05f807ce18b64c6449f94f3121 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Wed, 3 May 2023 10:17:48 +0530 Subject: [PATCH 13/20] Update index.js --- .../components/HeadingWithSubHeading/index.js | 12 ++---------- 1 file changed, 2 insertions(+), 10 deletions(-) diff --git a/src/OnboardingSPA/components/HeadingWithSubHeading/index.js b/src/OnboardingSPA/components/HeadingWithSubHeading/index.js index fb00afc72..42330c799 100644 --- a/src/OnboardingSPA/components/HeadingWithSubHeading/index.js +++ b/src/OnboardingSPA/components/HeadingWithSubHeading/index.js @@ -1,5 +1,3 @@ -import { __ } from '@wordpress/i18n'; - /** * Interface Cards with standard design. * @@ -11,15 +9,9 @@ import { __ } from '@wordpress/i18n'; const HeadingWithSubHeading = ( { title, subtitle, children } ) => { return (
-

- { /* eslint-disable-next-line @wordpress/i18n-no-variables */ } - { __( title, 'wp-module-onboarding' ) } -

+

{ title }

{ subtitle && ( -

- { /* eslint-disable-next-line @wordpress/i18n-no-variables */ } - { __( subtitle, 'wp-module-onboarding' ) } -

+

{ subtitle }

) } { children }
From 94be00cfc216af77d64d7568e525787c01bd2df6 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Wed, 3 May 2023 10:35:19 +0530 Subject: [PATCH 14/20] Adding a content.js file --- .../Steps/DesignThemeStyles/Menu/index.js | 8 +++--- .../Steps/DesignThemeStyles/Preview/index.js | 13 +++------- .../pages/Steps/DesignThemeStyles/contents.js | 25 +++++++++++++++++++ 3 files changed, 34 insertions(+), 12 deletions(-) create mode 100644 src/OnboardingSPA/pages/Steps/DesignThemeStyles/contents.js diff --git a/src/OnboardingSPA/pages/Steps/DesignThemeStyles/Menu/index.js b/src/OnboardingSPA/pages/Steps/DesignThemeStyles/Menu/index.js index 1a7342da8..d0d9ebed4 100644 --- a/src/OnboardingSPA/pages/Steps/DesignThemeStyles/Menu/index.js +++ b/src/OnboardingSPA/pages/Steps/DesignThemeStyles/Menu/index.js @@ -2,6 +2,7 @@ import { useSelect, useDispatch } from '@wordpress/data'; import { useState, useEffect } from '@wordpress/element'; import { useNavigate, useLocation } from 'react-router-dom'; +import getContents from '../contents'; import { store as nfdOnboardingStore } from '../../../../store'; import CommonLayout from '../../../../components/Layouts/Common'; import HeadingWithSubHeading from '../../../../components/HeadingWithSubHeading'; @@ -23,6 +24,7 @@ import { import { addColorAndTypographyRoutes } from '../utils'; const StepDesignThemeStylesMenu = () => { + const content = getContents(); const location = useLocation(); const [ pattern, setPattern ] = useState(); const [ globalStyles, setGlobalStyles ] = useState(); @@ -146,14 +148,14 @@ const StepDesignThemeStylesMenu = () => {
- +

- { currentStep?.subheading }{ ' ' } + { content?.subheading }{ ' ' }

diff --git a/src/OnboardingSPA/pages/Steps/DesignThemeStyles/Preview/index.js b/src/OnboardingSPA/pages/Steps/DesignThemeStyles/Preview/index.js index eb5e050c5..31400c554 100644 --- a/src/OnboardingSPA/pages/Steps/DesignThemeStyles/Preview/index.js +++ b/src/OnboardingSPA/pages/Steps/DesignThemeStyles/Preview/index.js @@ -2,7 +2,6 @@ import { useSelect, useDispatch } from '@wordpress/data'; import { useState, useEffect } from '@wordpress/element'; import { useLocation } from 'react-router-dom'; import { CheckboxControl } from '@wordpress/components'; -import { __ } from '@wordpress/i18n'; import { addColorAndTypographyRoutes, removeColorAndTypographyRoutes, @@ -12,6 +11,7 @@ import { LivePreview, GlobalStylesProvider, } from '../../../../components/LivePreview'; +import getContents from '../contents'; import CommonLayout from '../../../../components/Layouts/Common'; import { VIEW_DESIGN_THEME_STYLES_PREVIEW, @@ -24,6 +24,7 @@ import { getPatterns } from '../../../../utils/api/patterns'; import { DesignStateHandler } from '../../../../components/StateHandlers'; const StepDesignThemeStylesPreview = () => { + const content = getContents(); const location = useLocation(); const [ pattern, setPattern ] = useState(); const [ customize, setCustomize ] = useState( false ); @@ -119,15 +120,9 @@ const StepDesignThemeStylesPreview = () => { label={
- { __( - 'Customize Colors & Fonts?', - 'wp-module-onboarding' - ) } + { content?.checkbox_label } - { __( - 'Check to customize in the next few steps (or leave empty and use the Site Editor later)', - 'wp-module-onboarding' - ) } + { content?.checkbox_hint }
diff --git a/src/OnboardingSPA/pages/Steps/DesignThemeStyles/contents.js b/src/OnboardingSPA/pages/Steps/DesignThemeStyles/contents.js new file mode 100644 index 000000000..4371420db --- /dev/null +++ b/src/OnboardingSPA/pages/Steps/DesignThemeStyles/contents.js @@ -0,0 +1,25 @@ +import { __ } from '@wordpress/i18n'; + +const getContents = () => { + return { + heading: __( + 'Lets tailor your theme for the perfect fit', + 'wp-module-onboarding' + ), + subheading: __( + 'Start with a style preset or', + 'wp-module-onboarding' + ), + subheading_link: __( 'build a custom design.', 'wp-module-onboarding' ), + checkbox_label: __( + 'Customize Colors & Fonts?', + 'wp-module-onboarding' + ), + checkbox_hint: __( + 'Check to customize in the next few steps (or leave empty and use the Site Editor later)', + 'wp-module-onboarding' + ), + }; +}; + +export default getContents; From c6e2d4942b8d20d3521ad7a5e25037281a40485f Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Wed, 3 May 2023 10:51:09 +0530 Subject: [PATCH 15/20] Fixed Code --- .../pages/Steps/DesignThemeStyles/Menu/index.js | 6 +++--- .../pages/Steps/DesignThemeStyles/Preview/index.js | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/OnboardingSPA/pages/Steps/DesignThemeStyles/Menu/index.js b/src/OnboardingSPA/pages/Steps/DesignThemeStyles/Menu/index.js index d0d9ebed4..15fb19a3a 100644 --- a/src/OnboardingSPA/pages/Steps/DesignThemeStyles/Menu/index.js +++ b/src/OnboardingSPA/pages/Steps/DesignThemeStyles/Menu/index.js @@ -148,14 +148,14 @@ const StepDesignThemeStylesMenu = () => {
- +

- { content?.subheading }{ ' ' } + { `${ content.subheading } ` }

diff --git a/src/OnboardingSPA/pages/Steps/DesignThemeStyles/Preview/index.js b/src/OnboardingSPA/pages/Steps/DesignThemeStyles/Preview/index.js index 31400c554..61a15de9a 100644 --- a/src/OnboardingSPA/pages/Steps/DesignThemeStyles/Preview/index.js +++ b/src/OnboardingSPA/pages/Steps/DesignThemeStyles/Preview/index.js @@ -120,9 +120,9 @@ const StepDesignThemeStylesPreview = () => { label={
- { content?.checkbox_label } + { content.checkbox_label } - { content?.checkbox_hint } + { content.checkbox_hint }
From 19d2efef3249b95ad55f34f51a38712d1ec23cf5 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Wed, 3 May 2023 11:00:09 +0530 Subject: [PATCH 16/20] Update default-flow.js --- src/OnboardingSPA/data/routes/default-flow.js | 24 ------------------- 1 file changed, 24 deletions(-) diff --git a/src/OnboardingSPA/data/routes/default-flow.js b/src/OnboardingSPA/data/routes/default-flow.js index 665ff48d0..14ae4dee8 100644 --- a/src/OnboardingSPA/data/routes/default-flow.js +++ b/src/OnboardingSPA/data/routes/default-flow.js @@ -381,18 +381,6 @@ export const steps = [ { path: '/wp-setup/step/design/theme-styles/menu', title: __( 'Theme Styles', 'wp-module-onboarding' ), - heading: __( - 'Lets tailor your theme for the perfect fit', - 'wp-module-onboarding' - ), - subheading: __( - 'Start with a style preset or ', - 'wp-module-onboarding' - ), - description: __( - 'All these styles -- plus the ability to customize them -- are available in the WordPress Site Editor', - 'wp-module-onboarding' - ), Component: StepDesignThemeStylesMenu, Icon: styles, priority: 160, @@ -410,18 +398,6 @@ export const steps = [ { path: '/wp-setup/step/design/theme-styles/preview', title: __( 'Theme Styles', 'wp-module-onboarding' ), - heading: __( - 'Lets tailor your theme for the perfect fit', - 'wp-module-onboarding' - ), - subheading: __( - "Use these styles or bring your own. You're always free to remix them.", - 'wp-module-onboarding' - ), - description: __( - 'All these styles -- plus the ability to customize them -- are available in the WordPress Site Editor', - 'wp-module-onboarding' - ), Component: StepDesignThemeStylesPreview, Icon: styles, priority: 170, From f912518c9a828dba977150d01110f34bef8f03ad Mon Sep 17 00:00:00 2001 From: William Earnhardt Date: Wed, 3 May 2023 08:51:09 -0400 Subject: [PATCH 17/20] Fix whitespace issue --- includes/LoginRedirect.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/includes/LoginRedirect.php b/includes/LoginRedirect.php index e5f836134..e8d836297 100644 --- a/includes/LoginRedirect.php +++ b/includes/LoginRedirect.php @@ -19,8 +19,8 @@ public static function handle_redirect( $redirect ) { $redirect_option_name = Options::get_option_name( 'redirect' ); // If request has ?nfd_module_onboarding_redirect=false then temporarily disable the redirect if ( isset( $_GET[ $redirect_option_name ] ) - && 'false' === $_GET[ $redirect_option_name ] ) { - self::disable_redirect(); + && 'false' === $_GET[ $redirect_option_name ] ) { + self::disable_redirect(); } // Redirect was temporarily disabled via transient @@ -45,7 +45,7 @@ public static function handle_redirect( $redirect ) { if ( empty( $redirect_option ) ) { $redirect_option = \update_option( $redirect_option_name, true ); } - if (! $redirect_option) { + if ( ! $redirect_option ) { return $redirect; } @@ -55,12 +55,12 @@ public static function handle_redirect( $redirect ) { $interval = $current_date->diff( $install_date ); $interval_in_hours = ( $interval->days * 24 ) + $interval->h; if ( $interval_in_hours >= 72 ) { - return $redirect; + return $redirect; } // Finally, if we made it this far, then set the redirect URL to point to onboarding if the user is an admin if ( ! current_user_can( 'manage_options' ) ) { - return \admin_url( '/index.php?page=nfd-onboarding' ); + return \admin_url( '/index.php?page=nfd-onboarding' ); } return $redirect; @@ -72,7 +72,7 @@ public static function handle_redirect( $redirect ) { * @return void */ public static function disable_redirect() { - \set_transient( Options::get_option_name( 'redirect_param' ), '1', 30 ); + \set_transient( Options::get_option_name( 'redirect_param' ), '1', 30 ); } /** @@ -81,7 +81,7 @@ public static function disable_redirect() { * @return void */ public static function enable_redirect() { - \set_transient( Options::get_option_name( 'redirect_param' ), '0', 30 ); + \set_transient( Options::get_option_name( 'redirect_param' ), '0', 30 ); } /** @@ -90,6 +90,6 @@ public static function enable_redirect() { * @return bool */ public static function remove_handle_redirect_action() { - return \remove_action( 'login_redirect', array( __CLASS__, 'handle_redirect' ) ); + return \remove_action( 'login_redirect', array( __CLASS__, 'handle_redirect' ) ); } } From f90571bb6dd7c3f0a0ff3464dbdbb086a56ac2f6 Mon Sep 17 00:00:00 2001 From: William Earnhardt Date: Wed, 3 May 2023 09:21:07 -0400 Subject: [PATCH 18/20] Rename variable for clarity --- includes/LoginRedirect.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/includes/LoginRedirect.php b/includes/LoginRedirect.php index e8d836297..6d42b3772 100644 --- a/includes/LoginRedirect.php +++ b/includes/LoginRedirect.php @@ -12,10 +12,10 @@ class LoginRedirect { /** * Handles the redirect to onboarding * - * @param string $redirect The requested redirect URL + * @param string $original_redirect The requested redirect URL * @return string */ - public static function handle_redirect( $redirect ) { + public static function handle_redirect( $original_redirect ) { $redirect_option_name = Options::get_option_name( 'redirect' ); // If request has ?nfd_module_onboarding_redirect=false then temporarily disable the redirect if ( isset( $_GET[ $redirect_option_name ] ) @@ -25,18 +25,18 @@ public static function handle_redirect( $redirect ) { // Redirect was temporarily disabled via transient if ( \get_transient( Options::get_option_name( 'redirect_param' ) ) === '1' ) { - return $redirect; + return $original_redirect; } // Don't redirect if coming soon is off. User has launched their site if ( \get_option( Options::get_option_name( 'coming_soon', false ), 'true' ) !== 'true' ) { - return $redirect; + return $original_redirect; } // Don't redirect if they have intentionally exited or completed onboarding $flow_data = \get_option( Options::get_option_name( 'flow' ), false ); if ( data_get( $flow_data, 'hasExited' ) || data_get( $flow_data, 'isComplete' ) ) { - return $redirect; + return $original_redirect; } // Check for disabled redirect database option: nfd_module_onboarding_redirect @@ -46,7 +46,7 @@ public static function handle_redirect( $redirect ) { $redirect_option = \update_option( $redirect_option_name, true ); } if ( ! $redirect_option ) { - return $redirect; + return $original_redirect; } // If site was created more than 72 hours ago, don't redirect to onboarding @@ -55,7 +55,7 @@ public static function handle_redirect( $redirect ) { $interval = $current_date->diff( $install_date ); $interval_in_hours = ( $interval->days * 24 ) + $interval->h; if ( $interval_in_hours >= 72 ) { - return $redirect; + return $original_redirect; } // Finally, if we made it this far, then set the redirect URL to point to onboarding if the user is an admin @@ -63,7 +63,7 @@ public static function handle_redirect( $redirect ) { return \admin_url( '/index.php?page=nfd-onboarding' ); } - return $redirect; + return $original_redirect; } /** From 8c1d8e5db5bb4d8e9135ffcd8af7c04aca67b9dc Mon Sep 17 00:00:00 2001 From: William Earnhardt Date: Wed, 3 May 2023 09:25:26 -0400 Subject: [PATCH 19/20] Reverse admin check logic --- includes/LoginRedirect.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/LoginRedirect.php b/includes/LoginRedirect.php index 6d42b3772..75e3c8dc9 100644 --- a/includes/LoginRedirect.php +++ b/includes/LoginRedirect.php @@ -59,7 +59,7 @@ public static function handle_redirect( $original_redirect ) { } // Finally, if we made it this far, then set the redirect URL to point to onboarding if the user is an admin - if ( ! current_user_can( 'manage_options' ) ) { + if ( current_user_can( 'manage_options' ) ) { return \admin_url( '/index.php?page=nfd-onboarding' ); } From a5d17ef65bebb0c512a38764c9f68aa5090ffc37 Mon Sep 17 00:00:00 2001 From: William Earnhardt Date: Wed, 3 May 2023 10:32:09 -0400 Subject: [PATCH 20/20] Move admin check to the top to prevent queries for non-admins --- includes/LoginRedirect.php | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/includes/LoginRedirect.php b/includes/LoginRedirect.php index 75e3c8dc9..624557518 100644 --- a/includes/LoginRedirect.php +++ b/includes/LoginRedirect.php @@ -16,6 +16,11 @@ class LoginRedirect { * @return string */ public static function handle_redirect( $original_redirect ) { + // Don't redirect if user is not an admin + if ( ! current_user_can( 'manage_options' ) ) { + return $original_redirect; + } + $redirect_option_name = Options::get_option_name( 'redirect' ); // If request has ?nfd_module_onboarding_redirect=false then temporarily disable the redirect if ( isset( $_GET[ $redirect_option_name ] ) @@ -58,12 +63,8 @@ public static function handle_redirect( $original_redirect ) { return $original_redirect; } - // Finally, if we made it this far, then set the redirect URL to point to onboarding if the user is an admin - if ( current_user_can( 'manage_options' ) ) { - return \admin_url( '/index.php?page=nfd-onboarding' ); - } - - return $original_redirect; + // Finally, if we made it this far, then set the redirect URL to point to onboarding + return \admin_url( '/index.php?page=nfd-onboarding' ); } /**