From efc08ca2e09a195d665278eee59b81ccbbf6b058 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Mon, 21 Nov 2022 17:35:11 +0530 Subject: [PATCH 01/49] Basic Components for Site Features --- .../CheckboxTemplate/CheckboxItem/index.js | 18 ++++ .../CheckboxItem/stylesheet.scss | 0 .../CheckboxTemplate/CheckboxList/index.js | 29 ++++++ .../CheckboxList/stylesheet.scss | 0 .../components/CheckboxTemplate/index.js | 2 + src/OnboardingSPA/data/routes/default-flow.js | 4 +- .../pages/Steps/SiteFeatures/index.js | 91 +++++++++++++++++-- src/OnboardingSPA/styles/app.scss | 2 + 8 files changed, 135 insertions(+), 11 deletions(-) create mode 100644 src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js create mode 100644 src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss create mode 100644 src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/index.js create mode 100644 src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/stylesheet.scss create mode 100644 src/OnboardingSPA/components/CheckboxTemplate/index.js diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js new file mode 100644 index 000000000..f1882da40 --- /dev/null +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js @@ -0,0 +1,18 @@ +/** + * Checkbox Item Component + * This returns a Single Element with a toggable description + * + * @returns CheckboxItem + */ + +const CheckboxItem = ({ title, subtitle, desc }) => { + + return ( +
+ {title} + {subtitle} +
+ ); +}; + +export default CheckboxItem; diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss new file mode 100644 index 000000000..e69de29bb diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/index.js b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/index.js new file mode 100644 index 000000000..5ff9281d9 --- /dev/null +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/index.js @@ -0,0 +1,29 @@ +import { CheckboxItem } from "../index"; + + +/** + * Checkbox List Component + * This returns a List of Checkbox Items to be placed dynamically on screen + * + * @returns CheckboxList + */ +const CheckboxList = ({ data }) => { + + const buildCheckboxItems = () => { + return data.map((item, idx) => { + return + }); + } + + return ( +
+ HEy + { buildCheckboxItems() } +
+ ); +}; + +export default CheckboxList; diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/stylesheet.scss b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/stylesheet.scss new file mode 100644 index 000000000..e69de29bb diff --git a/src/OnboardingSPA/components/CheckboxTemplate/index.js b/src/OnboardingSPA/components/CheckboxTemplate/index.js new file mode 100644 index 000000000..024215455 --- /dev/null +++ b/src/OnboardingSPA/components/CheckboxTemplate/index.js @@ -0,0 +1,2 @@ +export { default as CheckboxItem } from './CheckboxItem'; +export { default as CheckboxList } from './CheckboxList'; diff --git a/src/OnboardingSPA/data/routes/default-flow.js b/src/OnboardingSPA/data/routes/default-flow.js index e1a18eacf..c5c63b323 100644 --- a/src/OnboardingSPA/data/routes/default-flow.js +++ b/src/OnboardingSPA/data/routes/default-flow.js @@ -510,9 +510,9 @@ export const steps = [ { path: '/wp-setup/step/site-features', title: __( 'Features', 'wp-module-onboarding' ), - heading: __( 'Our toolbox is your toolbox', 'wp-module-onboarding' ), + heading: __( 'Key features to supercharge your site', 'wp-module-onboarding' ), subheading: __( - "We've learned a lot in 16 years of WordPress! Now that expertise is yours.", + "Our toolbox of Plugins & Services is your toolbox.", 'wp-module-onboarding' ), description: __( diff --git a/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js b/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js index 76b143abb..055eeff80 100644 --- a/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js +++ b/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js @@ -1,20 +1,93 @@ -import { store as nfdOnboardingStore } from '../../../store'; -import { useDispatch } from '@wordpress/data'; import { useEffect } from '@wordpress/element'; +import { useViewportMatch } from '@wordpress/compose'; +import { useSelect, useDispatch } from '@wordpress/data'; +import { store as nfdOnboardingStore } from '../../../store'; +import { VIEW_NAV_PRIMARY } from '../../../../constants'; import CommonLayout from '../../../components/Layouts/Common'; -import StepOverview from '../../../components/StepOverview'; +import HeadingWithSubHeading from '../../../components/HeadingWithSubHeading'; +import CheckboxList from '../../../components/CheckboxTemplate/CheckboxList'; const StepSiteFeatures = () => { - const { setIsSidebarOpened } = useDispatch( nfdOnboardingStore ); + const isLargeViewport = useViewportMatch('medium'); + const { setIsDrawerOpened, setDrawerActiveView, setIsSidebarOpened, setIsDrawerSuppressed } = + useDispatch(nfdOnboardingStore); + + const { currentStep } = useSelect( + (select) => { + return { + currentStep: select(nfdOnboardingStore).getCurrentStep() + }; + }, + [] + ); + + useEffect(() => { + if (isLargeViewport) { + setIsDrawerOpened(true); + } + setIsSidebarOpened(false); + setIsDrawerSuppressed(false); + setDrawerActiveView(VIEW_NAV_PRIMARY); + }, []); - useEffect( () => { - setIsSidebarOpened( false ); - }, [] ); + const data = [ + { + 'title': 'Security, Speed & Growth', + 'subtitle': 'Powered by Jetpack', + 'desc': 'Jetpack' + }, + { + 'title': 'Forms', + 'subtitle': 'Powered by WP Forms', + 'desc': 'WP Forms' + }, + { + 'title': 'Site Traffic', + 'subtitle': 'Powered by MonsterInsights', + 'desc': 'MonsterInsights' + }, + { + 'title': 'Search Engine Optimization', + 'subtitle': 'Powered by Yoast', + 'desc': 'Yoast' + }, + { + 'title': 'Email Newsletters', + 'subtitle': 'Powered by Creative Email', + 'desc': 'Creative Email' + }, + { + 'title': 'Enhanced Product Search', + 'subtitle': 'Powered by YITH', + 'desc': 'YITH' + }, + { + 'title': 'Enhanced Product Filters', + 'subtitle': 'Powered by YITH', + 'desc': 'YITH' + }, + { + 'title': 'Bookings & Appointments', + 'subtitle': 'Powered by YITH', + 'desc': 'YITH' + }, + { + 'title': 'Product Wishlists', + 'subtitle': 'Powered by YITH', + 'desc': 'YITH' + }, + { + 'title': 'Lead Generation', + 'subtitle': 'Powered by Optin Monster', + 'desc': 'Optin Monster' + } + ] return ( - - + + + ); }; diff --git a/src/OnboardingSPA/styles/app.scss b/src/OnboardingSPA/styles/app.scss index 31cc4feec..67211109a 100644 --- a/src/OnboardingSPA/styles/app.scss +++ b/src/OnboardingSPA/styles/app.scss @@ -34,6 +34,8 @@ @import "../components/Button/NavCardButton/stylesheet"; @import "../pages/Steps/Ecommerce/stylesheet"; @import "../components/ErrorState/stylesheet"; +@import "../components/CheckboxTemplate/CheckboxItem/stylesheet"; +@import "../components/CheckboxTemplate/CheckboxList/stylesheet"; @import "../components/Sidebar/components/LearnMore/Skeleton/stylesheet"; // CSS for Pages From 8286dac16c138d02e2c1fc0fcc7564edeb23277c Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Mon, 21 Nov 2022 17:58:27 +0530 Subject: [PATCH 02/49] Added Some Styling --- .../CheckboxTemplate/CheckboxItem/index.js | 20 ++++++++++++--- .../CheckboxItem/stylesheet.scss | 10 ++++++++ .../CheckboxTemplate/CheckboxList/index.js | 25 +++++++++++++------ .../CheckboxList/stylesheet.scss | 12 +++++++++ .../pages/Steps/SiteFeatures/index.js | 12 ++++++++- 5 files changed, 66 insertions(+), 13 deletions(-) diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js index f1882da40..8aed8ceaf 100644 --- a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js @@ -1,16 +1,28 @@ +import { CheckboxControl } from '@wordpress/components'; + /** * Checkbox Item Component * This returns a Single Element with a toggable description * + * @param {string} icon - The icon name of the Item + * @param {string} title - The Main Title of the Item + * @param {string} subtitle - The Sub Title of the Item + * @param {string} desc - The Description of the Item + * * @returns CheckboxItem */ -const CheckboxItem = ({ title, subtitle, desc }) => { +const CheckboxItem = ({ icon, title, subtitle, desc }) => { return ( -
- {title} - {subtitle} +
+ + {title} + {subtitle} +
+ }/>
); }; diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss index e69de29bb..5d56d184a 100644 --- a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss @@ -0,0 +1,10 @@ +.checkbox-item { + width: 20vw; + margin: 10px; + padding: 10px; + min-width: 300px; + border-radius: 2px; + border: 1px solid #97C8FA; + background: rgba(132, 192, 252, 0.2); + box-shadow: 0px 2px 8px 2px rgba(204, 204, 204, 0.175295); +} \ No newline at end of file diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/index.js b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/index.js index 5ff9281d9..39042a5f2 100644 --- a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/index.js +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/index.js @@ -4,24 +4,33 @@ import { CheckboxItem } from "../index"; /** * Checkbox List Component * This returns a List of Checkbox Items to be placed dynamically on screen - * + * + * @param {Object} data - The List to be shown with a Title, Subtitle and a Description + * * @returns CheckboxList */ const CheckboxList = ({ data }) => { const buildCheckboxItems = () => { return data.map((item, idx) => { - return + return ( + + ) }); } return ( -
- HEy - { buildCheckboxItems() } +
+
+ {buildCheckboxItems().slice(0, Math.floor(data.length/2))} +
+
+ {buildCheckboxItems().slice(Math.floor(data.length / 2), data.length)} +
); }; diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/stylesheet.scss b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/stylesheet.scss index e69de29bb..711c11bb6 100644 --- a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/stylesheet.scss +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/stylesheet.scss @@ -0,0 +1,12 @@ +.checkbox-list { + display: flex; + align-items: center; + justify-content: center; + + &-col { + display: flex; + align-items: center; + flex-direction: column; + justify-content: center; + } +} \ No newline at end of file diff --git a/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js b/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js index 055eeff80..bdb9c9823 100644 --- a/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js +++ b/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js @@ -24,7 +24,7 @@ const StepSiteFeatures = () => { useEffect(() => { if (isLargeViewport) { - setIsDrawerOpened(true); + setIsDrawerOpened(false); } setIsSidebarOpened(false); setIsDrawerSuppressed(false); @@ -33,51 +33,61 @@ const StepSiteFeatures = () => { const data = [ { + 'icon': 'icon-name', 'title': 'Security, Speed & Growth', 'subtitle': 'Powered by Jetpack', 'desc': 'Jetpack' }, { + 'icon': 'icon-name', 'title': 'Forms', 'subtitle': 'Powered by WP Forms', 'desc': 'WP Forms' }, { + 'icon': 'icon-name', 'title': 'Site Traffic', 'subtitle': 'Powered by MonsterInsights', 'desc': 'MonsterInsights' }, { + 'icon': 'icon-name', 'title': 'Search Engine Optimization', 'subtitle': 'Powered by Yoast', 'desc': 'Yoast' }, { + 'icon': 'icon-name', 'title': 'Email Newsletters', 'subtitle': 'Powered by Creative Email', 'desc': 'Creative Email' }, { + 'icon': 'icon-name', 'title': 'Enhanced Product Search', 'subtitle': 'Powered by YITH', 'desc': 'YITH' }, { + 'icon': 'icon-name', 'title': 'Enhanced Product Filters', 'subtitle': 'Powered by YITH', 'desc': 'YITH' }, { + 'icon': 'icon-name', 'title': 'Bookings & Appointments', 'subtitle': 'Powered by YITH', 'desc': 'YITH' }, { + 'icon': 'icon-name', 'title': 'Product Wishlists', 'subtitle': 'Powered by YITH', 'desc': 'YITH' }, { + 'icon': 'icon-name', 'title': 'Lead Generation', 'subtitle': 'Powered by Optin Monster', 'desc': 'Optin Monster' From bdf4d9ce8c4b2104fa5609f920b8e13b94cad2e5 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Tue, 22 Nov 2022 12:46:06 +0530 Subject: [PATCH 03/49] Added some Styling --- .../CheckboxTemplate/CheckboxItem/index.js | 27 +++++++++-- .../CheckboxItem/stylesheet.scss | 48 +++++++++++++++++++ 2 files changed, 72 insertions(+), 3 deletions(-) diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js index 8aed8ceaf..e25e6ec77 100644 --- a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js @@ -1,3 +1,5 @@ +import { Icon, help, search } from '@wordpress/icons'; + import { CheckboxControl } from '@wordpress/components'; /** @@ -17,10 +19,29 @@ const CheckboxItem = ({ icon, title, subtitle, desc }) => { return (
- {title} - {subtitle} +
+
+ +
+
+

{title}

+

{subtitle}

+
+
+ +
}/>
diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss index 5d56d184a..197b4dcbd 100644 --- a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss @@ -2,9 +2,57 @@ width: 20vw; margin: 10px; padding: 10px; + display: flex; min-width: 300px; border-radius: 2px; + align-items: center; border: 1px solid #97C8FA; + justify-content: flex-start; background: rgba(132, 192, 252, 0.2); box-shadow: 0px 2px 8px 2px rgba(204, 204, 204, 0.175295); + + &-checkbox{ + width: 100%; + } + + &__contents{ + width: 100%; + display: flex; + align-items: center; + justify-content: center; + + &-icon{ + + } + + &-text { + flex: 1; + display: flex; + flex-direction: column; + align-items: flex-start; + justify-content: center; + + p { + margin: 0px; + padding: 0px; + } + + &-title{ + font-size: 15px; + line-height: 18px; + color: #1C5CBA; + } + + &-subtitle { + font-weight: 300; + font-size: 13px; + line-height: 18px; + color: #343434; + } + } + + &-help { + + } + } } \ No newline at end of file From 8a7d2e568d40257821527835e9a50d660acf50b0 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Thu, 24 Nov 2022 17:37:17 +0530 Subject: [PATCH 04/49] Added Styling --- .../CheckboxTemplate/CheckboxItem/index.js | 59 ++++++++++++------- .../CheckboxItem/stylesheet.scss | 47 ++++++++++----- 2 files changed, 70 insertions(+), 36 deletions(-) diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js index e25e6ec77..2449d37ef 100644 --- a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js @@ -1,3 +1,4 @@ +import { useState } from '@wordpress/element'; import { Icon, help, search } from '@wordpress/icons'; import { CheckboxControl } from '@wordpress/components'; @@ -16,33 +17,47 @@ import { CheckboxControl } from '@wordpress/components'; const CheckboxItem = ({ icon, title, subtitle, desc }) => { + const [showDescription, setShowDescription] = useState(false); + + const handleShowDesc = () => { + setShowDescription(!showDescription); + }; + return ( -
+
-
- -
-
-

{title}

-

{subtitle}

-
-
- + <> +
+
+ +
+
+
{title}
+
{subtitle}
+
+
+ +
-
+ {showDescription &&
{desc}
} + }/>
); diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss index 197b4dcbd..a987a0fb6 100644 --- a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss @@ -1,13 +1,10 @@ .checkbox-item { - width: 20vw; + width: 25vw; margin: 10px; padding: 10px; - display: flex; min-width: 300px; border-radius: 2px; - align-items: center; border: 1px solid #97C8FA; - justify-content: flex-start; background: rgba(132, 192, 252, 0.2); box-shadow: 0px 2px 8px 2px rgba(204, 204, 204, 0.175295); @@ -22,7 +19,18 @@ justify-content: center; &-icon{ + width: 45px; + height: 45px; + margin: 16px; + display: flex; + border-radius: 50%; + align-items: center; + background: #1C5CBA; + justify-content: center; + &--active { + background: #F0F0F0; + } } &-text { @@ -32,27 +40,38 @@ align-items: flex-start; justify-content: center; - p { - margin: 0px; - padding: 0px; - } - &-title{ - font-size: 15px; - line-height: 18px; + font-size: 16px; color: #1C5CBA; + line-height: 18px; + margin-bottom: 6px; } &-subtitle { - font-weight: 300; - font-size: 13px; + font-size: 14px; + font-weight: 200; line-height: 18px; color: #343434; } } &-help { - } + + } + + &--active { + z-index: 9999; + position: absolute; + transform: translateX(0%); + border-radius: 2px; + background: #E2E9F4; + border: 1px solid #CADFE7; + box-shadow: 0px 11px 8px -3px rgba(88, 124, 175, 0.37); + } + + &__desc { + font-size: 14px; + font-style: italic; } } \ No newline at end of file From 69ea17c6759f8813b727844f3749b6e13b84cc34 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Thu, 24 Nov 2022 18:12:14 +0530 Subject: [PATCH 05/49] Fixed Checkbox Behaviour --- .../CheckboxTemplate/CheckboxItem/index.js | 75 ++++++++++--------- .../CheckboxItem/stylesheet.scss | 22 ++++-- 2 files changed, 55 insertions(+), 42 deletions(-) diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js index 2449d37ef..a72cb237e 100644 --- a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js @@ -15,50 +15,55 @@ import { CheckboxControl } from '@wordpress/components'; * @returns CheckboxItem */ -const CheckboxItem = ({ icon, title, subtitle, desc }) => { +const CheckboxItem = ({ key, icon, title, subtitle, desc, callback }) => { + const [isSelected, setIsSelected] = useState(false); const [showDescription, setShowDescription] = useState(false); + const handleCheck = () => { + setIsSelected(!isSelected); + }; + const handleShowDesc = () => { setShowDescription(!showDescription); }; return (
- -
-
- -
-
-
{title}
-
{subtitle}
-
-
- -
-
- {showDescription &&
{desc}
} - - }/> +
+ +
+
+ +
+
+
{title}
+
{subtitle}
+
+
+ +
+
+
+ {showDescription &&
{desc}
}
); }; diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss index a987a0fb6..6658d3920 100644 --- a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss @@ -1,15 +1,24 @@ .checkbox-item { - width: 25vw; - margin: 10px; - padding: 10px; + width: 23vw; + margin: 12px; + padding: 16px; min-width: 300px; border-radius: 2px; border: 1px solid #97C8FA; background: rgba(132, 192, 252, 0.2); box-shadow: 0px 2px 8px 2px rgba(204, 204, 204, 0.175295); + &-container{ + display: flex; + align-items: center; + justify-content: flex-start; + } + &-checkbox{ - width: 100%; + padding: 6px; + display: flex; + align-items: center; + justify-content: center; } &__contents{ @@ -21,8 +30,8 @@ &-icon{ width: 45px; height: 45px; - margin: 16px; display: flex; + margin-right: 16px; border-radius: 50%; align-items: center; background: #1C5CBA; @@ -62,8 +71,6 @@ &--active { z-index: 9999; - position: absolute; - transform: translateX(0%); border-radius: 2px; background: #E2E9F4; border: 1px solid #CADFE7; @@ -72,6 +79,7 @@ &__desc { font-size: 14px; + margin-top: 20px; font-style: italic; } } \ No newline at end of file From aa0d00e91963840fcbb319331d1f1dfcbe73fd5e Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Thu, 24 Nov 2022 19:03:46 +0530 Subject: [PATCH 06/49] Added an API to fetch the Plugins --- includes/Data/SiteFeatures.php | 93 +++++++++++++++++++ includes/RestApi/RestApi.php | 1 + includes/RestApi/SiteFeaturesController.php | 54 +++++++++++ .../CheckboxTemplate/CheckboxList/index.js | 10 +- .../pages/Steps/SiteFeatures/index.js | 85 ++++------------- src/OnboardingSPA/utils/api/plugins.js | 8 ++ 6 files changed, 181 insertions(+), 70 deletions(-) create mode 100644 includes/Data/SiteFeatures.php create mode 100644 includes/RestApi/SiteFeaturesController.php diff --git a/includes/Data/SiteFeatures.php b/includes/Data/SiteFeatures.php new file mode 100644 index 000000000..4b6479f26 --- /dev/null +++ b/includes/Data/SiteFeatures.php @@ -0,0 +1,93 @@ + '1', + 'icon' => 'icon-name', + 'title' => 'Security, Speed & Growth', + 'subtitle' => 'Powered by Jetpack', + 'desc' => 'Jetpack', + ), + array( + 'slug' => '2', + 'icon' => 'icon-name', + 'title' => 'Forms', + 'subtitle' => 'Powered by WP Forms', + 'desc' => 'WP Forms', + ), + array( + 'slug' => '3', + 'icon' => 'icon-name', + 'title' => 'Site Traffic', + 'subtitle' => 'Powered by MonsterInsights', + 'desc' => 'MonsterInsights', + ), + array( + 'slug' => '4', + 'icon' => 'icon-name', + 'title' => 'Search Engine Optimization', + 'subtitle' => 'Powered by Yoast', + 'desc' => 'Yoast', + ), + array( + 'slug' => '5', + 'icon' => 'icon-name', + 'title' => 'Email Newsletters', + 'subtitle' => 'Powered by Creative Email', + 'desc' => 'Creative Email', + ), + array( + 'slug' => '6', + 'icon' => 'icon-name', + 'title' => 'Enhanced Product Search', + 'subtitle' => 'Powered by YITH', + 'desc' => 'YITH', + ), + array( + 'slug' => '7', + 'icon' => 'icon-name', + 'title' => 'Enhanced Product Filters', + 'subtitle' => 'Powered by YITH', + 'desc' => 'YITH', + ), + array( + 'slug' => '8', + 'icon' => 'icon-name', + 'title' => 'Bookings & Appointments', + 'subtitle' => 'Powered by YITH', + 'desc' => 'YITH', + ), + array( + 'slug' => '9', + 'icon' => 'icon-name', + 'title' => 'Product Wishlists', + 'subtitle' => 'Powered by YITH', + 'desc' => 'YITH', + ), + array( + 'slug' => '10', + 'icon' => 'icon-name', + 'title' => 'Lead Generation', + 'subtitle' => 'Powered by Optin Monster', + 'desc' => 'Optin Monster', + ), + ); + + + + public static function get_default_plugins_list() { + return self::$default_plugins; + } + + public static function get_custom_plugins_list() { + + return self::get_default_plugins_list(); + } + +} diff --git a/includes/RestApi/RestApi.php b/includes/RestApi/RestApi.php index d01fb545f..1b4791712 100644 --- a/includes/RestApi/RestApi.php +++ b/includes/RestApi/RestApi.php @@ -18,6 +18,7 @@ final class RestApi { 'NewfoldLabs\\WP\\Module\\Onboarding\\RestApi\\SettingsController', 'NewfoldLabs\\WP\\Module\\Onboarding\\RestApi\\EventsController', 'NewfoldLabs\\WP\\Module\\Onboarding\\RestApi\\PagesController', + 'NewfoldLabs\WP\\Module\\Onboarding\\RestApi\\SiteFeaturesController', 'NewfoldLabs\WP\\Module\\Onboarding\\RestApi\\Themes\\ThemeInstallerController', 'NewfoldLabs\WP\\Module\\Onboarding\\RestApi\\Themes\\ThemeFontsController', 'NewfoldLabs\WP\\Module\\Onboarding\\RestApi\\Themes\\ThemeColorsController' diff --git a/includes/RestApi/SiteFeaturesController.php b/includes/RestApi/SiteFeaturesController.php new file mode 100644 index 000000000..c5c48508a --- /dev/null +++ b/includes/RestApi/SiteFeaturesController.php @@ -0,0 +1,54 @@ +namespace, + $this->rest_base, + array( + array( + 'methods' => \WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_custom_plugins' ), + 'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), + ), + ) + ); + } + + /** + * Retrieves the Customized list of Plugins for the user. + * + * @return array|\WP_Error + */ + public function get_custom_plugins() { + $custom_plugins = SiteFeatures::get_custom_plugins_list(); + return $custom_plugins; + } +} diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/index.js b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/index.js index 39042a5f2..7f62039f6 100644 --- a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/index.js +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/index.js @@ -5,14 +5,14 @@ import { CheckboxItem } from "../index"; * Checkbox List Component * This returns a List of Checkbox Items to be placed dynamically on screen * - * @param {Object} data - The List to be shown with a Title, Subtitle and a Description + * @param {Object} customPluginsList - The List to be shown with a Title, Subtitle and a Description * * @returns CheckboxList */ -const CheckboxList = ({ data }) => { +const CheckboxList = ({ customPluginsList }) => { const buildCheckboxItems = () => { - return data.map((item, idx) => { + return customPluginsList.map((item, idx) => { return ( { return (
- {buildCheckboxItems().slice(0, Math.floor(data.length/2))} + {buildCheckboxItems().slice(0, Math.floor(customPluginsList.length/2))}
- {buildCheckboxItems().slice(Math.floor(data.length / 2), data.length)} + {buildCheckboxItems().slice(Math.floor(customPluginsList.length / 2), customPluginsList.length)}
); diff --git a/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js b/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js index bdb9c9823..d991ffe2f 100644 --- a/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js +++ b/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js @@ -1,15 +1,20 @@ -import { useEffect } from '@wordpress/element'; import { useViewportMatch } from '@wordpress/compose'; +import { useEffect, useState } from '@wordpress/element'; import { useSelect, useDispatch } from '@wordpress/data'; import { store as nfdOnboardingStore } from '../../../store'; import { VIEW_NAV_PRIMARY } from '../../../../constants'; import CommonLayout from '../../../components/Layouts/Common'; +import { getCustomPluginsList } from '../../../utils/api/plugins'; import HeadingWithSubHeading from '../../../components/HeadingWithSubHeading'; import CheckboxList from '../../../components/CheckboxTemplate/CheckboxList'; const StepSiteFeatures = () => { const isLargeViewport = useViewportMatch('medium'); + + const [isLoaded, setisLoaded] = useState(false); + const [customPluginsList, setCustomPluginsList] = useState(); + const { setIsDrawerOpened, setDrawerActiveView, setIsSidebarOpened, setIsDrawerSuppressed } = useDispatch(nfdOnboardingStore); @@ -22,6 +27,19 @@ const StepSiteFeatures = () => { [] ); + async function getCustomPlugins() { + const customPluginsList = await getCustomPluginsList(); + setCustomPluginsList(customPluginsList.body); + + setisLoaded(true); + } + + useEffect(() => { + if (!isLoaded) { + getCustomPlugins(); + } + }, [isLoaded]); + useEffect(() => { if (isLargeViewport) { setIsDrawerOpened(false); @@ -31,73 +49,10 @@ const StepSiteFeatures = () => { setDrawerActiveView(VIEW_NAV_PRIMARY); }, []); - const data = [ - { - 'icon': 'icon-name', - 'title': 'Security, Speed & Growth', - 'subtitle': 'Powered by Jetpack', - 'desc': 'Jetpack' - }, - { - 'icon': 'icon-name', - 'title': 'Forms', - 'subtitle': 'Powered by WP Forms', - 'desc': 'WP Forms' - }, - { - 'icon': 'icon-name', - 'title': 'Site Traffic', - 'subtitle': 'Powered by MonsterInsights', - 'desc': 'MonsterInsights' - }, - { - 'icon': 'icon-name', - 'title': 'Search Engine Optimization', - 'subtitle': 'Powered by Yoast', - 'desc': 'Yoast' - }, - { - 'icon': 'icon-name', - 'title': 'Email Newsletters', - 'subtitle': 'Powered by Creative Email', - 'desc': 'Creative Email' - }, - { - 'icon': 'icon-name', - 'title': 'Enhanced Product Search', - 'subtitle': 'Powered by YITH', - 'desc': 'YITH' - }, - { - 'icon': 'icon-name', - 'title': 'Enhanced Product Filters', - 'subtitle': 'Powered by YITH', - 'desc': 'YITH' - }, - { - 'icon': 'icon-name', - 'title': 'Bookings & Appointments', - 'subtitle': 'Powered by YITH', - 'desc': 'YITH' - }, - { - 'icon': 'icon-name', - 'title': 'Product Wishlists', - 'subtitle': 'Powered by YITH', - 'desc': 'YITH' - }, - { - 'icon': 'icon-name', - 'title': 'Lead Generation', - 'subtitle': 'Powered by Optin Monster', - 'desc': 'Optin Monster' - } - ] - return ( - + { customPluginsList && } ); }; diff --git a/src/OnboardingSPA/utils/api/plugins.js b/src/OnboardingSPA/utils/api/plugins.js index af7b8b8e8..d4d9c11f9 100644 --- a/src/OnboardingSPA/utils/api/plugins.js +++ b/src/OnboardingSPA/utils/api/plugins.js @@ -30,3 +30,11 @@ export const getPluginStatus = async ( plugin ) => { } ) ); }; + +export const getCustomPluginsList = async () => { + return await resolve( + apiFetch({ + url: onboardingRestURL('features'), + }) + ); +}; From 4a475f42ce49284877332ade9a525e0b9f7b7542 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Thu, 24 Nov 2022 19:09:05 +0530 Subject: [PATCH 07/49] Added some styling --- .../CheckboxTemplate/CheckboxItem/index.js | 4 ++-- .../CheckboxTemplate/CheckboxItem/stylesheet.scss | 14 ++++++++++---- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js index a72cb237e..15b3c93dc 100644 --- a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js @@ -29,14 +29,14 @@ const CheckboxItem = ({ key, icon, title, subtitle, desc, callback }) => { }; return ( -
+
-
+
Date: Fri, 25 Nov 2022 12:49:23 +0530 Subject: [PATCH 08/49] Added support to be checked and unchecked --- includes/Data/SiteFeatures.php | 10 +++++++ .../CheckboxTemplate/CheckboxItem/index.js | 5 ++-- .../CheckboxTemplate/CheckboxList/index.js | 8 ++++-- .../pages/Steps/SiteFeatures/index.js | 27 +++++++++++++++++-- 4 files changed, 44 insertions(+), 6 deletions(-) diff --git a/includes/Data/SiteFeatures.php b/includes/Data/SiteFeatures.php index 4b6479f26..fcf45ea0a 100644 --- a/includes/Data/SiteFeatures.php +++ b/includes/Data/SiteFeatures.php @@ -13,6 +13,7 @@ final class SiteFeatures { 'title' => 'Security, Speed & Growth', 'subtitle' => 'Powered by Jetpack', 'desc' => 'Jetpack', + 'selected' => false, ), array( 'slug' => '2', @@ -20,6 +21,7 @@ final class SiteFeatures { 'title' => 'Forms', 'subtitle' => 'Powered by WP Forms', 'desc' => 'WP Forms', + 'selected' => true, ), array( 'slug' => '3', @@ -27,6 +29,7 @@ final class SiteFeatures { 'title' => 'Site Traffic', 'subtitle' => 'Powered by MonsterInsights', 'desc' => 'MonsterInsights', + 'selected' => true, ), array( 'slug' => '4', @@ -34,6 +37,7 @@ final class SiteFeatures { 'title' => 'Search Engine Optimization', 'subtitle' => 'Powered by Yoast', 'desc' => 'Yoast', + 'selected' => false, ), array( 'slug' => '5', @@ -41,6 +45,7 @@ final class SiteFeatures { 'title' => 'Email Newsletters', 'subtitle' => 'Powered by Creative Email', 'desc' => 'Creative Email', + 'selected' => false, ), array( 'slug' => '6', @@ -48,6 +53,7 @@ final class SiteFeatures { 'title' => 'Enhanced Product Search', 'subtitle' => 'Powered by YITH', 'desc' => 'YITH', + 'selected' => true, ), array( 'slug' => '7', @@ -55,6 +61,7 @@ final class SiteFeatures { 'title' => 'Enhanced Product Filters', 'subtitle' => 'Powered by YITH', 'desc' => 'YITH', + 'selected' => true, ), array( 'slug' => '8', @@ -62,6 +69,7 @@ final class SiteFeatures { 'title' => 'Bookings & Appointments', 'subtitle' => 'Powered by YITH', 'desc' => 'YITH', + 'selected' => false, ), array( 'slug' => '9', @@ -69,6 +77,7 @@ final class SiteFeatures { 'title' => 'Product Wishlists', 'subtitle' => 'Powered by YITH', 'desc' => 'YITH', + 'selected' => false, ), array( 'slug' => '10', @@ -76,6 +85,7 @@ final class SiteFeatures { 'title' => 'Lead Generation', 'subtitle' => 'Powered by Optin Monster', 'desc' => 'Optin Monster', + 'selected' => true, ), ); diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js index 15b3c93dc..62a8d44be 100644 --- a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js @@ -15,13 +15,14 @@ import { CheckboxControl } from '@wordpress/components'; * @returns CheckboxItem */ -const CheckboxItem = ({ key, icon, title, subtitle, desc, callback }) => { +const CheckboxItem = ({ slug, icon, title, subtitle, desc, isSelectedDefault, callback }) => { - const [isSelected, setIsSelected] = useState(false); const [showDescription, setShowDescription] = useState(false); + const [isSelected, setIsSelected] = useState(isSelectedDefault); const handleCheck = () => { setIsSelected(!isSelected); + callback(slug, !isSelected); }; const handleShowDesc = () => { diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/index.js b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/index.js index 7f62039f6..e3141fc66 100644 --- a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/index.js +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/index.js @@ -9,16 +9,20 @@ import { CheckboxItem } from "../index"; * * @returns CheckboxList */ -const CheckboxList = ({ customPluginsList }) => { +const CheckboxList = ({ callback, selectedPlugins, customPluginsList }) => { const buildCheckboxItems = () => { return customPluginsList.map((item, idx) => { + let isSelectedDefault = selectedPlugins[item.slug]; return ( + desc={item.desc} + callback={callback} + isSelectedDefault={isSelectedDefault ?? false} /> ) }); } diff --git a/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js b/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js index d991ffe2f..bb9deb931 100644 --- a/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js +++ b/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js @@ -13,6 +13,7 @@ const StepSiteFeatures = () => { const isLargeViewport = useViewportMatch('medium'); const [isLoaded, setisLoaded] = useState(false); + const [selectedPlugins, setSelectedPlugins] = useState(); const [customPluginsList, setCustomPluginsList] = useState(); const { setIsDrawerOpened, setDrawerActiveView, setIsSidebarOpened, setIsDrawerSuppressed } = @@ -27,10 +28,28 @@ const StepSiteFeatures = () => { [] ); + async function selectPlugin(slug, choice) { + let selectedPluginsCopy = {...selectedPlugins}; + if(choice) + selectedPluginsCopy[slug] = 1; + else + delete selectedPluginsCopy[slug]; + setSelectedPlugins(selectedPluginsCopy); + } + + async function changeToStoreSchema( customPluginsList ) { + let selectedPlugins = {}; + customPluginsList.forEach(plugin => { + if (plugin.selected === true) + selectedPlugins[plugin.slug] = 1; + }); + setSelectedPlugins(selectedPlugins); + } + async function getCustomPlugins() { const customPluginsList = await getCustomPluginsList(); + changeToStoreSchema(customPluginsList.body); setCustomPluginsList(customPluginsList.body); - setisLoaded(true); } @@ -52,7 +71,11 @@ const StepSiteFeatures = () => { return ( - { customPluginsList && } + {customPluginsList && + } ); }; From 45dbbd545b13b8d92fa3ff5ff1960845dee69d07 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Fri, 25 Nov 2022 13:15:30 +0530 Subject: [PATCH 09/49] Added saving to Store --- .../pages/Steps/SiteFeatures/index.js | 25 +++++++++++++++---- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js b/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js index bb9deb931..c20b902a2 100644 --- a/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js +++ b/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js @@ -1,3 +1,4 @@ +import { isEmpty } from 'lodash'; import { useViewportMatch } from '@wordpress/compose'; import { useEffect, useState } from '@wordpress/element'; import { useSelect, useDispatch } from '@wordpress/data'; @@ -16,13 +17,14 @@ const StepSiteFeatures = () => { const [selectedPlugins, setSelectedPlugins] = useState(); const [customPluginsList, setCustomPluginsList] = useState(); - const { setIsDrawerOpened, setDrawerActiveView, setIsSidebarOpened, setIsDrawerSuppressed } = + const { setIsDrawerOpened, setDrawerActiveView, setIsSidebarOpened, setCurrentOnboardingData, setIsDrawerSuppressed } = useDispatch(nfdOnboardingStore); - const { currentStep } = useSelect( + const { currentStep, currentData } = useSelect( (select) => { return { - currentStep: select(nfdOnboardingStore).getCurrentStep() + currentStep: select(nfdOnboardingStore).getCurrentStep(), + currentData: select(nfdOnboardingStore).getCurrentOnboardingData(), }; }, [] @@ -34,21 +36,34 @@ const StepSiteFeatures = () => { selectedPluginsCopy[slug] = 1; else delete selectedPluginsCopy[slug]; + + currentData.data.siteFeatures = {...selectedPluginsCopy}; + setCurrentOnboardingData(currentData); setSelectedPlugins(selectedPluginsCopy); } - async function changeToStoreSchema( customPluginsList ) { + async function changeToStoreSchema( customPluginsList, saveToStore = false ) { let selectedPlugins = {}; + customPluginsList.forEach(plugin => { if (plugin.selected === true) selectedPlugins[plugin.slug] = 1; }); setSelectedPlugins(selectedPlugins); + + if (saveToStore) { + currentData.data.siteFeatures = { ...selectedPlugins }; + setCurrentOnboardingData(currentData); + } } async function getCustomPlugins() { const customPluginsList = await getCustomPluginsList(); - changeToStoreSchema(customPluginsList.body); + if (isEmpty(currentData?.data?.siteFeatures)) + changeToStoreSchema(customPluginsList.body, true); + else + setSelectedPlugins({ ...currentData?.data?.siteFeatures }); + setCustomPluginsList(customPluginsList.body); setisLoaded(true); } From 4e238a9944212ab9793dc4f3bee33f52ea24dc82 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Fri, 25 Nov 2022 18:41:32 +0530 Subject: [PATCH 10/49] Refactored Code --- .../CheckboxTemplate/CheckboxItem/stylesheet.scss | 1 + src/OnboardingSPA/pages/Steps/SiteFeatures/index.js | 7 +++---- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss index 0b1ae5d87..5777b5420 100644 --- a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss @@ -65,6 +65,7 @@ } &-help { + cursor: pointer; } } diff --git a/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js b/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js index c20b902a2..b618ffd41 100644 --- a/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js +++ b/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js @@ -33,9 +33,9 @@ const StepSiteFeatures = () => { async function selectPlugin(slug, choice) { let selectedPluginsCopy = {...selectedPlugins}; if(choice) - selectedPluginsCopy[slug] = 1; + selectedPluginsCopy[slug] = true; else - delete selectedPluginsCopy[slug]; + selectedPluginsCopy[slug] = false; currentData.data.siteFeatures = {...selectedPluginsCopy}; setCurrentOnboardingData(currentData); @@ -46,8 +46,7 @@ const StepSiteFeatures = () => { let selectedPlugins = {}; customPluginsList.forEach(plugin => { - if (plugin.selected === true) - selectedPlugins[plugin.slug] = 1; + selectedPlugins[plugin.slug] = plugin.selected; }); setSelectedPlugins(selectedPlugins); From 34ac04eaa5f1e4043a62e81c5605657e9108745a Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Mon, 28 Nov 2022 18:14:18 +0530 Subject: [PATCH 11/49] Added some Boiler Plate Code --- includes/Data/Options.php | 2 + includes/Services/PluginUninstaller.php | 87 +++++++++ .../PluginUninstallTaskManager.php | 169 ++++++++++++++++++ includes/Tasks/PluginUnistallTask.php | 62 +++++++ 4 files changed, 320 insertions(+) create mode 100644 includes/Services/PluginUninstaller.php create mode 100644 includes/TaskManagers/PluginUninstallTaskManager.php create mode 100644 includes/Tasks/PluginUnistallTask.php diff --git a/includes/Data/Options.php b/includes/Data/Options.php index b216e7f1b..d70e10d6a 100644 --- a/includes/Data/Options.php +++ b/includes/Data/Options.php @@ -30,6 +30,8 @@ final class Options { 'settings_initialized' => 'settings_initialized', 'plugins_init_status' => 'plugins_init_status', 'plugin_install_queue' => 'plugin_install_queue', + 'plugins_un_init_status' => 'plugins_un_init_status', + 'plugin_uninstall_queue' => 'plugin_uninstall_queue', 'flow' => 'flow', 'theme_init_status' => 'theme_init_status', 'theme_install_queue' => 'theme_install_queue', diff --git a/includes/Services/PluginUninstaller.php b/includes/Services/PluginUninstaller.php new file mode 100644 index 000000000..166cd3c02 --- /dev/null +++ b/includes/Services/PluginUninstaller.php @@ -0,0 +1,87 @@ + 30, + 'display' => __( 'Once Every Thirty Seconds' ), + ); + } + + return $schedules; + } + + public static function queue_initial_uninstalls( $un_init_plugins ) { + + // Checks if the init_list of plugins have already been queued. + if ( \get_option( Options::get_option_name( 'plugins_un_init_status' ), 'init' ) !== 'init' ) { + return true; + } + + // Set option to uninstalling to prevent re-queueing the uninstall init_list again on page load. + \update_option( Options::get_option_name( 'plugins_un_init_status' ), 'uninstalling' ); + + // Get the initial list of plugins to be uninstalled based on the plan. + + + foreach ( $un_init_plugins as $un_init_plugin ) { + // Checks if a plugin with the given slug and activation criteria already exists. + if ( ! PluginUninstaller::exists( $un_init_plugin['slug'] ) ) { + // Add a new PluginUninstallTask to the Plugin uninstall queue. + self::add_to_queue( + new PluginUninstallTask( + $un_init_plugin['slug'], + $un_init_plugin['priority'] + ) + ); + } + } + + return true; + } + + /** + * Queue out a PluginUninstallTask with the highest priority in the plugin uninstall queue and execute it. + * + * @return array|false + */ + public function uninstall() { + /* + Get the plugins queued up to be installed, the PluginInstall task gets + converted to an associative array before storing it in the option. */ + $plugins = \get_option( Options::get_option_name( self::$queue_name ), array() ); + + /* + Conversion of the max heap to an array will always place the PluginUninstallTask with the highest + priority at the beginning of the array */ + $plugin_to_uninstall = array_shift( $plugins ); + + // Recreate the PluginInstall task from the associative array. + $plugin_uninstall_task = new PluginUninstallTask( + $plugin_to_uninstall['slug'], + $plugin_to_uninstall['priority'], + $plugin_to_uninstall['retries'] + ); + + // Update status to the current slug being installed. + \update_option( Options::get_option_name( 'plugins_un_init_status' ), $plugin_uninstall_task->get_slug() ); + + // Execute the PluginUninstall Task. + $status = $plugin_uninstall_task->execute(); + if ( \is_wp_error( $status ) ) { + + // If there is an error, then increase the retry count for the task. + $plugin_uninstall_task->increment_retries(); + + /* + If the number of retries have not exceeded the limit + then re-queue the task at the end of the queue to be retried. */ + if ( $plugin_uninstall_task->get_retries() <= self::$retry_limit ) { + array_push( $plugins, $plugin_uninstall_task->to_array() ); + } + } + + // If there are no more plugins to be installed then change the status to completed. + if ( empty( $plugins ) ) { + \update_option( Options::get_option_name( 'plugins_un_init_status' ), 'completed' ); + } + + // Update the plugin uninstall queue. + return \update_option( Options::get_option_name( self::$queue_name ), $plugins ); + } + + /** + * @param PluginUninstallTask $plugin_uninstall_task + * + * Adds a new PluginUninstallTask to the Plugin Uninstall queue. + * The Task will be inserted at an appropriate position in the queue based on it's priority. + * + * @return array|false + */ + public static function add_to_queue( PluginUninstallTask $plugin_uninstall_task ) { + /* + Get the plugins queued up to be installed, the PluginInstall task gets + converted to an associative array before storing it in the option. */ + $plugins = \get_option( Options::get_option_name( self::$queue_name ), array() ); + + $queue = new PriorityQueue(); + foreach ( $plugins as $queued_plugin ) { + + /* + Check if there is an already existing PluginUninstallTask in the queue + for a given slug and activation criteria. */ + if ( $queued_plugin['slug'] === $plugin_uninstall_task->get_slug() ) { + return false; + } + $queue->insert( $queued_plugin, $queued_plugin['priority'] ); + } + + // Insert a new PluginUninstallTask at the appropriate position in the queue. + $queue->insert( + $plugin_uninstall_task->to_array(), + $plugin_uninstall_task->get_priority() + ); + + return \update_option( Options::get_option_name( self::$queue_name ), $queue->to_array() ); + } + + public static function status( $plugin ) { + $plugins = \get_option( Options::get_option_name( self::$queue_name ), array() ); + return array_search( $plugin, array_column( $plugins, 'slug' ) ); + } +} diff --git a/includes/Tasks/PluginUnistallTask.php b/includes/Tasks/PluginUnistallTask.php new file mode 100644 index 000000000..a2db68fac --- /dev/null +++ b/includes/Tasks/PluginUnistallTask.php @@ -0,0 +1,62 @@ +slug = $slug; + $this->priority = $priority; + $this->retries = $retries; + } + + public function get_slug() { + return $this->slug; + } + + public function get_priority() { + return $this->priority; + } + + public function get_retries() { + return $this->retries; + } + + public function increment_retries() { + $this->retries++; + } + + /** + * Installs the Plugin using the PluginUninstaller Service. + * + * @return \WP_REST_Response|WP_Error + */ + public function execute() { + return PluginUninstaller::uninstall( $this->get_slug() ); + } + + /** + * Convert the PluginUninstallTask into an associative array. + * + * @return array + */ + public function to_array() { + return array( + 'slug' => $this->slug, + 'priority' => $this->priority, + 'retries' => $this->retries, + ); + } + +} From e2150b96d3a894a6299c103f3b45ae4e75f46e44 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Mon, 28 Nov 2022 18:17:20 +0530 Subject: [PATCH 12/49] Changed Option name --- includes/Data/Options.php | 2 +- includes/TaskManagers/PluginUninstallTaskManager.php | 8 ++++---- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/includes/Data/Options.php b/includes/Data/Options.php index d70e10d6a..707e39cf7 100644 --- a/includes/Data/Options.php +++ b/includes/Data/Options.php @@ -30,7 +30,7 @@ final class Options { 'settings_initialized' => 'settings_initialized', 'plugins_init_status' => 'plugins_init_status', 'plugin_install_queue' => 'plugin_install_queue', - 'plugins_un_init_status' => 'plugins_un_init_status', + 'plugins_uninit_status' => 'plugins_uninit_status', 'plugin_uninstall_queue' => 'plugin_uninstall_queue', 'flow' => 'flow', 'theme_init_status' => 'theme_init_status', diff --git a/includes/TaskManagers/PluginUninstallTaskManager.php b/includes/TaskManagers/PluginUninstallTaskManager.php index 85021b538..6fc3d46a8 100644 --- a/includes/TaskManagers/PluginUninstallTaskManager.php +++ b/includes/TaskManagers/PluginUninstallTaskManager.php @@ -51,12 +51,12 @@ public function add_thirty_seconds_schedule( $schedules ) { public static function queue_initial_uninstalls( $un_init_plugins ) { // Checks if the init_list of plugins have already been queued. - if ( \get_option( Options::get_option_name( 'plugins_un_init_status' ), 'init' ) !== 'init' ) { + if ( \get_option( Options::get_option_name( 'plugins_uninit_status' ), 'init' ) !== 'init' ) { return true; } // Set option to uninstalling to prevent re-queueing the uninstall init_list again on page load. - \update_option( Options::get_option_name( 'plugins_un_init_status' ), 'uninstalling' ); + \update_option( Options::get_option_name( 'plugins_uninit_status' ), 'uninstalling' ); // Get the initial list of plugins to be uninstalled based on the plan. @@ -101,7 +101,7 @@ public function uninstall() { ); // Update status to the current slug being installed. - \update_option( Options::get_option_name( 'plugins_un_init_status' ), $plugin_uninstall_task->get_slug() ); + \update_option( Options::get_option_name( 'plugins_uninit_status' ), $plugin_uninstall_task->get_slug() ); // Execute the PluginUninstall Task. $status = $plugin_uninstall_task->execute(); @@ -120,7 +120,7 @@ public function uninstall() { // If there are no more plugins to be installed then change the status to completed. if ( empty( $plugins ) ) { - \update_option( Options::get_option_name( 'plugins_un_init_status' ), 'completed' ); + \update_option( Options::get_option_name( 'plugins_uninit_status' ), 'completed' ); } // Update the plugin uninstall queue. From 5ef49e0a96d71cb551b3344ab0df0c69bbe836f4 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Tue, 29 Nov 2022 09:55:05 +0530 Subject: [PATCH 13/49] Minor Refactoring --- includes/RestApi/PluginsController.php | 26 +++++++++++++++++++ includes/Services/PluginUninstaller.php | 4 +-- .../PluginUninstallTaskManager.php | 16 +++++------- includes/Tasks/PluginUnistallTask.php | 2 +- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/includes/RestApi/PluginsController.php b/includes/RestApi/PluginsController.php index b2a9197f3..0ebc69c33 100644 --- a/includes/RestApi/PluginsController.php +++ b/includes/RestApi/PluginsController.php @@ -5,6 +5,7 @@ use NewfoldLabs\WP\Module\Onboarding\Data\Plugins; use NewfoldLabs\WP\Module\Onboarding\Data\Options; use NewfoldLabs\WP\Module\Onboarding\Services\PluginInstaller; +use NewfoldLabs\WP\Module\Onboarding\Services\PluginUninstaller; use NewfoldLabs\WP\Module\Onboarding\Tasks\PluginInstallTask; use NewfoldLabs\WP\Module\Onboarding\TaskManagers\PluginInstallTaskManager; @@ -78,6 +79,18 @@ public function register_routes() { ), ) ); + + \register_rest_route( + $this->namespace, + $this->rest_base . '/uninstall', + array( + array( + 'methods' => \WP_REST_Server::READABLE, + 'callback' => array( $this, 'uninstall' ), + 'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), + ), + ) + ); } /** @@ -172,6 +185,18 @@ public function initialize() { * * @return \WP_REST_Response|\WP_Error */ + public function uninstall( \WP_REST_Request $request ) { + + return PluginUninstaller::uninstall('woocomerce'); + } + + /** + * Uninstalls the requested plugin. + * + * @param \WP_REST_Request $request + * + * @return \WP_REST_Response|\WP_Error + */ public function install( \WP_REST_Request $request ) { $plugin = $request->get_param( 'plugin' ); $activate = $request->get_param( 'activate' ); @@ -209,6 +234,7 @@ public function install( \WP_REST_Request $request ) { return $plugin_install_task->execute(); } + public function get_status( \WP_REST_Request $request ) { $plugin = $request->get_param( 'plugin' ); $activated = $request->get_param( 'activated' ); diff --git a/includes/Services/PluginUninstaller.php b/includes/Services/PluginUninstaller.php index 166cd3c02..31a641de0 100644 --- a/includes/Services/PluginUninstaller.php +++ b/includes/Services/PluginUninstaller.php @@ -14,10 +14,10 @@ public static function uninstall( $plugin ) { // if ( $activate && ! \is_plugin_active( $plugin_path ) ) { // return false; // } - + $installed_plugins = \get_plugins(); return new \WP_REST_Response( - array(), + $installed_plugins, 201 ); } diff --git a/includes/TaskManagers/PluginUninstallTaskManager.php b/includes/TaskManagers/PluginUninstallTaskManager.php index 6fc3d46a8..48e44fc27 100644 --- a/includes/TaskManagers/PluginUninstallTaskManager.php +++ b/includes/TaskManagers/PluginUninstallTaskManager.php @@ -48,27 +48,25 @@ public function add_thirty_seconds_schedule( $schedules ) { return $schedules; } - public static function queue_initial_uninstalls( $un_init_plugins ) { + public static function queue_initial_uninstalls( $uninit_plugins ) { - // Checks if the init_list of plugins have already been queued. + // Checks if the uninit_list of plugins have already been queued. if ( \get_option( Options::get_option_name( 'plugins_uninit_status' ), 'init' ) !== 'init' ) { return true; } - // Set option to uninstalling to prevent re-queueing the uninstall init_list again on page load. + // Set option to uninstalling to prevent re-queueing the uninstall on page load. \update_option( Options::get_option_name( 'plugins_uninit_status' ), 'uninstalling' ); - // Get the initial list of plugins to be uninstalled based on the plan. - - foreach ( $un_init_plugins as $un_init_plugin ) { + foreach ( $uninit_plugins as $uninit_plugin ) { // Checks if a plugin with the given slug and activation criteria already exists. - if ( ! PluginUninstaller::exists( $un_init_plugin['slug'] ) ) { + if ( ! PluginUninstaller::exists( $uninit_plugin['slug'] ) ) { // Add a new PluginUninstallTask to the Plugin uninstall queue. self::add_to_queue( new PluginUninstallTask( - $un_init_plugin['slug'], - $un_init_plugin['priority'] + $uninit_plugin['slug'], + $uninit_plugin['priority'] ) ); } diff --git a/includes/Tasks/PluginUnistallTask.php b/includes/Tasks/PluginUnistallTask.php index a2db68fac..902432512 100644 --- a/includes/Tasks/PluginUnistallTask.php +++ b/includes/Tasks/PluginUnistallTask.php @@ -38,7 +38,7 @@ public function increment_retries() { } /** - * Installs the Plugin using the PluginUninstaller Service. + * Uninstalls the Plugin using the PluginUninstaller Service. * * @return \WP_REST_Response|WP_Error */ From 6a809dd693ecf2138eccc8c76185fadb2ed46dff Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Tue, 29 Nov 2022 11:37:32 +0530 Subject: [PATCH 14/49] Pre-checked Installed Plugins --- includes/Data/SiteFeatures.php | 43 +++++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/includes/Data/SiteFeatures.php b/includes/Data/SiteFeatures.php index fcf45ea0a..f2b4ad658 100644 --- a/includes/Data/SiteFeatures.php +++ b/includes/Data/SiteFeatures.php @@ -8,7 +8,7 @@ final class SiteFeatures { protected static $default_plugins = array( array( - 'slug' => '1', + 'slug' => 'jetpack', 'icon' => 'icon-name', 'title' => 'Security, Speed & Growth', 'subtitle' => 'Powered by Jetpack', @@ -16,12 +16,12 @@ final class SiteFeatures { 'selected' => false, ), array( - 'slug' => '2', + 'slug' => 'wpforms-lite', 'icon' => 'icon-name', 'title' => 'Forms', 'subtitle' => 'Powered by WP Forms', 'desc' => 'WP Forms', - 'selected' => true, + 'selected' => false, ), array( 'slug' => '3', @@ -29,7 +29,7 @@ final class SiteFeatures { 'title' => 'Site Traffic', 'subtitle' => 'Powered by MonsterInsights', 'desc' => 'MonsterInsights', - 'selected' => true, + 'selected' => false, ), array( 'slug' => '4', @@ -53,7 +53,7 @@ final class SiteFeatures { 'title' => 'Enhanced Product Search', 'subtitle' => 'Powered by YITH', 'desc' => 'YITH', - 'selected' => true, + 'selected' => false, ), array( 'slug' => '7', @@ -61,7 +61,7 @@ final class SiteFeatures { 'title' => 'Enhanced Product Filters', 'subtitle' => 'Powered by YITH', 'desc' => 'YITH', - 'selected' => true, + 'selected' => false, ), array( 'slug' => '8', @@ -72,7 +72,7 @@ final class SiteFeatures { 'selected' => false, ), array( - 'slug' => '9', + 'slug' => 'nfd_slug_yith_shippo_shippings_for_woocommerce', 'icon' => 'icon-name', 'title' => 'Product Wishlists', 'subtitle' => 'Powered by YITH', @@ -80,18 +80,43 @@ final class SiteFeatures { 'selected' => false, ), array( - 'slug' => '10', + 'slug' => 'optinmonster', 'icon' => 'icon-name', 'title' => 'Lead Generation', 'subtitle' => 'Powered by Optin Monster', 'desc' => 'Optin Monster', - 'selected' => true, + 'selected' => false, ), ); + public static function convert_to_hash() { + $idx = 0; + $default_plugins_hash = array(); + + foreach(self::$default_plugins as $default_plugin){ + $default_plugins_hash[$default_plugin["slug"]] = $idx; + $idx += 1; + } + + return $default_plugins_hash; + } + + public static function mark_installed_plugins() { + $installed_plugins = Plugins::get_init(); + + // Make an Hash Map for faster updation + $default_plugins_hash = self::convert_to_hash(); + + foreach($installed_plugins as $installed_plugin){ + if(isset($default_plugins_hash[$installed_plugin["slug"]])) + self::$default_plugins[$default_plugins_hash[$installed_plugin["slug"]]]["selected"] = true; + } + + } public static function get_default_plugins_list() { + self::mark_installed_plugins(); return self::$default_plugins; } From 13ed47d05a87855c9335a0f054942fd505fd4fbf Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Tue, 29 Nov 2022 12:35:18 +0530 Subject: [PATCH 15/49] Added uninstall code --- includes/Data/SiteFeatures.php | 13 +++---- includes/RestApi/PluginsController.php | 2 +- includes/Services/PluginUninstaller.php | 47 +++++++++++++++++-------- 3 files changed, 40 insertions(+), 22 deletions(-) diff --git a/includes/Data/SiteFeatures.php b/includes/Data/SiteFeatures.php index f2b4ad658..4301782c3 100644 --- a/includes/Data/SiteFeatures.php +++ b/includes/Data/SiteFeatures.php @@ -90,11 +90,11 @@ final class SiteFeatures { ); public static function convert_to_hash() { - $idx = 0; + $idx = 0; $default_plugins_hash = array(); - foreach(self::$default_plugins as $default_plugin){ - $default_plugins_hash[$default_plugin["slug"]] = $idx; + foreach ( self::$default_plugins as $default_plugin ) { + $default_plugins_hash[ $default_plugin['slug'] ] = $idx; $idx += 1; } @@ -107,9 +107,10 @@ public static function mark_installed_plugins() { // Make an Hash Map for faster updation $default_plugins_hash = self::convert_to_hash(); - foreach($installed_plugins as $installed_plugin){ - if(isset($default_plugins_hash[$installed_plugin["slug"]])) - self::$default_plugins[$default_plugins_hash[$installed_plugin["slug"]]]["selected"] = true; + foreach ( $installed_plugins as $installed_plugin ) { + if ( isset( $default_plugins_hash[ $installed_plugin['slug'] ] ) ) { + self::$default_plugins[ $default_plugins_hash[ $installed_plugin['slug'] ] ]['selected'] = true; + } } } diff --git a/includes/RestApi/PluginsController.php b/includes/RestApi/PluginsController.php index 0ebc69c33..52aa89f40 100644 --- a/includes/RestApi/PluginsController.php +++ b/includes/RestApi/PluginsController.php @@ -187,7 +187,7 @@ public function initialize() { */ public function uninstall( \WP_REST_Request $request ) { - return PluginUninstaller::uninstall('woocomerce'); + return PluginUninstaller::uninstall('gutenberg'); } /** diff --git a/includes/Services/PluginUninstaller.php b/includes/Services/PluginUninstaller.php index 31a641de0..7a1a8a4e7 100644 --- a/includes/Services/PluginUninstaller.php +++ b/includes/Services/PluginUninstaller.php @@ -6,18 +6,40 @@ class PluginUninstaller { public static function uninstall( $plugin ) { - - // if ( ! self::is_plugin_installed( $plugin_path ) ) { - // return false; - // } - // if ( $activate && ! \is_plugin_active( $plugin_path ) ) { - // return false; - // } - $installed_plugins = \get_plugins(); + $plugin_path = $plugin . '/' . $plugin . '.php'; + + if ( self::is_plugin_installed( $plugin_path ) ) { + + if ( \is_plugin_active( $plugin_path ) ) { + \deactivate_plugins( $plugin_path ); + } + + if ( ! self::connect_to_filesystem() ) { + return new \WP_Error( + 'nfd_onboarding_error', + 'Could not connect to the filesystem.', + array( 'status' => 500 ) + ); + } + + if ( ! \delete_plugins( array( $plugin_path ) ) ) { + return new \WP_Error( + 'nfd_onboarding_error', + 'Unable to Delete the Plugin', + array( 'status' => 500 ) + ); + } + } else { + return new \WP_Error( + 'nfd_onboarding_error', + 'The Plugin is not installed', + array( 'status' => 500 ) + ); + } return new \WP_REST_Response( - $installed_plugins, + array(), 201 ); } @@ -30,15 +52,10 @@ public static function uninstall( $plugin ) { * @return boolean */ public static function exists( $plugin ) { - $plugin_type = self::get_plugin_type( $plugin ); - $plugin_path = self::get_plugin_path( $plugin, $plugin_type ); + $plugin_path = $plugin . '/' . $plugin . '.php'; if ( ! self::is_plugin_installed( $plugin_path ) ) { return false; } - - if ( ! \is_plugin_active( $plugin_path ) ) { - return false; - } return true; } From 4b1d5df7c91d012096107f13dfff3d763bd860b9 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Tue, 29 Nov 2022 17:26:40 +0530 Subject: [PATCH 16/49] Added a cron for uninstalling --- includes/Data/Plugins.php | 12 ++++ includes/RestApi/PluginsController.php | 60 ++++++++++++++++--- includes/Services/PluginUninstaller.php | 5 +- .../TaskManagers/PluginInstallTaskManager.php | 18 ++++++ .../PluginUninstallTaskManager.php | 29 +-------- includes/TaskManagers/TaskManager.php | 1 + ...istallTask.php => PluginUninstallTask.php} | 6 +- 7 files changed, 91 insertions(+), 40 deletions(-) rename includes/Tasks/{PluginUnistallTask.php => PluginUninstallTask.php} (81%) diff --git a/includes/Data/Plugins.php b/includes/Data/Plugins.php index 1cbe923e9..29200c504 100644 --- a/includes/Data/Plugins.php +++ b/includes/Data/Plugins.php @@ -229,6 +229,18 @@ public static function get() { ); } + /** + * Use this for finding the path for installed plugins. + * + * @return array + */ + public static function get_squashed() { + return array_merge( + self::$wp_slugs, + self::$nfd_slugs, + ); + } + /** * Get approved slugs/urls/domains * diff --git a/includes/RestApi/PluginsController.php b/includes/RestApi/PluginsController.php index 52aa89f40..2ece05beb 100644 --- a/includes/RestApi/PluginsController.php +++ b/includes/RestApi/PluginsController.php @@ -1,13 +1,16 @@ rest_base . '/status', array( array( - 'methods' => \WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_status' ), - 'args' => $this->get_status_args(), + 'methods' => \WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_status' ), + 'args' => $this->get_status_args(), 'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), ), ) @@ -85,8 +88,9 @@ public function register_routes() { $this->rest_base . '/uninstall', array( array( - 'methods' => \WP_REST_Server::READABLE, + 'methods' => \WP_REST_Server::CREATABLE, 'callback' => array( $this, 'uninstall' ), + 'args' => $this->get_uninstall_plugin_args(), 'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), ), ) @@ -145,6 +149,15 @@ public function get_status_args() { ); } + public function get_uninstall_plugin_args() { + return array( + 'plugins' => array( + 'type' => 'object', + 'required' => true, + ), + ); + } + /** * Verify caller has permissions to install plugins. * @@ -186,8 +199,41 @@ public function initialize() { * @return \WP_REST_Response|\WP_Error */ public function uninstall( \WP_REST_Request $request ) { - - return PluginUninstaller::uninstall('gutenberg'); + + $plugin_body = json_decode( $request->get_body(), true ); + $plugins = isset( $plugin_body['plugins'] ) ? $plugin_body['plugins'] : false; + + if ( $plugins ) { + foreach ( $plugins as $plugin => $decision ) { + echo $decision; + if ( $decision ) { + PluginInstallTaskManager::add_to_queue( + new PluginInstallTask( + $plugin, + true, + ) + ); + } else { + $position_in_queue = PluginInstallTaskManager::status( $plugin ); + if ( $position_in_queue === false ) { + PluginUninstallTaskManager::add_to_queue( + new PluginUninstallTask( + $plugin, + ) + ); + } else { + PluginInstallTaskManager::remove_from_queue( + $plugin, + ); + } + } + } + } + + return new \WP_REST_Response( + array(), + 202 + ); } /** diff --git a/includes/Services/PluginUninstaller.php b/includes/Services/PluginUninstaller.php index 7a1a8a4e7..52bf3d147 100644 --- a/includes/Services/PluginUninstaller.php +++ b/includes/Services/PluginUninstaller.php @@ -7,9 +7,10 @@ class PluginUninstaller { public static function uninstall( $plugin ) { - $plugin_path = $plugin . '/' . $plugin . '.php'; + $plugin_list = Plugins::get_squashed(); + $plugin_path = $plugin_list[ $plugin ]['path']; - if ( self::is_plugin_installed( $plugin_path ) ) { + if ( isset( $plugin_path ) && self::is_plugin_installed( $plugin_path ) ) { if ( \is_plugin_active( $plugin_path ) ) { \deactivate_plugins( $plugin_path ); diff --git a/includes/TaskManagers/PluginInstallTaskManager.php b/includes/TaskManagers/PluginInstallTaskManager.php index 283c191b6..b7916a9a4 100644 --- a/includes/TaskManagers/PluginInstallTaskManager.php +++ b/includes/TaskManagers/PluginInstallTaskManager.php @@ -166,6 +166,24 @@ public static function add_to_queue( PluginInstallTask $plugin_install_task ) { return \update_option( Options::get_option_name( self::$queue_name ), $queue->to_array() ); } + public static function remove_from_queue( $plugin ) { + /* + Get the plugins queued up to be installed, the PluginInstall task gets + converted to an associative array before storing it in the option. */ + $plugins = \get_option( Options::get_option_name( self::$queue_name ), array() ); + + $queue = new PriorityQueue(); + foreach ( $plugins as $queued_plugin ) { + /* + If the Plugin slug does not match add it back to the queue. */ + if ( $queued_plugin['slug'] !== $plugin ) { + $queue->insert( $queued_plugin, $queued_plugin['priority'] ); + } + } + + return \update_option( Options::get_option_name( self::$queue_name ), $queue->to_array() ); + } + public static function status( $plugin ) { $plugins = \get_option( Options::get_option_name( self::$queue_name ), array() ); return array_search( $plugin, array_column( $plugins, 'slug' ) ); diff --git a/includes/TaskManagers/PluginUninstallTaskManager.php b/includes/TaskManagers/PluginUninstallTaskManager.php index 48e44fc27..94bb9df6a 100644 --- a/includes/TaskManagers/PluginUninstallTaskManager.php +++ b/includes/TaskManagers/PluginUninstallTaskManager.php @@ -4,7 +4,6 @@ use NewfoldLabs\WP\Module\Onboarding\Data\Options; use NewfoldLabs\WP\Module\Onboarding\Models\PriorityQueue; use NewfoldLabs\WP\Module\Onboarding\Tasks\PluginUninstallTask; -use NewfoldLabs\WP\Module\Onboarding\Services\PluginUninstaller; /** * Manages the execution of PluginUninstallTasks. @@ -48,34 +47,8 @@ public function add_thirty_seconds_schedule( $schedules ) { return $schedules; } - public static function queue_initial_uninstalls( $uninit_plugins ) { - - // Checks if the uninit_list of plugins have already been queued. - if ( \get_option( Options::get_option_name( 'plugins_uninit_status' ), 'init' ) !== 'init' ) { - return true; - } - - // Set option to uninstalling to prevent re-queueing the uninstall on page load. - \update_option( Options::get_option_name( 'plugins_uninit_status' ), 'uninstalling' ); - - - foreach ( $uninit_plugins as $uninit_plugin ) { - // Checks if a plugin with the given slug and activation criteria already exists. - if ( ! PluginUninstaller::exists( $uninit_plugin['slug'] ) ) { - // Add a new PluginUninstallTask to the Plugin uninstall queue. - self::add_to_queue( - new PluginUninstallTask( - $uninit_plugin['slug'], - $uninit_plugin['priority'] - ) - ); - } - } - - return true; - } - /** + * Queue out a PluginUninstallTask with the highest priority in the plugin uninstall queue and execute it. * * @return array|false diff --git a/includes/TaskManagers/TaskManager.php b/includes/TaskManagers/TaskManager.php index 5b394a941..e4b816b6c 100644 --- a/includes/TaskManagers/TaskManager.php +++ b/includes/TaskManagers/TaskManager.php @@ -7,6 +7,7 @@ final class TaskManager { protected $task_managers = array( 'NewfoldLabs\\WP\Module\\Onboarding\\TaskManagers\\PluginInstallTaskManager', + 'NewfoldLabs\\WP\Module\\Onboarding\\TaskManagers\\PluginUninstallTaskManager', 'NewfoldLabs\\WP\Module\\Onboarding\\TaskManagers\\ThemeInstallTaskManager', ); diff --git a/includes/Tasks/PluginUnistallTask.php b/includes/Tasks/PluginUninstallTask.php similarity index 81% rename from includes/Tasks/PluginUnistallTask.php rename to includes/Tasks/PluginUninstallTask.php index 902432512..3fe021d8f 100644 --- a/includes/Tasks/PluginUnistallTask.php +++ b/includes/Tasks/PluginUninstallTask.php @@ -11,9 +11,9 @@ class PluginUninstallTask extends Task { private $slug, $priority, $retries; /** - * @param string $slug The slug for the Plugin. Ref: includes/Data/Plugins.php for the slugs. - * @param int $priority Priority of the task, higher the number higher the priority. - * @param int $retries The number of times the Task has been retried + * @param string $slug The slug for the Plugin. Ref: includes/Data/Plugins.php for the slugs. + * @param int $priority Priority of the task, higher the number higher the priority. + * @param int $retries The number of times the Task has been retried */ function __construct( $slug, $priority = 0, $retries = 0 ) { $this->slug = $slug; From 0221d595f005ecb30f6792420d8f90896a9b6c1b Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Tue, 29 Nov 2022 19:07:16 +0530 Subject: [PATCH 17/49] Added some CSS --- .../CheckboxTemplate/CheckboxItem/index.js | 12 +++++++----- .../CheckboxTemplate/CheckboxItem/stylesheet.scss | 12 ++++++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js index 62a8d44be..6f4a51cca 100644 --- a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js @@ -37,18 +37,20 @@ const CheckboxItem = ({ slug, icon, title, subtitle, desc, isSelectedDefault, ca onChange={handleCheck} className="checkbox-item-checkbox" />
-
+
-
{title}
+
{title}
{subtitle}
diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss index 5777b5420..f728feb0a 100644 --- a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss @@ -34,8 +34,12 @@ margin-right: 16px; border-radius: 50%; align-items: center; - background: #1C5CBA; + background: #F0F0F0; justify-content: center; + + &--selected { + background: #1C5CBA; + } &--shown { background: #F0F0F0; @@ -51,9 +55,13 @@ &-title{ font-size: 16px; - color: #1C5CBA; + color: #0D0D0D; line-height: 18px; margin-bottom: 6px; + + &--selected { + color: #1C5CBA; + } } &-subtitle { From aea1d85936625df45adec974b63d2b0e49239708 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Tue, 29 Nov 2022 19:55:44 +0530 Subject: [PATCH 18/49] Added Icon Support --- includes/Data/SiteFeatures.php | 20 ++++++++-------- .../CheckboxTemplate/CheckboxItem/index.js | 10 ++++---- .../static/icons/site-features/analytics.svg | 18 +++++++++++++++ .../icons/site-features/analytics_light.svg | 18 +++++++++++++++ .../icons/site-features/bookingcalendar.svg | 23 +++++++++++++++++++ .../site-features/bookingcalendar_light.svg | 23 +++++++++++++++++++ .../static/icons/site-features/email.svg | 3 +++ .../icons/site-features/email_light.svg | 3 +++ .../static/icons/site-features/filter.svg | 11 +++++++++ .../icons/site-features/filter_light.svg | 11 +++++++++ .../static/icons/site-features/form.svg | 18 +++++++++++++++ .../static/icons/site-features/form_light.svg | 18 +++++++++++++++ .../static/icons/site-features/lead.svg | 18 +++++++++++++++ .../static/icons/site-features/lead_light.svg | 18 +++++++++++++++ .../static/icons/site-features/search.svg | 4 ++++ .../icons/site-features/search_light.svg | 4 ++++ .../static/icons/site-features/security.svg | 18 +++++++++++++++ .../icons/site-features/security_light.svg | 18 +++++++++++++++ .../static/icons/site-features/share.svg | 18 +++++++++++++++ .../icons/site-features/share_light.svg | 18 +++++++++++++++ .../static/icons/site-features/wishlist.svg | 4 ++++ .../icons/site-features/wishlist_light.svg | 4 ++++ src/OnboardingSPA/styles/_icons.scss | 21 +++++++++++++++++ 23 files changed, 307 insertions(+), 14 deletions(-) create mode 100644 src/OnboardingSPA/static/icons/site-features/analytics.svg create mode 100644 src/OnboardingSPA/static/icons/site-features/analytics_light.svg create mode 100644 src/OnboardingSPA/static/icons/site-features/bookingcalendar.svg create mode 100644 src/OnboardingSPA/static/icons/site-features/bookingcalendar_light.svg create mode 100644 src/OnboardingSPA/static/icons/site-features/email.svg create mode 100644 src/OnboardingSPA/static/icons/site-features/email_light.svg create mode 100644 src/OnboardingSPA/static/icons/site-features/filter.svg create mode 100644 src/OnboardingSPA/static/icons/site-features/filter_light.svg create mode 100644 src/OnboardingSPA/static/icons/site-features/form.svg create mode 100644 src/OnboardingSPA/static/icons/site-features/form_light.svg create mode 100644 src/OnboardingSPA/static/icons/site-features/lead.svg create mode 100644 src/OnboardingSPA/static/icons/site-features/lead_light.svg create mode 100644 src/OnboardingSPA/static/icons/site-features/search.svg create mode 100644 src/OnboardingSPA/static/icons/site-features/search_light.svg create mode 100644 src/OnboardingSPA/static/icons/site-features/security.svg create mode 100644 src/OnboardingSPA/static/icons/site-features/security_light.svg create mode 100644 src/OnboardingSPA/static/icons/site-features/share.svg create mode 100644 src/OnboardingSPA/static/icons/site-features/share_light.svg create mode 100644 src/OnboardingSPA/static/icons/site-features/wishlist.svg create mode 100644 src/OnboardingSPA/static/icons/site-features/wishlist_light.svg diff --git a/includes/Data/SiteFeatures.php b/includes/Data/SiteFeatures.php index 4301782c3..bed42d898 100644 --- a/includes/Data/SiteFeatures.php +++ b/includes/Data/SiteFeatures.php @@ -9,7 +9,7 @@ final class SiteFeatures { protected static $default_plugins = array( array( 'slug' => 'jetpack', - 'icon' => 'icon-name', + 'icon' => '--site-features-security', 'title' => 'Security, Speed & Growth', 'subtitle' => 'Powered by Jetpack', 'desc' => 'Jetpack', @@ -17,7 +17,7 @@ final class SiteFeatures { ), array( 'slug' => 'wpforms-lite', - 'icon' => 'icon-name', + 'icon' => '--site-features-form', 'title' => 'Forms', 'subtitle' => 'Powered by WP Forms', 'desc' => 'WP Forms', @@ -25,7 +25,7 @@ final class SiteFeatures { ), array( 'slug' => '3', - 'icon' => 'icon-name', + 'icon' => '--site-features-analytics', 'title' => 'Site Traffic', 'subtitle' => 'Powered by MonsterInsights', 'desc' => 'MonsterInsights', @@ -33,7 +33,7 @@ final class SiteFeatures { ), array( 'slug' => '4', - 'icon' => 'icon-name', + 'icon' => '--site-features-share', 'title' => 'Search Engine Optimization', 'subtitle' => 'Powered by Yoast', 'desc' => 'Yoast', @@ -41,7 +41,7 @@ final class SiteFeatures { ), array( 'slug' => '5', - 'icon' => 'icon-name', + 'icon' => '--site-features-email', 'title' => 'Email Newsletters', 'subtitle' => 'Powered by Creative Email', 'desc' => 'Creative Email', @@ -49,7 +49,7 @@ final class SiteFeatures { ), array( 'slug' => '6', - 'icon' => 'icon-name', + 'icon' => '--site-features-search', 'title' => 'Enhanced Product Search', 'subtitle' => 'Powered by YITH', 'desc' => 'YITH', @@ -57,7 +57,7 @@ final class SiteFeatures { ), array( 'slug' => '7', - 'icon' => 'icon-name', + 'icon' => '--site-features-filter', 'title' => 'Enhanced Product Filters', 'subtitle' => 'Powered by YITH', 'desc' => 'YITH', @@ -65,7 +65,7 @@ final class SiteFeatures { ), array( 'slug' => '8', - 'icon' => 'icon-name', + 'icon' => '--site-features-bookingcalendar', 'title' => 'Bookings & Appointments', 'subtitle' => 'Powered by YITH', 'desc' => 'YITH', @@ -73,7 +73,7 @@ final class SiteFeatures { ), array( 'slug' => 'nfd_slug_yith_shippo_shippings_for_woocommerce', - 'icon' => 'icon-name', + 'icon' => '--site-features-wishlist', 'title' => 'Product Wishlists', 'subtitle' => 'Powered by YITH', 'desc' => 'YITH', @@ -81,7 +81,7 @@ final class SiteFeatures { ), array( 'slug' => 'optinmonster', - 'icon' => 'icon-name', + 'icon' => '--site-features-lead', 'title' => 'Lead Generation', 'subtitle' => 'Powered by Optin Monster', 'desc' => 'Optin Monster', diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js index 6f4a51cca..593af017e 100644 --- a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js @@ -1,5 +1,5 @@ import { useState } from '@wordpress/element'; -import { Icon, help, search } from '@wordpress/icons'; +import { Icon, help, box } from '@wordpress/icons'; import { CheckboxControl } from '@wordpress/components'; @@ -40,12 +40,14 @@ const CheckboxItem = ({ slug, icon, title, subtitle, desc, isSelectedDefault, ca
-
diff --git a/src/OnboardingSPA/static/icons/site-features/analytics.svg b/src/OnboardingSPA/static/icons/site-features/analytics.svg new file mode 100644 index 000000000..303e3c4b7 --- /dev/null +++ b/src/OnboardingSPA/static/icons/site-features/analytics.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/OnboardingSPA/static/icons/site-features/analytics_light.svg b/src/OnboardingSPA/static/icons/site-features/analytics_light.svg new file mode 100644 index 000000000..28b5002c6 --- /dev/null +++ b/src/OnboardingSPA/static/icons/site-features/analytics_light.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/OnboardingSPA/static/icons/site-features/bookingcalendar.svg b/src/OnboardingSPA/static/icons/site-features/bookingcalendar.svg new file mode 100644 index 000000000..8c3b47bf9 --- /dev/null +++ b/src/OnboardingSPA/static/icons/site-features/bookingcalendar.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/OnboardingSPA/static/icons/site-features/bookingcalendar_light.svg b/src/OnboardingSPA/static/icons/site-features/bookingcalendar_light.svg new file mode 100644 index 000000000..95cb715db --- /dev/null +++ b/src/OnboardingSPA/static/icons/site-features/bookingcalendar_light.svg @@ -0,0 +1,23 @@ + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/OnboardingSPA/static/icons/site-features/email.svg b/src/OnboardingSPA/static/icons/site-features/email.svg new file mode 100644 index 000000000..4016aa347 --- /dev/null +++ b/src/OnboardingSPA/static/icons/site-features/email.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/OnboardingSPA/static/icons/site-features/email_light.svg b/src/OnboardingSPA/static/icons/site-features/email_light.svg new file mode 100644 index 000000000..7a7207337 --- /dev/null +++ b/src/OnboardingSPA/static/icons/site-features/email_light.svg @@ -0,0 +1,3 @@ + + + diff --git a/src/OnboardingSPA/static/icons/site-features/filter.svg b/src/OnboardingSPA/static/icons/site-features/filter.svg new file mode 100644 index 000000000..0c91ce13f --- /dev/null +++ b/src/OnboardingSPA/static/icons/site-features/filter.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/src/OnboardingSPA/static/icons/site-features/filter_light.svg b/src/OnboardingSPA/static/icons/site-features/filter_light.svg new file mode 100644 index 000000000..9d6ba62ff --- /dev/null +++ b/src/OnboardingSPA/static/icons/site-features/filter_light.svg @@ -0,0 +1,11 @@ + + + + + + + + + + + diff --git a/src/OnboardingSPA/static/icons/site-features/form.svg b/src/OnboardingSPA/static/icons/site-features/form.svg new file mode 100644 index 000000000..d0d897472 --- /dev/null +++ b/src/OnboardingSPA/static/icons/site-features/form.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/OnboardingSPA/static/icons/site-features/form_light.svg b/src/OnboardingSPA/static/icons/site-features/form_light.svg new file mode 100644 index 000000000..dc81d3598 --- /dev/null +++ b/src/OnboardingSPA/static/icons/site-features/form_light.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/OnboardingSPA/static/icons/site-features/lead.svg b/src/OnboardingSPA/static/icons/site-features/lead.svg new file mode 100644 index 000000000..ea59e7e8e --- /dev/null +++ b/src/OnboardingSPA/static/icons/site-features/lead.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/OnboardingSPA/static/icons/site-features/lead_light.svg b/src/OnboardingSPA/static/icons/site-features/lead_light.svg new file mode 100644 index 000000000..08e883fa8 --- /dev/null +++ b/src/OnboardingSPA/static/icons/site-features/lead_light.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/OnboardingSPA/static/icons/site-features/search.svg b/src/OnboardingSPA/static/icons/site-features/search.svg new file mode 100644 index 000000000..220fb5167 --- /dev/null +++ b/src/OnboardingSPA/static/icons/site-features/search.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/OnboardingSPA/static/icons/site-features/search_light.svg b/src/OnboardingSPA/static/icons/site-features/search_light.svg new file mode 100644 index 000000000..69ccf0539 --- /dev/null +++ b/src/OnboardingSPA/static/icons/site-features/search_light.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/OnboardingSPA/static/icons/site-features/security.svg b/src/OnboardingSPA/static/icons/site-features/security.svg new file mode 100644 index 000000000..089ff3def --- /dev/null +++ b/src/OnboardingSPA/static/icons/site-features/security.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/OnboardingSPA/static/icons/site-features/security_light.svg b/src/OnboardingSPA/static/icons/site-features/security_light.svg new file mode 100644 index 000000000..5f028d1f4 --- /dev/null +++ b/src/OnboardingSPA/static/icons/site-features/security_light.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/OnboardingSPA/static/icons/site-features/share.svg b/src/OnboardingSPA/static/icons/site-features/share.svg new file mode 100644 index 000000000..746564332 --- /dev/null +++ b/src/OnboardingSPA/static/icons/site-features/share.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/OnboardingSPA/static/icons/site-features/share_light.svg b/src/OnboardingSPA/static/icons/site-features/share_light.svg new file mode 100644 index 000000000..65252b90a --- /dev/null +++ b/src/OnboardingSPA/static/icons/site-features/share_light.svg @@ -0,0 +1,18 @@ + + + + + + + + + + + + + + + + + + diff --git a/src/OnboardingSPA/static/icons/site-features/wishlist.svg b/src/OnboardingSPA/static/icons/site-features/wishlist.svg new file mode 100644 index 000000000..58d756018 --- /dev/null +++ b/src/OnboardingSPA/static/icons/site-features/wishlist.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/OnboardingSPA/static/icons/site-features/wishlist_light.svg b/src/OnboardingSPA/static/icons/site-features/wishlist_light.svg new file mode 100644 index 000000000..661edd9f7 --- /dev/null +++ b/src/OnboardingSPA/static/icons/site-features/wishlist_light.svg @@ -0,0 +1,4 @@ + + + + diff --git a/src/OnboardingSPA/styles/_icons.scss b/src/OnboardingSPA/styles/_icons.scss index 2be397c74..0e02f9160 100644 --- a/src/OnboardingSPA/styles/_icons.scss +++ b/src/OnboardingSPA/styles/_icons.scss @@ -50,6 +50,27 @@ body { --nfd-onboarding-sidebar-learn-more-pages-illustration: url("../static/icons/learn-more-pages.svg"); --nfd-onboarding-sidebar-learn-more-site-features-illustration: url("../static/icons/learn-more-site-features.svg"); --nfd-onboarding-sidebar-learn-more-what-next-illustration: url("../static/icons/learn-more-what-next.svg"); + + --site-features-analytics: url("../static/icons/site-features/analytics.svg"); + --site-features-analytics--light: url("../static/icons/site-features/analytics_light.svg"); + --site-features-bookingcalendar: url("../static/icons/site-features/bookingcalendar.svg"); + --site-features-bookingcalendar--light: url("../static/icons/site-features/bookingcalendar_light.svg"); + --site-features-email: url("../static/icons/site-features/email.svg"); + --site-features-email--light: url("../static/icons/site-features/email_light.svg"); + --site-features-filter: url("../static/icons/site-features/filter.svg"); + --site-features-filter--light: url("../static/icons/site-features/filter_light.svg"); + --site-features-form: url("../static/icons/site-features/form.svg"); + --site-features-form--light: url("../static/icons/site-features/form_light.svg"); + --site-features-lead: url("../static/icons/site-features/lead.svg"); + --site-features-lead--light: url("../static/icons/site-features/lead_light.svg"); + --site-features-search: url("../static/icons/site-features/search.svg"); + --site-features-search--light: url("../static/icons/site-features/search_light.svg"); + --site-features-security: url("../static/icons/site-features/security.svg"); + --site-features-security--light: url("../static/icons/site-features/security_light.svg"); + --site-features-share: url("../static/icons/site-features/share.svg"); + --site-features-share--light: url("../static/icons/site-features/share_light.svg"); + --site-features-wishlist: url("../static/icons/site-features/wishlist.svg"); + --site-features-wishlist--light: url("../static/icons/site-features/wishlist_light.svg"); /* * Below Icons are commented because they get added to the CSS bundle and From 35232240b3d9f3caeb06f5ab366e9a863835fa89 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Wed, 30 Nov 2022 13:09:40 +0530 Subject: [PATCH 19/49] Update PluginsController.php --- includes/RestApi/PluginsController.php | 94 +++++++++++++------------- 1 file changed, 47 insertions(+), 47 deletions(-) diff --git a/includes/RestApi/PluginsController.php b/includes/RestApi/PluginsController.php index 2ece05beb..c63de5941 100644 --- a/includes/RestApi/PluginsController.php +++ b/includes/RestApi/PluginsController.php @@ -192,52 +192,7 @@ public function initialize() { } /** - * Install the requested plugin via a zip url (or) slug. - * - * @param \WP_REST_Request $request - * - * @return \WP_REST_Response|\WP_Error - */ - public function uninstall( \WP_REST_Request $request ) { - - $plugin_body = json_decode( $request->get_body(), true ); - $plugins = isset( $plugin_body['plugins'] ) ? $plugin_body['plugins'] : false; - - if ( $plugins ) { - foreach ( $plugins as $plugin => $decision ) { - echo $decision; - if ( $decision ) { - PluginInstallTaskManager::add_to_queue( - new PluginInstallTask( - $plugin, - true, - ) - ); - } else { - $position_in_queue = PluginInstallTaskManager::status( $plugin ); - if ( $position_in_queue === false ) { - PluginUninstallTaskManager::add_to_queue( - new PluginUninstallTask( - $plugin, - ) - ); - } else { - PluginInstallTaskManager::remove_from_queue( - $plugin, - ); - } - } - } - } - - return new \WP_REST_Response( - array(), - 202 - ); - } - - /** - * Uninstalls the requested plugin. + * Installs the requested plugin. * * @param \WP_REST_Request $request * @@ -280,7 +235,6 @@ public function install( \WP_REST_Request $request ) { return $plugin_install_task->execute(); } - public function get_status( \WP_REST_Request $request ) { $plugin = $request->get_param( 'plugin' ); $activated = $request->get_param( 'activated' ); @@ -314,4 +268,50 @@ public function get_status( \WP_REST_Request $request ) { ); } + + /** + * Installs/Uninstalls the requested plugins. + * + * @param \WP_REST_Request $request + * + * @return \WP_REST_Response|\WP_Error + */ + public function uninstall( \WP_REST_Request $request ) { + + $plugin_body = json_decode( $request->get_body(), true ); + $plugins = isset( $plugin_body['plugins'] ) ? $plugin_body['plugins'] : false; + + if ( $plugins ) { + foreach ( $plugins as $plugin => $decision ) { + echo $decision; + if ( $decision ) { + PluginInstallTaskManager::add_to_queue( + new PluginInstallTask( + $plugin, + true, + ) + ); + } else { + $position_in_queue = PluginInstallTaskManager::status( $plugin ); + if ( $position_in_queue === false ) { + PluginUninstallTaskManager::add_to_queue( + new PluginUninstallTask( + $plugin, + ) + ); + } else { + PluginInstallTaskManager::remove_from_queue( + $plugin, + ); + } + } + } + } + + return new \WP_REST_Response( + array(), + 202 + ); + } } + From d974c88dbc1c5440e993f96d9cd262718d7c52d6 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Wed, 30 Nov 2022 13:09:45 +0530 Subject: [PATCH 20/49] Update index.js --- .../components/CheckboxTemplate/CheckboxItem/index.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js index 593af017e..e84efb595 100644 --- a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js @@ -44,7 +44,6 @@ const CheckboxItem = ({ slug, icon, title, subtitle, desc, isSelectedDefault, ca style={{ width: '35px', height: '35px', - stroke: 'red', backgroundPosition: 'center', backgroundRepeat: 'no-repeat', backgroundImage: `var(${icon}${isSelected ? '--light' : ''})`, From b1e512ac7be8c5656ad9632756f5e5a977c8ec25 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Wed, 30 Nov 2022 18:01:16 +0530 Subject: [PATCH 21/49] Fixed Plugin Slugs --- includes/Data/Plugins.php | 4 ++++ includes/Data/SiteFeatures.php | 14 +++++++------- includes/RestApi/PluginsController.php | 1 - 3 files changed, 11 insertions(+), 8 deletions(-) diff --git a/includes/Data/Plugins.php b/includes/Data/Plugins.php index 29200c504..7fc708d73 100644 --- a/includes/Data/Plugins.php +++ b/includes/Data/Plugins.php @@ -41,6 +41,10 @@ final class Plugins { 'approved' => true, 'path' => 'yith-woocommerce-ajax-search/init.php', ), + 'creative-mail-by-constant-contact' => array( + 'approved' => true, + 'path' => 'creative-mail-by-constant-contact/creative-mail-plugin.php', + ), ); /** diff --git a/includes/Data/SiteFeatures.php b/includes/Data/SiteFeatures.php index bed42d898..2ff419160 100644 --- a/includes/Data/SiteFeatures.php +++ b/includes/Data/SiteFeatures.php @@ -24,7 +24,7 @@ final class SiteFeatures { 'selected' => false, ), array( - 'slug' => '3', + 'slug' => 'google-analytics-for-wordpress', 'icon' => '--site-features-analytics', 'title' => 'Site Traffic', 'subtitle' => 'Powered by MonsterInsights', @@ -32,7 +32,7 @@ final class SiteFeatures { 'selected' => false, ), array( - 'slug' => '4', + 'slug' => 'wordpress-seo', 'icon' => '--site-features-share', 'title' => 'Search Engine Optimization', 'subtitle' => 'Powered by Yoast', @@ -40,7 +40,7 @@ final class SiteFeatures { 'selected' => false, ), array( - 'slug' => '5', + 'slug' => 'creative-mail-by-constant-contact', 'icon' => '--site-features-email', 'title' => 'Email Newsletters', 'subtitle' => 'Powered by Creative Email', @@ -48,7 +48,7 @@ final class SiteFeatures { 'selected' => false, ), array( - 'slug' => '6', + 'slug' => 'yith-woocommerce-ajax-search', 'icon' => '--site-features-search', 'title' => 'Enhanced Product Search', 'subtitle' => 'Powered by YITH', @@ -56,7 +56,7 @@ final class SiteFeatures { 'selected' => false, ), array( - 'slug' => '7', + 'slug' => 'nfd_slug_yith_woocommerce_ajax_product_filter', 'icon' => '--site-features-filter', 'title' => 'Enhanced Product Filters', 'subtitle' => 'Powered by YITH', @@ -64,7 +64,7 @@ final class SiteFeatures { 'selected' => false, ), array( - 'slug' => '8', + 'slug' => 'nfd_slug_yith_woocommerce_booking', 'icon' => '--site-features-bookingcalendar', 'title' => 'Bookings & Appointments', 'subtitle' => 'Powered by YITH', @@ -72,7 +72,7 @@ final class SiteFeatures { 'selected' => false, ), array( - 'slug' => 'nfd_slug_yith_shippo_shippings_for_woocommerce', + 'slug' => 'nfd_slug_yith_woocommerce_wishlist', 'icon' => '--site-features-wishlist', 'title' => 'Product Wishlists', 'subtitle' => 'Powered by YITH', diff --git a/includes/RestApi/PluginsController.php b/includes/RestApi/PluginsController.php index c63de5941..3f51afde1 100644 --- a/includes/RestApi/PluginsController.php +++ b/includes/RestApi/PluginsController.php @@ -283,7 +283,6 @@ public function uninstall( \WP_REST_Request $request ) { if ( $plugins ) { foreach ( $plugins as $plugin => $decision ) { - echo $decision; if ( $decision ) { PluginInstallTaskManager::add_to_queue( new PluginInstallTask( From 6853aa68073ee28558f75c1209e7b851e1245abb Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Wed, 30 Nov 2022 18:27:53 +0530 Subject: [PATCH 22/49] Update PluginUninstaller.php --- includes/Services/PluginUninstaller.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/includes/Services/PluginUninstaller.php b/includes/Services/PluginUninstaller.php index 52bf3d147..aebe1f319 100644 --- a/includes/Services/PluginUninstaller.php +++ b/includes/Services/PluginUninstaller.php @@ -31,11 +31,11 @@ public static function uninstall( $plugin ) { array( 'status' => 500 ) ); } + } else { - return new \WP_Error( - 'nfd_onboarding_error', - 'The Plugin is not installed', - array( 'status' => 500 ) + return new \WP_REST_Response( + array(), + 201 ); } From efca3a2fb41fef6d75a845f48060164f9f0817bc Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Wed, 30 Nov 2022 18:28:23 +0530 Subject: [PATCH 23/49] Update PluginUninstaller.php --- includes/Services/PluginUninstaller.php | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/includes/Services/PluginUninstaller.php b/includes/Services/PluginUninstaller.php index aebe1f319..7c561301d 100644 --- a/includes/Services/PluginUninstaller.php +++ b/includes/Services/PluginUninstaller.php @@ -31,12 +31,7 @@ public static function uninstall( $plugin ) { array( 'status' => 500 ) ); } - - } else { - return new \WP_REST_Response( - array(), - 201 - ); + } return new \WP_REST_Response( From 066cf9e4b75e3ad1062c7c232bf237a4fd210f8f Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Thu, 1 Dec 2022 11:29:59 +0530 Subject: [PATCH 24/49] Refactored Code --- includes/Services/PluginUninstaller.php | 87 +++++++++++++++++++------ 1 file changed, 68 insertions(+), 19 deletions(-) diff --git a/includes/Services/PluginUninstaller.php b/includes/Services/PluginUninstaller.php index 7c561301d..3cb6b43ec 100644 --- a/includes/Services/PluginUninstaller.php +++ b/includes/Services/PluginUninstaller.php @@ -3,35 +3,28 @@ use NewfoldLabs\WP\Module\Onboarding\Data\Plugins; +/** + * Class PluginUninstaller + * This class is responsible to Uninstall a specified plugin + */ + class PluginUninstaller { public static function uninstall( $plugin ) { $plugin_list = Plugins::get_squashed(); + // Gets the specified path for the Plugin from the predefined list $plugin_path = $plugin_list[ $plugin ]['path']; if ( isset( $plugin_path ) && self::is_plugin_installed( $plugin_path ) ) { - if ( \is_plugin_active( $plugin_path ) ) { - \deactivate_plugins( $plugin_path ); - } + self::deactivate_plugin_if_active( $plugin_path ); + $res = self::delete_plugin( $plugin_path ); - if ( ! self::connect_to_filesystem() ) { - return new \WP_Error( - 'nfd_onboarding_error', - 'Could not connect to the filesystem.', - array( 'status' => 500 ) - ); + // If Deletion is not successful throw an error for a retry. + if ( is_wp_error( $res ) ) { + return $res; } - - if ( ! \delete_plugins( array( $plugin_path ) ) ) { - return new \WP_Error( - 'nfd_onboarding_error', - 'Unable to Delete the Plugin', - array( 'status' => 500 ) - ); - } - } return new \WP_REST_Response( @@ -48,7 +41,10 @@ public static function uninstall( $plugin ) { * @return boolean */ public static function exists( $plugin ) { - $plugin_path = $plugin . '/' . $plugin . '.php'; + + $plugin_list = Plugins::get_squashed(); + $plugin_path = $plugin_list[ $plugin ]['path']; + if ( ! self::is_plugin_installed( $plugin_path ) ) { return false; } @@ -74,6 +70,26 @@ public static function is_plugin_installed( $plugin_path ) { } } + /** + * Deactivates a Plugin if it is activated. + * + * @param string $plugin_path Path to the plugin's header file. + */ + public static function deactivate_plugin_if_active( $plugin_path ) { + + // Checks if the necessary functions exist + if ( ! function_exists( 'is_plugin_active' ) || ! function_exists( 'deactivate_plugins' ) ) { + require_once ABSPATH . 'wp-admin/includes/plugin.php'; + } + + // Determines whether a plugin is active. + if ( \is_plugin_active( $plugin_path ) ) { + // Deactivates a single plugin or multiple plugins. + // /wp-admin/includes/plugin.php + \deactivate_plugins( $plugin_path ); + } + } + /** * Establishes a connection to the wp_filesystem. * @@ -97,4 +113,37 @@ protected static function connect_to_filesystem() { return true; } + /** + * Deletes a Plugin if it exists. + * + * @param string $plugin_path Path to the plugin's header file. + * @return boolean|\WP_Error + */ + public static function delete_plugin( $plugin_path ) { + + // Checks if the necessary functions exist + if ( ! function_exists( 'delete_plugins' ) ) { + require_once ABSPATH . 'wp-admin/includes/plugin.php'; + } + + if ( ! self::connect_to_filesystem() ) { + return new \WP_Error( + 'nfd_onboarding_error', + 'Could not connect to the filesystem.', + array( 'status' => 500 ) + ); + } + + // Removes directory and files of a plugin + if ( ! \delete_plugins( array( $plugin_path ) ) ) { + return new \WP_Error( + 'nfd_onboarding_error', + 'Unable to Delete the Plugin', + array( 'status' => 500 ) + ); + } + + return true; + } + } From c256dfa377164dc8d8cfd84e82ebb9a7d473b832 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Thu, 1 Dec 2022 11:51:34 +0530 Subject: [PATCH 25/49] Fixed Code Comments --- includes/TaskManagers/PluginUninstallTaskManager.php | 6 +++--- includes/Tasks/PluginUninstallTask.php | 4 ++-- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/includes/TaskManagers/PluginUninstallTaskManager.php b/includes/TaskManagers/PluginUninstallTaskManager.php index 94bb9df6a..8cf1541a5 100644 --- a/includes/TaskManagers/PluginUninstallTaskManager.php +++ b/includes/TaskManagers/PluginUninstallTaskManager.php @@ -55,7 +55,7 @@ public function add_thirty_seconds_schedule( $schedules ) { */ public function uninstall() { /* - Get the plugins queued up to be installed, the PluginInstall task gets + Get the plugins queued up to be uninstalled, the PluginUninstall task gets converted to an associative array before storing it in the option. */ $plugins = \get_option( Options::get_option_name( self::$queue_name ), array() ); @@ -108,7 +108,7 @@ public function uninstall() { */ public static function add_to_queue( PluginUninstallTask $plugin_uninstall_task ) { /* - Get the plugins queued up to be installed, the PluginInstall task gets + Get the plugins queued up to be uninstalled, the PluginUninstall task gets converted to an associative array before storing it in the option. */ $plugins = \get_option( Options::get_option_name( self::$queue_name ), array() ); @@ -117,7 +117,7 @@ public static function add_to_queue( PluginUninstallTask $plugin_uninstall_task /* Check if there is an already existing PluginUninstallTask in the queue - for a given slug and activation criteria. */ + for a given slug. */ if ( $queued_plugin['slug'] === $plugin_uninstall_task->get_slug() ) { return false; } diff --git a/includes/Tasks/PluginUninstallTask.php b/includes/Tasks/PluginUninstallTask.php index 3fe021d8f..a0780cdfb 100644 --- a/includes/Tasks/PluginUninstallTask.php +++ b/includes/Tasks/PluginUninstallTask.php @@ -4,7 +4,7 @@ use NewfoldLabs\WP\Module\Onboarding\Services\PluginUninstaller; /** - * Task for uninstalling a Plugin. + * Task for Uninstalling a Plugin. */ class PluginUninstallTask extends Task { @@ -40,7 +40,7 @@ public function increment_retries() { /** * Uninstalls the Plugin using the PluginUninstaller Service. * - * @return \WP_REST_Response|WP_Error + * @return \WP_REST_Response|\WP_Error */ public function execute() { return PluginUninstaller::uninstall( $this->get_slug() ); From 9a0818409528a90ba2a6154931b32fd2227787d0 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Thu, 1 Dec 2022 11:54:19 +0530 Subject: [PATCH 26/49] Update PluginsController.php --- includes/RestApi/PluginsController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/RestApi/PluginsController.php b/includes/RestApi/PluginsController.php index 3f51afde1..2af81b74c 100644 --- a/includes/RestApi/PluginsController.php +++ b/includes/RestApi/PluginsController.php @@ -91,7 +91,7 @@ public function register_routes() { 'methods' => \WP_REST_Server::CREATABLE, 'callback' => array( $this, 'uninstall' ), 'args' => $this->get_uninstall_plugin_args(), - 'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), + 'permission_callback' => array( $this, 'check_install_permissions' ), ), ) ); @@ -192,7 +192,7 @@ public function initialize() { } /** - * Installs the requested plugin. + * Install the requested plugin via a zip url (or) slug. * * @param \WP_REST_Request $request * From 31c5d2cf66e220e640e0762b8ccf50b81d3d3258 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Thu, 1 Dec 2022 12:01:45 +0530 Subject: [PATCH 27/49] Linting the JS --- .../CheckboxTemplate/CheckboxItem/index.js | 153 +++++++++++------- .../CheckboxTemplate/CheckboxList/index.js | 74 +++++---- src/OnboardingSPA/data/routes/default-flow.js | 12 +- .../pages/Steps/SiteFeatures/index.js | 124 +++++++------- src/OnboardingSPA/utils/api/plugins.js | 6 +- 5 files changed, 214 insertions(+), 155 deletions(-) diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js index e84efb595..fed89a655 100644 --- a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js @@ -1,5 +1,5 @@ import { useState } from '@wordpress/element'; -import { Icon, help, box } from '@wordpress/icons'; +import { Icon, help, box } from '@wordpress/icons'; import { CheckboxControl } from '@wordpress/components'; @@ -7,69 +7,106 @@ import { CheckboxControl } from '@wordpress/components'; * Checkbox Item Component * This returns a Single Element with a toggable description * - * @param {string} icon - The icon name of the Item - * @param {string} title - The Main Title of the Item + * @param {string} icon - The icon name of the Item + * @param {string} title - The Main Title of the Item * @param {string} subtitle - The Sub Title of the Item - * @param {string} desc - The Description of the Item - * - * @returns CheckboxItem + * @param {string} desc - The Description of the Item + * + * @return CheckboxItem */ -const CheckboxItem = ({ slug, icon, title, subtitle, desc, isSelectedDefault, callback }) => { - - const [showDescription, setShowDescription] = useState(false); - const [isSelected, setIsSelected] = useState(isSelectedDefault); +const CheckboxItem = ( { + slug, + icon, + title, + subtitle, + desc, + isSelectedDefault, + callback, +} ) => { + const [ showDescription, setShowDescription ] = useState( false ); + const [ isSelected, setIsSelected ] = useState( isSelectedDefault ); - const handleCheck = () => { - setIsSelected(!isSelected); - callback(slug, !isSelected); - }; + const handleCheck = () => { + setIsSelected( ! isSelected ); + callback( slug, ! isSelected ); + }; - const handleShowDesc = () => { - setShowDescription(!showDescription); - }; + const handleShowDesc = () => { + setShowDescription( ! showDescription ); + }; - return ( -
-
- -
-
-
-
-
-
{title}
-
{subtitle}
-
-
- -
-
-
- {showDescription &&
{desc}
} -
- ); + return ( +
+
+ +
+
+
+
+
+
+ { title } +
+
+ { subtitle } +
+
+
+ +
+
+
+ { showDescription && ( +
{ desc }
+ ) } +
+ ); }; export default CheckboxItem; diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/index.js b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/index.js index e3141fc66..e66b855a8 100644 --- a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/index.js +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/index.js @@ -1,42 +1,50 @@ -import { CheckboxItem } from "../index"; - +import { CheckboxItem } from '../index'; /** * Checkbox List Component * This returns a List of Checkbox Items to be placed dynamically on screen - * - * @param {Object} customPluginsList - The List to be shown with a Title, Subtitle and a Description - * - * @returns CheckboxList + * + * @param customPluginsList.callback + * @param {Object} customPluginsList - The List to be shown with a Title, Subtitle and a Description + * + * @param customPluginsList.selectedPlugins + * @param customPluginsList.customPluginsList + * @return CheckboxList */ -const CheckboxList = ({ callback, selectedPlugins, customPluginsList }) => { - - const buildCheckboxItems = () => { - return customPluginsList.map((item, idx) => { - let isSelectedDefault = selectedPlugins[item.slug]; - return ( - - ) - }); - } +const CheckboxList = ( { callback, selectedPlugins, customPluginsList } ) => { + const buildCheckboxItems = () => { + return customPluginsList.map( ( item, idx ) => { + const isSelectedDefault = selectedPlugins[ item.slug ]; + return ( + + ); + } ); + }; - return ( -
-
- {buildCheckboxItems().slice(0, Math.floor(customPluginsList.length/2))} -
-
- {buildCheckboxItems().slice(Math.floor(customPluginsList.length / 2), customPluginsList.length)} -
-
- ); + return ( +
+
+ { buildCheckboxItems().slice( + 0, + Math.floor( customPluginsList.length / 2 ) + ) } +
+
+ { buildCheckboxItems().slice( + Math.floor( customPluginsList.length / 2 ), + customPluginsList.length + ) } +
+
+ ); }; export default CheckboxList; diff --git a/src/OnboardingSPA/data/routes/default-flow.js b/src/OnboardingSPA/data/routes/default-flow.js index a78db5940..b03438063 100644 --- a/src/OnboardingSPA/data/routes/default-flow.js +++ b/src/OnboardingSPA/data/routes/default-flow.js @@ -489,7 +489,10 @@ export const steps = [ { path: '/wp-setup/step/site-pages', title: __( 'Pages', 'wp-module-onboarding' ), - heading: __( "You have ideas, we have page templates", 'wp-module-onboarding' ), + heading: __( + 'You have ideas, we have page templates', + 'wp-module-onboarding' + ), subheading: __( 'Begin closer to the finish line than a blank canvas.', 'wp-module-onboarding' @@ -511,9 +514,12 @@ export const steps = [ { path: '/wp-setup/step/site-features', title: __( 'Features', 'wp-module-onboarding' ), - heading: __( 'Key features to supercharge your site', 'wp-module-onboarding' ), + heading: __( + 'Key features to supercharge your site', + 'wp-module-onboarding' + ), subheading: __( - "Our toolbox of Plugins & Services is your toolbox.", + 'Our toolbox of Plugins & Services is your toolbox.', 'wp-module-onboarding' ), description: __( diff --git a/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js b/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js index b618ffd41..1823996f0 100644 --- a/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js +++ b/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js @@ -11,85 +11,93 @@ import HeadingWithSubHeading from '../../../components/HeadingWithSubHeading'; import CheckboxList from '../../../components/CheckboxTemplate/CheckboxList'; const StepSiteFeatures = () => { - const isLargeViewport = useViewportMatch('medium'); - - const [isLoaded, setisLoaded] = useState(false); - const [selectedPlugins, setSelectedPlugins] = useState(); - const [customPluginsList, setCustomPluginsList] = useState(); - - const { setIsDrawerOpened, setDrawerActiveView, setIsSidebarOpened, setCurrentOnboardingData, setIsDrawerSuppressed } = - useDispatch(nfdOnboardingStore); - - const { currentStep, currentData } = useSelect( - (select) => { - return { - currentStep: select(nfdOnboardingStore).getCurrentStep(), - currentData: select(nfdOnboardingStore).getCurrentOnboardingData(), - }; - }, - [] - ); + const isLargeViewport = useViewportMatch( 'medium' ); + + const [ isLoaded, setisLoaded ] = useState( false ); + const [ selectedPlugins, setSelectedPlugins ] = useState(); + const [ customPluginsList, setCustomPluginsList ] = useState(); + + const { + setIsDrawerOpened, + setDrawerActiveView, + setIsSidebarOpened, + setCurrentOnboardingData, + setIsDrawerSuppressed, + } = useDispatch( nfdOnboardingStore ); - async function selectPlugin(slug, choice) { - let selectedPluginsCopy = {...selectedPlugins}; - if(choice) - selectedPluginsCopy[slug] = true; - else - selectedPluginsCopy[slug] = false; + const { currentStep, currentData } = useSelect( ( select ) => { + return { + currentStep: select( nfdOnboardingStore ).getCurrentStep(), + currentData: + select( nfdOnboardingStore ).getCurrentOnboardingData(), + }; + }, [] ); - currentData.data.siteFeatures = {...selectedPluginsCopy}; - setCurrentOnboardingData(currentData); - setSelectedPlugins(selectedPluginsCopy); + async function selectPlugin( slug, choice ) { + const selectedPluginsCopy = { ...selectedPlugins }; + if ( choice ) selectedPluginsCopy[ slug ] = true; + else selectedPluginsCopy[ slug ] = false; + + currentData.data.siteFeatures = { ...selectedPluginsCopy }; + setCurrentOnboardingData( currentData ); + setSelectedPlugins( selectedPluginsCopy ); } - async function changeToStoreSchema( customPluginsList, saveToStore = false ) { - let selectedPlugins = {}; + async function changeToStoreSchema( + customPluginsList, + saveToStore = false + ) { + const selectedPlugins = {}; - customPluginsList.forEach(plugin => { - selectedPlugins[plugin.slug] = plugin.selected; - }); - setSelectedPlugins(selectedPlugins); + customPluginsList.forEach( ( plugin ) => { + selectedPlugins[ plugin.slug ] = plugin.selected; + } ); + setSelectedPlugins( selectedPlugins ); - if (saveToStore) { + if ( saveToStore ) { currentData.data.siteFeatures = { ...selectedPlugins }; - setCurrentOnboardingData(currentData); + setCurrentOnboardingData( currentData ); } } async function getCustomPlugins() { const customPluginsList = await getCustomPluginsList(); - if (isEmpty(currentData?.data?.siteFeatures)) - changeToStoreSchema(customPluginsList.body, true); - else - setSelectedPlugins({ ...currentData?.data?.siteFeatures }); - - setCustomPluginsList(customPluginsList.body); - setisLoaded(true); + if ( isEmpty( currentData?.data?.siteFeatures ) ) + changeToStoreSchema( customPluginsList.body, true ); + else setSelectedPlugins( { ...currentData?.data?.siteFeatures } ); + + setCustomPluginsList( customPluginsList.body ); + setisLoaded( true ); } - useEffect(() => { - if (!isLoaded) { + useEffect( () => { + if ( ! isLoaded ) { getCustomPlugins(); } - }, [isLoaded]); + }, [ isLoaded ] ); - useEffect(() => { - if (isLargeViewport) { - setIsDrawerOpened(false); + useEffect( () => { + if ( isLargeViewport ) { + setIsDrawerOpened( false ); } - setIsSidebarOpened(false); - setIsDrawerSuppressed(false); - setDrawerActiveView(VIEW_NAV_PRIMARY); - }, []); + setIsSidebarOpened( false ); + setIsDrawerSuppressed( false ); + setDrawerActiveView( VIEW_NAV_PRIMARY ); + }, [] ); return ( - - {customPluginsList && - } + + { customPluginsList && ( + + ) } ); }; diff --git a/src/OnboardingSPA/utils/api/plugins.js b/src/OnboardingSPA/utils/api/plugins.js index d4d9c11f9..2d1d2faa6 100644 --- a/src/OnboardingSPA/utils/api/plugins.js +++ b/src/OnboardingSPA/utils/api/plugins.js @@ -33,8 +33,8 @@ export const getPluginStatus = async ( plugin ) => { export const getCustomPluginsList = async () => { return await resolve( - apiFetch({ - url: onboardingRestURL('features'), - }) + apiFetch( { + url: onboardingRestURL( 'features' ), + } ) ); }; From 7e3fbfe1ee0687c4e9793fbe51dd33a3b9f2b73f Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Thu, 1 Dec 2022 12:13:50 +0530 Subject: [PATCH 28/49] Update index.js --- src/OnboardingSPA/pages/Steps/SiteFeatures/index.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js b/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js index 1823996f0..806ad65e4 100644 --- a/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js +++ b/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js @@ -35,12 +35,11 @@ const StepSiteFeatures = () => { async function selectPlugin( slug, choice ) { const selectedPluginsCopy = { ...selectedPlugins }; - if ( choice ) selectedPluginsCopy[ slug ] = true; - else selectedPluginsCopy[ slug ] = false; - + selectedPluginsCopy[ slug ] = choice; + setSelectedPlugins( selectedPluginsCopy ); + currentData.data.siteFeatures = { ...selectedPluginsCopy }; setCurrentOnboardingData( currentData ); - setSelectedPlugins( selectedPluginsCopy ); } async function changeToStoreSchema( From f59437e0ae9a2ed781cfc47ee839efafb5574f6f Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Thu, 1 Dec 2022 12:51:29 +0530 Subject: [PATCH 29/49] Removed SiteFeaturesController --- includes/RestApi/PluginsController.php | 26 ++++++++-- includes/RestApi/RestApi.php | 1 - includes/RestApi/SiteFeaturesController.php | 54 --------------------- src/OnboardingSPA/utils/api/plugins.js | 2 +- 4 files changed, 24 insertions(+), 59 deletions(-) delete mode 100644 includes/RestApi/SiteFeaturesController.php diff --git a/includes/RestApi/PluginsController.php b/includes/RestApi/PluginsController.php index 2af81b74c..55a98ce28 100644 --- a/includes/RestApi/PluginsController.php +++ b/includes/RestApi/PluginsController.php @@ -1,16 +1,14 @@ namespace, + $this->rest_base . '/features', + array( + array( + 'methods' => \WP_REST_Server::READABLE, + 'callback' => array( $this, 'get_custom_plugins' ), + 'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), + ), + ) + ); + \register_rest_route( $this->namespace, $this->rest_base . '/uninstall', @@ -269,6 +279,16 @@ public function get_status( \WP_REST_Request $request ) { } + /** + * Retrieves the Customized list of Plugins for the user. + * + * @return array|\WP_Error + */ + public function get_custom_plugins() { + $custom_plugins = SiteFeatures::get_custom_plugins_list(); + return $custom_plugins; + } + /** * Installs/Uninstalls the requested plugins. * diff --git a/includes/RestApi/RestApi.php b/includes/RestApi/RestApi.php index 1b4791712..d01fb545f 100644 --- a/includes/RestApi/RestApi.php +++ b/includes/RestApi/RestApi.php @@ -18,7 +18,6 @@ final class RestApi { 'NewfoldLabs\\WP\\Module\\Onboarding\\RestApi\\SettingsController', 'NewfoldLabs\\WP\\Module\\Onboarding\\RestApi\\EventsController', 'NewfoldLabs\\WP\\Module\\Onboarding\\RestApi\\PagesController', - 'NewfoldLabs\WP\\Module\\Onboarding\\RestApi\\SiteFeaturesController', 'NewfoldLabs\WP\\Module\\Onboarding\\RestApi\\Themes\\ThemeInstallerController', 'NewfoldLabs\WP\\Module\\Onboarding\\RestApi\\Themes\\ThemeFontsController', 'NewfoldLabs\WP\\Module\\Onboarding\\RestApi\\Themes\\ThemeColorsController' diff --git a/includes/RestApi/SiteFeaturesController.php b/includes/RestApi/SiteFeaturesController.php deleted file mode 100644 index c5c48508a..000000000 --- a/includes/RestApi/SiteFeaturesController.php +++ /dev/null @@ -1,54 +0,0 @@ -namespace, - $this->rest_base, - array( - array( - 'methods' => \WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_custom_plugins' ), - 'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), - ), - ) - ); - } - - /** - * Retrieves the Customized list of Plugins for the user. - * - * @return array|\WP_Error - */ - public function get_custom_plugins() { - $custom_plugins = SiteFeatures::get_custom_plugins_list(); - return $custom_plugins; - } -} diff --git a/src/OnboardingSPA/utils/api/plugins.js b/src/OnboardingSPA/utils/api/plugins.js index 2d1d2faa6..293023086 100644 --- a/src/OnboardingSPA/utils/api/plugins.js +++ b/src/OnboardingSPA/utils/api/plugins.js @@ -34,7 +34,7 @@ export const getPluginStatus = async ( plugin ) => { export const getCustomPluginsList = async () => { return await resolve( apiFetch( { - url: onboardingRestURL( 'features' ), + url: onboardingRestURL( 'plugins/features' ), } ) ); }; From 440b08bf828b89bcea0ceaac25835cdf43273ed9 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Thu, 1 Dec 2022 15:49:59 +0530 Subject: [PATCH 30/49] Added a Fix for Dirty Read --- includes/RestApi/PluginsController.php | 2 +- includes/TaskManagers/PluginInstallTaskManager.php | 14 +++++++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/includes/RestApi/PluginsController.php b/includes/RestApi/PluginsController.php index 55a98ce28..e7867a41a 100644 --- a/includes/RestApi/PluginsController.php +++ b/includes/RestApi/PluginsController.php @@ -312,7 +312,7 @@ public function uninstall( \WP_REST_Request $request ) { ); } else { $position_in_queue = PluginInstallTaskManager::status( $plugin ); - if ( $position_in_queue === false ) { + if ( $position_in_queue === false || $position_in_queue === 0 ) { PluginUninstallTaskManager::add_to_queue( new PluginUninstallTask( $plugin, diff --git a/includes/TaskManagers/PluginInstallTaskManager.php b/includes/TaskManagers/PluginInstallTaskManager.php index b7916a9a4..ed2058005 100644 --- a/includes/TaskManagers/PluginInstallTaskManager.php +++ b/includes/TaskManagers/PluginInstallTaskManager.php @@ -95,6 +95,9 @@ public function install() { priority at the beginning of the array */ $plugin_to_install = array_shift( $plugins ); + // Update the plugin install queue. + \update_option( Options::get_option_name( self::$queue_name ), $plugins ); + // Recreate the PluginInstall task from the associative array. $plugin_install_task = new PluginInstallTask( $plugin_to_install['slug'], @@ -113,21 +116,26 @@ public function install() { // If there is an error, then increase the retry count for the task. $plugin_install_task->increment_retries(); + // Get Latest Value of the install queue + $plugins = \get_option( Options::get_option_name( self::$queue_name ), array() ); + /* If the number of retries have not exceeded the limit then re-queue the task at the end of the queue to be retried. */ if ( $plugin_install_task->get_retries() <= self::$retry_limit ) { array_push( $plugins, $plugin_install_task->to_array() ); + + // Update the plugin install queue. + \update_option( Options::get_option_name( self::$queue_name ), $plugins ); } } // If there are no more plugins to be installed then change the status to completed. if ( empty( $plugins ) ) { - \update_option( Options::get_option_name( 'plugins_init_status' ), 'completed' ); + return \update_option( Options::get_option_name( 'plugins_init_status' ), 'completed' ); } - // Update the plugin install queue. - return \update_option( Options::get_option_name( self::$queue_name ), $plugins ); + return true; } /** From 987bc95683b7e33ee079f6757dd06fbaaebaef71 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Thu, 1 Dec 2022 16:04:11 +0530 Subject: [PATCH 31/49] Update PluginInstallTaskManager.php --- includes/TaskManagers/PluginInstallTaskManager.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/includes/TaskManagers/PluginInstallTaskManager.php b/includes/TaskManagers/PluginInstallTaskManager.php index ed2058005..c03014281 100644 --- a/includes/TaskManagers/PluginInstallTaskManager.php +++ b/includes/TaskManagers/PluginInstallTaskManager.php @@ -123,10 +123,10 @@ public function install() { If the number of retries have not exceeded the limit then re-queue the task at the end of the queue to be retried. */ if ( $plugin_install_task->get_retries() <= self::$retry_limit ) { - array_push( $plugins, $plugin_install_task->to_array() ); + array_push( $plugins, $plugin_install_task->to_array() ); - // Update the plugin install queue. - \update_option( Options::get_option_name( self::$queue_name ), $plugins ); + // Update the plugin install queue. + \update_option( Options::get_option_name( self::$queue_name ), $plugins ); } } From e201bfe09ee8ec124d5504f470df61ded60210b2 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Fri, 2 Dec 2022 10:51:56 +0530 Subject: [PATCH 32/49] Update PluginUninstallTaskManager.php --- .../TaskManagers/PluginUninstallTaskManager.php | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/includes/TaskManagers/PluginUninstallTaskManager.php b/includes/TaskManagers/PluginUninstallTaskManager.php index 8cf1541a5..025292fb1 100644 --- a/includes/TaskManagers/PluginUninstallTaskManager.php +++ b/includes/TaskManagers/PluginUninstallTaskManager.php @@ -64,6 +64,9 @@ public function uninstall() { priority at the beginning of the array */ $plugin_to_uninstall = array_shift( $plugins ); + // Update the plugin uninstall queue. + \update_option( Options::get_option_name( self::$queue_name ), $plugins ); + // Recreate the PluginInstall task from the associative array. $plugin_uninstall_task = new PluginUninstallTask( $plugin_to_uninstall['slug'], @@ -85,17 +88,19 @@ public function uninstall() { If the number of retries have not exceeded the limit then re-queue the task at the end of the queue to be retried. */ if ( $plugin_uninstall_task->get_retries() <= self::$retry_limit ) { - array_push( $plugins, $plugin_uninstall_task->to_array() ); + array_push( $plugins, $plugin_uninstall_task->to_array() ); + + // Update the plugin install queue. + \update_option( Options::get_option_name( self::$queue_name ), $plugins ); } } // If there are no more plugins to be installed then change the status to completed. if ( empty( $plugins ) ) { - \update_option( Options::get_option_name( 'plugins_uninit_status' ), 'completed' ); + return \update_option( Options::get_option_name( 'plugins_uninit_status' ), 'completed' ); } - // Update the plugin uninstall queue. - return \update_option( Options::get_option_name( self::$queue_name ), $plugins ); + return true; } /** From 23484339f9b987735f29e1d43e4a41440e1c0d8b Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Mon, 5 Dec 2022 11:14:15 +0530 Subject: [PATCH 33/49] CSS Tweaks --- .../CheckboxItem/stylesheet.scss | 39 +++++++++++-------- .../CheckboxList/stylesheet.scss | 4 ++ 2 files changed, 26 insertions(+), 17 deletions(-) diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss index f728feb0a..2595f1cb9 100644 --- a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss @@ -1,11 +1,17 @@ +/*COLOR VARIABLES*/ +$white-offset: rgb(224, 224, 224); +$main-color-dark: var(--wp-admin-theme-color); +$main-color-light: var(--nfd-onboarding-white); +$main-color: var(--nfd-onboarding-highlighted--rgb); +$main-border-main: var(--nfd-onboarding-primary-alt); + .checkbox-item { - width: 23vw; margin: 12px; padding: 16px; - min-width: 300px; border-radius: 2px; - background: #FFFFFF; - border: 1px solid #E0E0E0; + background: $main-color-light; + border: 1px solid $white-offset; + width: clamp(15rem, 25vw, 35rem); box-shadow: 0px 2px 8px 2px rgba(204, 204, 204, 0.175295); &-container{ @@ -38,7 +44,7 @@ justify-content: center; &--selected { - background: #1C5CBA; + background: $main-color-dark !important; } &--shown { @@ -54,21 +60,21 @@ justify-content: center; &-title{ - font-size: 16px; color: #0D0D0D; line-height: 18px; margin-bottom: 6px; + font-size: clamp(0.9rem, 2vw, 1rem); &--selected { - color: #1C5CBA; + color: $main-color-dark; } } &-subtitle { - font-size: 14px; + color: #343434; font-weight: 200; line-height: 18px; - color: #343434; + font-size: clamp(0.82rem, 2vw, 0.9rem); } } @@ -79,22 +85,21 @@ } &--selected { - border: 1px solid #97C8FA; - background: rgba(132, 192, 252, 0.2); - box-shadow: 0px 2px 8px 2px rgba(204, 204, 204, 0.175295); + background: rgba($main-color, 0.2); + border: 1px solid rgba($main-color, 0.6); + box-shadow: 0px 2px 8px 2px rgba($white-offset, 0.8); } &--shown { - z-index: 9999; border-radius: 2px; - background: #E2E9F4; - border: 1px solid #CADFE7; - box-shadow: 0px 11px 8px -3px rgba(88, 124, 175, 0.37); + background: rgba($white-offset, 0.2); + border: 1px solid rgba($main-color, 0.1); + box-shadow: 0px 11px 8px -3px rgba($main-color, 0.20); } &__desc { - font-size: 14px; margin-top: 20px; font-style: italic; + font-size: clamp(0.82rem, 2vw, 0.9rem); } } \ No newline at end of file diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/stylesheet.scss b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/stylesheet.scss index 711c11bb6..564491c4a 100644 --- a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/stylesheet.scss +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/stylesheet.scss @@ -3,6 +3,10 @@ align-items: center; justify-content: center; + @media (max-width: #{ ($break-xlarge) }) { + flex-direction: column; + } + &-col { display: flex; align-items: center; From affd33fee6a0370b94b6514516535aea69545fe0 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Mon, 5 Dec 2022 14:22:13 +0530 Subject: [PATCH 34/49] CSS Styles to Fix Overlap --- .../CheckboxTemplate/CheckboxItem/index.js | 120 +++++++++--------- .../CheckboxItem/stylesheet.scss | 28 +++- 2 files changed, 81 insertions(+), 67 deletions(-) diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js index fed89a655..8107cd8b9 100644 --- a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js @@ -37,74 +37,72 @@ const CheckboxItem = ( { }; return ( -
-
- -
-
+
+
+
+ +
-
-
-
- { title } +
-
- { subtitle } +
+
+ {title} +
+
+ {subtitle} +
+
+
+
-
-
-
- { showDescription && ( -
{ desc }
- ) } + { + showDescription && ( +
{desc}
+ ) + }
); }; diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss index 2595f1cb9..88c2b4bd3 100644 --- a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss @@ -8,7 +8,7 @@ $main-border-main: var(--nfd-onboarding-primary-alt); .checkbox-item { margin: 12px; padding: 16px; - border-radius: 2px; + margin-top: 20px; background: $main-color-light; border: 1px solid $white-offset; width: clamp(15rem, 25vw, 35rem); @@ -91,15 +91,31 @@ $main-border-main: var(--nfd-onboarding-primary-alt); } &--shown { - border-radius: 2px; - background: rgba($white-offset, 0.2); - border: 1px solid rgba($main-color, 0.1); - box-shadow: 0px 11px 8px -3px rgba($main-color, 0.20); + border-bottom: none; + border-radius: 2px 2px 0px 0px; + background: rgba($white-offset, 0.8); + border-top: 1px solid rgba($main-color, 0.1); + border-left: 1px solid rgba($main-color, 0.1); + border-right: 1px solid rgba($main-color, 0.1); } &__desc { - margin-top: 20px; + z-index: 2; + padding: 16px; + border-top: none; + margin-left: 12px; + margin-top: -12px; + position: absolute; font-style: italic; + border-radius: 0px 0px 2px 2px; + transform-origin: top center; + width: clamp(15rem, 25vw, 35rem); + background: rgba($white-offset, 0.8); font-size: clamp(0.82rem, 2vw, 0.9rem); + border-left: 1px solid rgba($main-color, 0.1); + border-right: 1px solid rgba($main-color, 0.1); + border-bottom: 1px solid rgba($main-color, 0.1); + animation: dropdown 400ms ease-in-out forwards; + box-shadow: 0px 11px 8px -3px rgba($main-color, 0.20); } } \ No newline at end of file From 8d60645a3cdff7db414ab79ad684269ed170bbc8 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Mon, 5 Dec 2022 14:49:32 +0530 Subject: [PATCH 35/49] Some Review Comments --- includes/Data/Options.php | 1 - includes/Data/SiteFeatures.php | 176 +++++++++--------- .../PluginUninstallTaskManager.php | 8 - 3 files changed, 91 insertions(+), 94 deletions(-) diff --git a/includes/Data/Options.php b/includes/Data/Options.php index 22ab04df3..a19fb9fc6 100644 --- a/includes/Data/Options.php +++ b/includes/Data/Options.php @@ -30,7 +30,6 @@ final class Options { 'settings_initialized' => 'settings_initialized', 'plugins_init_status' => 'plugins_init_status', 'plugin_install_queue' => 'plugin_install_queue', - 'plugins_uninit_status' => 'plugins_uninit_status', 'plugin_uninstall_queue' => 'plugin_uninstall_queue', 'flow' => 'flow', 'theme_init_status' => 'theme_init_status', diff --git a/includes/Data/SiteFeatures.php b/includes/Data/SiteFeatures.php index 2ff419160..df214cf11 100644 --- a/includes/Data/SiteFeatures.php +++ b/includes/Data/SiteFeatures.php @@ -7,93 +7,97 @@ final class SiteFeatures { protected static $default_plugins = array( - array( - 'slug' => 'jetpack', - 'icon' => '--site-features-security', - 'title' => 'Security, Speed & Growth', - 'subtitle' => 'Powered by Jetpack', - 'desc' => 'Jetpack', - 'selected' => false, - ), - array( - 'slug' => 'wpforms-lite', - 'icon' => '--site-features-form', - 'title' => 'Forms', - 'subtitle' => 'Powered by WP Forms', - 'desc' => 'WP Forms', - 'selected' => false, - ), - array( - 'slug' => 'google-analytics-for-wordpress', - 'icon' => '--site-features-analytics', - 'title' => 'Site Traffic', - 'subtitle' => 'Powered by MonsterInsights', - 'desc' => 'MonsterInsights', - 'selected' => false, - ), - array( - 'slug' => 'wordpress-seo', - 'icon' => '--site-features-share', - 'title' => 'Search Engine Optimization', - 'subtitle' => 'Powered by Yoast', - 'desc' => 'Yoast', - 'selected' => false, - ), - array( - 'slug' => 'creative-mail-by-constant-contact', - 'icon' => '--site-features-email', - 'title' => 'Email Newsletters', - 'subtitle' => 'Powered by Creative Email', - 'desc' => 'Creative Email', - 'selected' => false, - ), - array( - 'slug' => 'yith-woocommerce-ajax-search', - 'icon' => '--site-features-search', - 'title' => 'Enhanced Product Search', - 'subtitle' => 'Powered by YITH', - 'desc' => 'YITH', - 'selected' => false, - ), - array( - 'slug' => 'nfd_slug_yith_woocommerce_ajax_product_filter', - 'icon' => '--site-features-filter', - 'title' => 'Enhanced Product Filters', - 'subtitle' => 'Powered by YITH', - 'desc' => 'YITH', - 'selected' => false, - ), - array( - 'slug' => 'nfd_slug_yith_woocommerce_booking', - 'icon' => '--site-features-bookingcalendar', - 'title' => 'Bookings & Appointments', - 'subtitle' => 'Powered by YITH', - 'desc' => 'YITH', - 'selected' => false, - ), - array( - 'slug' => 'nfd_slug_yith_woocommerce_wishlist', - 'icon' => '--site-features-wishlist', - 'title' => 'Product Wishlists', - 'subtitle' => 'Powered by YITH', - 'desc' => 'YITH', - 'selected' => false, - ), - array( - 'slug' => 'optinmonster', - 'icon' => '--site-features-lead', - 'title' => 'Lead Generation', - 'subtitle' => 'Powered by Optin Monster', - 'desc' => 'Optin Monster', - 'selected' => false, - ), + 'default' => array(), + 'ecommerce' => array( + array( + 'slug' => 'jetpack', + 'icon' => '--site-features-security', + 'title' => 'Security, Speed & Growth', + 'subtitle' => 'Powered by Jetpack', + 'desc' => 'Jetpack', + 'selected' => false, + ), + array( + 'slug' => 'wpforms-lite', + 'icon' => '--site-features-form', + 'title' => 'Forms', + 'subtitle' => 'Powered by WP Forms', + 'desc' => 'WP Forms', + 'selected' => false, + ), + array( + 'slug' => 'google-analytics-for-wordpress', + 'icon' => '--site-features-analytics', + 'title' => 'Site Traffic', + 'subtitle' => 'Powered by MonsterInsights', + 'desc' => 'MonsterInsights', + 'selected' => false, + ), + array( + 'slug' => 'wordpress-seo', + 'icon' => '--site-features-share', + 'title' => 'Search Engine Optimization', + 'subtitle' => 'Powered by Yoast', + 'desc' => 'Yoast', + 'selected' => false, + ), + array( + 'slug' => 'creative-mail-by-constant-contact', + 'icon' => '--site-features-email', + 'title' => 'Email Newsletters', + 'subtitle' => 'Powered by Creative Email', + 'desc' => 'Creative Email', + 'selected' => false, + ), + array( + 'slug' => 'yith-woocommerce-ajax-search', + 'icon' => '--site-features-search', + 'title' => 'Enhanced Product Search', + 'subtitle' => 'Powered by YITH', + 'desc' => 'YITH', + 'selected' => false, + ), + array( + 'slug' => 'nfd_slug_yith_woocommerce_ajax_product_filter', + 'icon' => '--site-features-filter', + 'title' => 'Enhanced Product Filters', + 'subtitle' => 'Powered by YITH', + 'desc' => 'YITH', + 'selected' => false, + ), + array( + 'slug' => 'nfd_slug_yith_woocommerce_booking', + 'icon' => '--site-features-bookingcalendar', + 'title' => 'Bookings & Appointments', + 'subtitle' => 'Powered by YITH', + 'desc' => 'YITH', + 'selected' => false, + ), + array( + 'slug' => 'nfd_slug_yith_woocommerce_wishlist', + 'icon' => '--site-features-wishlist', + 'title' => 'Product Wishlists', + 'subtitle' => 'Powered by YITH', + 'desc' => 'YITH', + 'selected' => false, + ), + array( + 'slug' => 'optinmonster', + 'icon' => '--site-features-lead', + 'title' => 'Lead Generation', + 'subtitle' => 'Powered by Optin Monster', + 'desc' => 'Optin Monster', + 'selected' => false, + ), + ) ); public static function convert_to_hash() { $idx = 0; + $flow = Data::current_flow(); $default_plugins_hash = array(); - foreach ( self::$default_plugins as $default_plugin ) { + foreach ( self::$default_plugins[$flow] as $default_plugin ) { $default_plugins_hash[ $default_plugin['slug'] ] = $idx; $idx += 1; } @@ -101,7 +105,8 @@ public static function convert_to_hash() { return $default_plugins_hash; } - public static function mark_installed_plugins() { + public static function mark_initial_plugins() { + $flow = Data::current_flow(); $installed_plugins = Plugins::get_init(); // Make an Hash Map for faster updation @@ -109,7 +114,7 @@ public static function mark_installed_plugins() { foreach ( $installed_plugins as $installed_plugin ) { if ( isset( $default_plugins_hash[ $installed_plugin['slug'] ] ) ) { - self::$default_plugins[ $default_plugins_hash[ $installed_plugin['slug'] ] ]['selected'] = true; + self::$default_plugins[$flow][ $default_plugins_hash[ $installed_plugin['slug'] ] ]['selected'] = true; } } @@ -117,8 +122,9 @@ public static function mark_installed_plugins() { public static function get_default_plugins_list() { - self::mark_installed_plugins(); - return self::$default_plugins; + $flow = Data::current_flow(); + self::mark_initial_plugins(); + return self::$default_plugins[$flow]; } public static function get_custom_plugins_list() { diff --git a/includes/TaskManagers/PluginUninstallTaskManager.php b/includes/TaskManagers/PluginUninstallTaskManager.php index 025292fb1..785484322 100644 --- a/includes/TaskManagers/PluginUninstallTaskManager.php +++ b/includes/TaskManagers/PluginUninstallTaskManager.php @@ -74,9 +74,6 @@ public function uninstall() { $plugin_to_uninstall['retries'] ); - // Update status to the current slug being installed. - \update_option( Options::get_option_name( 'plugins_uninit_status' ), $plugin_uninstall_task->get_slug() ); - // Execute the PluginUninstall Task. $status = $plugin_uninstall_task->execute(); if ( \is_wp_error( $status ) ) { @@ -95,11 +92,6 @@ public function uninstall() { } } - // If there are no more plugins to be installed then change the status to completed. - if ( empty( $plugins ) ) { - return \update_option( Options::get_option_name( 'plugins_uninit_status' ), 'completed' ); - } - return true; } From 07a540e0c07ec72981a0682a944641ca4f7be83e Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Mon, 5 Dec 2022 17:43:46 +0530 Subject: [PATCH 36/49] Code Reviewz --- includes/Data/SiteFeatures.php | 62 +++++++------------ includes/RestApi/PluginsController.php | 9 ++- includes/Services/PluginUninstaller.php | 6 +- .../CheckboxTemplate/CheckboxItem/index.js | 9 +-- .../CheckboxTemplate/CheckboxList/index.js | 46 ++++++++------ .../pages/Steps/SiteFeatures/index.js | 15 ++--- src/OnboardingSPA/utils/api/plugins.js | 4 +- 7 files changed, 70 insertions(+), 81 deletions(-) diff --git a/includes/Data/SiteFeatures.php b/includes/Data/SiteFeatures.php index df214cf11..9d0f50f32 100644 --- a/includes/Data/SiteFeatures.php +++ b/includes/Data/SiteFeatures.php @@ -6,10 +6,10 @@ final class SiteFeatures { - protected static $default_plugins = array( - 'default' => array(), + protected static $site_features = array( + 'default' => array(), 'ecommerce' => array( - array( + 'jetpack' => array( 'slug' => 'jetpack', 'icon' => '--site-features-security', 'title' => 'Security, Speed & Growth', @@ -17,7 +17,7 @@ final class SiteFeatures { 'desc' => 'Jetpack', 'selected' => false, ), - array( + 'wpforms-lite' => array( 'slug' => 'wpforms-lite', 'icon' => '--site-features-form', 'title' => 'Forms', @@ -25,7 +25,7 @@ final class SiteFeatures { 'desc' => 'WP Forms', 'selected' => false, ), - array( + 'google-analytics-for-wordpress' => array( 'slug' => 'google-analytics-for-wordpress', 'icon' => '--site-features-analytics', 'title' => 'Site Traffic', @@ -33,7 +33,7 @@ final class SiteFeatures { 'desc' => 'MonsterInsights', 'selected' => false, ), - array( + 'wordpress-seo' => array( 'slug' => 'wordpress-seo', 'icon' => '--site-features-share', 'title' => 'Search Engine Optimization', @@ -41,7 +41,7 @@ final class SiteFeatures { 'desc' => 'Yoast', 'selected' => false, ), - array( + 'creative-mail-by-constant-contact' => array( 'slug' => 'creative-mail-by-constant-contact', 'icon' => '--site-features-email', 'title' => 'Email Newsletters', @@ -49,7 +49,7 @@ final class SiteFeatures { 'desc' => 'Creative Email', 'selected' => false, ), - array( + 'yith-woocommerce-ajax-search' => array( 'slug' => 'yith-woocommerce-ajax-search', 'icon' => '--site-features-search', 'title' => 'Enhanced Product Search', @@ -57,7 +57,7 @@ final class SiteFeatures { 'desc' => 'YITH', 'selected' => false, ), - array( + 'nfd_slug_yith_woocommerce_ajax_product_filter' => array( 'slug' => 'nfd_slug_yith_woocommerce_ajax_product_filter', 'icon' => '--site-features-filter', 'title' => 'Enhanced Product Filters', @@ -65,7 +65,7 @@ final class SiteFeatures { 'desc' => 'YITH', 'selected' => false, ), - array( + 'nfd_slug_yith_woocommerce_booking' => array( 'slug' => 'nfd_slug_yith_woocommerce_booking', 'icon' => '--site-features-bookingcalendar', 'title' => 'Bookings & Appointments', @@ -73,7 +73,7 @@ final class SiteFeatures { 'desc' => 'YITH', 'selected' => false, ), - array( + 'nfd_slug_yith_woocommerce_wishlist' => array( 'slug' => 'nfd_slug_yith_woocommerce_wishlist', 'icon' => '--site-features-wishlist', 'title' => 'Product Wishlists', @@ -81,7 +81,7 @@ final class SiteFeatures { 'desc' => 'YITH', 'selected' => false, ), - array( + 'optinmonster' => array( 'slug' => 'optinmonster', 'icon' => '--site-features-lead', 'title' => 'Lead Generation', @@ -89,47 +89,27 @@ final class SiteFeatures { 'desc' => 'Optin Monster', 'selected' => false, ), - ) + ), ); - public static function convert_to_hash() { - $idx = 0; - $flow = Data::current_flow(); - $default_plugins_hash = array(); - - foreach ( self::$default_plugins[$flow] as $default_plugin ) { - $default_plugins_hash[ $default_plugin['slug'] ] = $idx; - $idx += 1; - } - - return $default_plugins_hash; - } - public static function mark_initial_plugins() { - $flow = Data::current_flow(); + $flow = Data::current_flow(); $installed_plugins = Plugins::get_init(); - // Make an Hash Map for faster updation - $default_plugins_hash = self::convert_to_hash(); + // Get a Copy of the list for alteration + $site_features_marked = self::$site_features[ $flow ]; foreach ( $installed_plugins as $installed_plugin ) { - if ( isset( $default_plugins_hash[ $installed_plugin['slug'] ] ) ) { - self::$default_plugins[$flow][ $default_plugins_hash[ $installed_plugin['slug'] ] ]['selected'] = true; + if ( isset( $site_features_marked[ $installed_plugin['slug'] ] ) ) { + $site_features_marked[ $installed_plugin['slug'] ]['selected'] = true; } } + return $site_features_marked; } - - public static function get_default_plugins_list() { - $flow = Data::current_flow(); - self::mark_initial_plugins(); - return self::$default_plugins[$flow]; - } - - public static function get_custom_plugins_list() { - - return self::get_default_plugins_list(); + public static function get() { + return self::mark_initial_plugins(); } } diff --git a/includes/RestApi/PluginsController.php b/includes/RestApi/PluginsController.php index e7867a41a..543ffabcb 100644 --- a/includes/RestApi/PluginsController.php +++ b/includes/RestApi/PluginsController.php @@ -83,11 +83,11 @@ public function register_routes() { \register_rest_route( $this->namespace, - $this->rest_base . '/features', + $this->rest_base . '/site-features', array( array( 'methods' => \WP_REST_Server::READABLE, - 'callback' => array( $this, 'get_custom_plugins' ), + 'callback' => array( $this, 'get_site_features' ), 'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), ), ) @@ -284,9 +284,8 @@ public function get_status( \WP_REST_Request $request ) { * * @return array|\WP_Error */ - public function get_custom_plugins() { - $custom_plugins = SiteFeatures::get_custom_plugins_list(); - return $custom_plugins; + public function get_site_features() { + return SiteFeatures::get(); } /** diff --git a/includes/Services/PluginUninstaller.php b/includes/Services/PluginUninstaller.php index 3cb6b43ec..4ee535096 100644 --- a/includes/Services/PluginUninstaller.php +++ b/includes/Services/PluginUninstaller.php @@ -19,11 +19,11 @@ public static function uninstall( $plugin ) { if ( isset( $plugin_path ) && self::is_plugin_installed( $plugin_path ) ) { self::deactivate_plugin_if_active( $plugin_path ); - $res = self::delete_plugin( $plugin_path ); + $deleted = self::delete_plugin( $plugin_path ); // If Deletion is not successful throw an error for a retry. - if ( is_wp_error( $res ) ) { - return $res; + if ( is_wp_error( $deleted ) ) { + return $deleted; } } diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js index 8107cd8b9..2512d7153 100644 --- a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js @@ -16,11 +16,12 @@ import { CheckboxControl } from '@wordpress/components'; */ const CheckboxItem = ( { - slug, + key, icon, title, - subtitle, desc, + subtitle, + className, isSelectedDefault, callback, } ) => { @@ -29,7 +30,7 @@ const CheckboxItem = ( { const handleCheck = () => { setIsSelected( ! isSelected ); - callback( slug, ! isSelected ); + callback( key, ! isSelected ); }; const handleShowDesc = () => { @@ -39,7 +40,7 @@ const CheckboxItem = ( { return (
diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/index.js b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/index.js index e66b855a8..d4329618b 100644 --- a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/index.js +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/index.js @@ -4,29 +4,37 @@ import { CheckboxItem } from '../index'; * Checkbox List Component * This returns a List of Checkbox Items to be placed dynamically on screen * - * @param customPluginsList.callback - * @param {Object} customPluginsList - The List to be shown with a Title, Subtitle and a Description + * @param customItemsList.callback + * @param {Object} customItemsList - The List to be shown with a Title, Subtitle and a Description * - * @param customPluginsList.selectedPlugins - * @param customPluginsList.customPluginsList + * @param customItemsList.selectedItems + * @param customItemsList.customItemsList * @return CheckboxList */ -const CheckboxList = ( { callback, selectedPlugins, customPluginsList } ) => { +const CheckboxList = ( { callback, selectedItems, customItemsList } ) => { + + const length = Object.keys(customItemsList).length; + const buildCheckboxItems = () => { - return customPluginsList.map( ( item, idx ) => { - const isSelectedDefault = selectedPlugins[ item.slug ]; - return ( + var customItems = []; + + for (const key in customItemsList) { + var item = customItemsList[key]; + const isSelectedDefault = selectedItems[item.slug]; + customItems.push( ); - } ); + } + + return customItems; }; return ( @@ -34,13 +42,13 @@ const CheckboxList = ( { callback, selectedPlugins, customPluginsList } ) => {
{ buildCheckboxItems().slice( 0, - Math.floor( customPluginsList.length / 2 ) + Math.floor( length / 2 ) ) }
{ buildCheckboxItems().slice( - Math.floor( customPluginsList.length / 2 ), - customPluginsList.length + Math.floor( length / 2 ), + length ) }
diff --git a/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js b/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js index 806ad65e4..d5947bc75 100644 --- a/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js +++ b/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js @@ -6,7 +6,7 @@ import { store as nfdOnboardingStore } from '../../../store'; import { VIEW_NAV_PRIMARY } from '../../../../constants'; import CommonLayout from '../../../components/Layouts/Common'; -import { getCustomPluginsList } from '../../../utils/api/plugins'; +import { getSiteFeatures } from '../../../utils/api/plugins'; import HeadingWithSubHeading from '../../../components/HeadingWithSubHeading'; import CheckboxList from '../../../components/CheckboxTemplate/CheckboxList'; @@ -48,9 +48,10 @@ const StepSiteFeatures = () => { ) { const selectedPlugins = {}; - customPluginsList.forEach( ( plugin ) => { - selectedPlugins[ plugin.slug ] = plugin.selected; - } ); + for (const key in customPluginsList) { + var plugin = customPluginsList[key]; + selectedPlugins[plugin.slug] = plugin.selected; + } setSelectedPlugins( selectedPlugins ); if ( saveToStore ) { @@ -60,7 +61,7 @@ const StepSiteFeatures = () => { } async function getCustomPlugins() { - const customPluginsList = await getCustomPluginsList(); + const customPluginsList = await getSiteFeatures(); if ( isEmpty( currentData?.data?.siteFeatures ) ) changeToStoreSchema( customPluginsList.body, true ); else setSelectedPlugins( { ...currentData?.data?.siteFeatures } ); @@ -93,8 +94,8 @@ const StepSiteFeatures = () => { { customPluginsList && ( ) } diff --git a/src/OnboardingSPA/utils/api/plugins.js b/src/OnboardingSPA/utils/api/plugins.js index 293023086..7716ad275 100644 --- a/src/OnboardingSPA/utils/api/plugins.js +++ b/src/OnboardingSPA/utils/api/plugins.js @@ -31,10 +31,10 @@ export const getPluginStatus = async ( plugin ) => { ); }; -export const getCustomPluginsList = async () => { +export const getSiteFeatures = async () => { return await resolve( apiFetch( { - url: onboardingRestURL( 'plugins/features' ), + url: onboardingRestURL( 'plugins/site-features' ), } ) ); }; From d7f598b6c0a8a2c075f237d30db80e507b40b457 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Mon, 5 Dec 2022 17:53:27 +0530 Subject: [PATCH 37/49] Added Classname option --- .../CheckboxTemplate/CheckboxItem/index.js | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js index 2512d7153..b7bd09438 100644 --- a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js @@ -21,9 +21,9 @@ const CheckboxItem = ( { title, desc, subtitle, - className, - isSelectedDefault, callback, + isSelectedDefault, + className = 'checkbox-item', } ) => { const [ showDescription, setShowDescription ] = useState( false ); const [ isSelected, setIsSelected ] = useState( isSelectedDefault ); @@ -40,23 +40,23 @@ const CheckboxItem = ( { return (
-
+
-
+
-
+
{title}
-
+
{subtitle}
{ showDescription && ( -
{desc}
+
{desc}
) }
From 6075671906bcf7757042ed4bf4bfe0b1d20eb39d Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Mon, 5 Dec 2022 19:41:40 +0530 Subject: [PATCH 38/49] Update PluginsController.php --- includes/RestApi/PluginsController.php | 54 ++++++++++++++------------ 1 file changed, 30 insertions(+), 24 deletions(-) diff --git a/includes/RestApi/PluginsController.php b/includes/RestApi/PluginsController.php index 543ffabcb..84a453ac8 100644 --- a/includes/RestApi/PluginsController.php +++ b/includes/RestApi/PluginsController.php @@ -300,32 +300,38 @@ public function uninstall( \WP_REST_Request $request ) { $plugin_body = json_decode( $request->get_body(), true ); $plugins = isset( $plugin_body['plugins'] ) ? $plugin_body['plugins'] : false; - if ( $plugins ) { - foreach ( $plugins as $plugin => $decision ) { - if ( $decision ) { - PluginInstallTaskManager::add_to_queue( - new PluginInstallTask( - $plugin, - true, - ) - ); - } else { - $position_in_queue = PluginInstallTaskManager::status( $plugin ); - if ( $position_in_queue === false || $position_in_queue === 0 ) { - PluginUninstallTaskManager::add_to_queue( - new PluginUninstallTask( - $plugin, - ) - ); - } else { - PluginInstallTaskManager::remove_from_queue( - $plugin, - ); - } - } - } + if ( ! $plugins ) { + return new \WP_Error( + "plugin_list_not_provided", + "Plugins List Not Provided", + array( 'status' => 404 ) + ); } + foreach ( $plugins as $plugin => $decision ) { + if ( $decision ) { + PluginInstallTaskManager::add_to_queue( + new PluginInstallTask( + $plugin, + true, + ) + ); + } else { + $position_in_queue = PluginInstallTaskManager::status( $plugin ); + if ( $position_in_queue === false || $position_in_queue === 0 ) { + PluginUninstallTaskManager::add_to_queue( + new PluginUninstallTask( + $plugin, + ) + ); + } else { + PluginInstallTaskManager::remove_from_queue( + $plugin, + ); + } + } + } + return new \WP_REST_Response( array(), 202 From a67fc86771f7b5caced9a915bdeb893b24ff4f7b Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Mon, 5 Dec 2022 19:50:54 +0530 Subject: [PATCH 39/49] Check Approved --- includes/Data/Plugins.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/Data/Plugins.php b/includes/Data/Plugins.php index 7fc708d73..76e597677 100644 --- a/includes/Data/Plugins.php +++ b/includes/Data/Plugins.php @@ -240,8 +240,8 @@ public static function get() { */ public static function get_squashed() { return array_merge( - self::$wp_slugs, - self::$nfd_slugs, + array_keys( array_filter( self::$wp_slugs, array( __CLASS__, 'check_approved' ) ) ), + array_keys( array_filter( self::$nfd_slugs, array( __CLASS__, 'check_approved' ) ) ), ); } From dc1c3cefdbd233c0c738da6a42514a7e012690d9 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Mon, 5 Dec 2022 19:54:21 +0530 Subject: [PATCH 40/49] Added a wp_error case for delete_plugin --- includes/Services/PluginUninstaller.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/includes/Services/PluginUninstaller.php b/includes/Services/PluginUninstaller.php index 4ee535096..4b484fab3 100644 --- a/includes/Services/PluginUninstaller.php +++ b/includes/Services/PluginUninstaller.php @@ -135,7 +135,8 @@ public static function delete_plugin( $plugin_path ) { } // Removes directory and files of a plugin - if ( ! \delete_plugins( array( $plugin_path ) ) ) { + $deleted = \delete_plugins( array( $plugin_path ) ); + if ( ! $deleted || is_wp_error( $deleted ) ) { return new \WP_Error( 'nfd_onboarding_error', 'Unable to Delete the Plugin', From 353aa8b64d794761a8331581a330869dfef2c939 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Mon, 5 Dec 2022 20:53:21 +0530 Subject: [PATCH 41/49] Update Plugins.php --- includes/Data/Plugins.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/includes/Data/Plugins.php b/includes/Data/Plugins.php index 76e597677..711c1a4eb 100644 --- a/includes/Data/Plugins.php +++ b/includes/Data/Plugins.php @@ -240,8 +240,8 @@ public static function get() { */ public static function get_squashed() { return array_merge( - array_keys( array_filter( self::$wp_slugs, array( __CLASS__, 'check_approved' ) ) ), - array_keys( array_filter( self::$nfd_slugs, array( __CLASS__, 'check_approved' ) ) ), + array_filter( self::$wp_slugs, array( __CLASS__, 'check_approved' ) ) , + array_filter( self::$nfd_slugs, array( __CLASS__, 'check_approved' ) ) , ); } From 008840d7ee725e9ef1f0150fec578a17eb70998e Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Mon, 5 Dec 2022 20:55:53 +0530 Subject: [PATCH 42/49] Changed Cron to 10 Seconds --- .../PluginUninstallTaskManager.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/includes/TaskManagers/PluginUninstallTaskManager.php b/includes/TaskManagers/PluginUninstallTaskManager.php index 785484322..74ea563fd 100644 --- a/includes/TaskManagers/PluginUninstallTaskManager.php +++ b/includes/TaskManagers/PluginUninstallTaskManager.php @@ -20,15 +20,15 @@ class PluginUninstallTaskManager { private static $queue_name = 'plugin_uninstall_queue'; function __construct() { - // Ensure there is a thirty second option in the cron schedules - add_filter( 'cron_schedules', array( $this, 'add_thirty_seconds_schedule' ) ); + // Ensure there is a Ten second option in the cron schedules + add_filter( 'cron_schedules', array( $this, 'add_ten_seconds_schedule' ) ); - // Thirty second cron hook + // Ten second cron hook add_action( 'nfd_module_onboarding_plugin_uninstall_cron', array( $this, 'uninstall' ) ); // Register the cron task if ( ! wp_next_scheduled( 'nfd_module_onboarding_plugin_uninstall_cron' ) ) { - wp_schedule_event( time(), 'thirty_seconds', 'nfd_module_onboarding_plugin_uninstall_cron' ); + wp_schedule_event( time(), 'ten_seconds', 'nfd_module_onboarding_plugin_uninstall_cron' ); } } @@ -36,11 +36,11 @@ public static function get_queue_name() { return self::$queue_name; } - public function add_thirty_seconds_schedule( $schedules ) { - if ( ! array_key_exists( 'thirty_seconds', $schedules ) || 30 !== $schedules['thirty_seconds']['interval'] ) { - $schedules['thirty_seconds'] = array( - 'interval' => 30, - 'display' => __( 'Once Every Thirty Seconds' ), + public function add_ten_seconds_schedule( $schedules ) { + if ( ! array_key_exists( 'ten_seconds', $schedules ) || 10 !== $schedules['ten_seconds']['interval'] ) { + $schedules['ten_seconds'] = array( + 'interval' => 10, + 'display' => __( 'Once Every Ten Seconds' ), ); } From 1fbb23f592212cf6387ff5c2a8da666c0e013ca9 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Mon, 5 Dec 2022 21:15:24 +0530 Subject: [PATCH 43/49] Refactored Code --- includes/RestApi/PluginsController.php | 65 +++++++++++-------------- includes/Services/PluginUninstaller.php | 8 +++ 2 files changed, 37 insertions(+), 36 deletions(-) diff --git a/includes/RestApi/PluginsController.php b/includes/RestApi/PluginsController.php index 84a453ac8..931a9ba69 100644 --- a/includes/RestApi/PluginsController.php +++ b/includes/RestApi/PluginsController.php @@ -95,12 +95,12 @@ public function register_routes() { \register_rest_route( $this->namespace, - $this->rest_base . '/uninstall', + $this->rest_base . '/site-features', array( array( 'methods' => \WP_REST_Server::CREATABLE, - 'callback' => array( $this, 'uninstall' ), - 'args' => $this->get_uninstall_plugin_args(), + 'callback' => array( $this, 'set_site_features' ), + 'args' => $this->set_site_features_args(), 'permission_callback' => array( $this, 'check_install_permissions' ), ), ) @@ -159,7 +159,7 @@ public function get_status_args() { ); } - public function get_uninstall_plugin_args() { + public function set_site_features_args() { return array( 'plugins' => array( 'type' => 'object', @@ -280,10 +280,10 @@ public function get_status( \WP_REST_Request $request ) { } /** - * Retrieves the Customized list of Plugins for the user. - * - * @return array|\WP_Error - */ + * Retrieves the Customized list of Plugins for the user. + * + * @return array|\WP_Error + */ public function get_site_features() { return SiteFeatures::get(); } @@ -295,42 +295,35 @@ public function get_site_features() { * * @return \WP_REST_Response|\WP_Error */ - public function uninstall( \WP_REST_Request $request ) { + public function set_site_features( \WP_REST_Request $request ) { $plugin_body = json_decode( $request->get_body(), true ); $plugins = isset( $plugin_body['plugins'] ) ? $plugin_body['plugins'] : false; if ( ! $plugins ) { return new \WP_Error( - "plugin_list_not_provided", - "Plugins List Not Provided", - array( 'status' => 404 ) - ); + 'plugin_list_not_provided', + 'Plugins List Not Provided', + array( 'status' => 404 ) + ); } - foreach ( $plugins as $plugin => $decision ) { - if ( $decision ) { - PluginInstallTaskManager::add_to_queue( - new PluginInstallTask( - $plugin, - true, - ) - ); - } else { - $position_in_queue = PluginInstallTaskManager::status( $plugin ); - if ( $position_in_queue === false || $position_in_queue === 0 ) { - PluginUninstallTaskManager::add_to_queue( - new PluginUninstallTask( - $plugin, - ) - ); - } else { - PluginInstallTaskManager::remove_from_queue( - $plugin, - ); - } - } - } + foreach ( $plugins as $plugin => $decision ) { + if ( $decision ) { + PluginInstallTaskManager::add_to_queue( + new PluginInstallTask( + $plugin, + true, + ) + ); + } else { + PluginUninstallTaskManager::add_to_queue( + new PluginUninstallTask( + $plugin, + ) + ); + } + } return new \WP_REST_Response( array(), diff --git a/includes/Services/PluginUninstaller.php b/includes/Services/PluginUninstaller.php index 4b484fab3..9b5c4406e 100644 --- a/includes/Services/PluginUninstaller.php +++ b/includes/Services/PluginUninstaller.php @@ -2,6 +2,7 @@ namespace NewfoldLabs\WP\Module\Onboarding\Services; use NewfoldLabs\WP\Module\Onboarding\Data\Plugins; +use NewfoldLabs\WP\Module\Onboarding\TaskManagers\PluginInstallTaskManager; /** * Class PluginUninstaller @@ -12,6 +13,13 @@ class PluginUninstaller { public static function uninstall( $plugin ) { + $position_in_queue = PluginInstallTaskManager::status( $plugin ); + if ( $position_in_queue !== false && $position_in_queue !== 0 ) { + PluginInstallTaskManager::remove_from_queue( + $plugin, + ); + } + $plugin_list = Plugins::get_squashed(); // Gets the specified path for the Plugin from the predefined list $plugin_path = $plugin_list[ $plugin ]['path']; From 34821396a01ba9b33bb9c16cbe7aa4d0d2ce7998 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Tue, 6 Dec 2022 10:51:15 +0530 Subject: [PATCH 44/49] Update SiteFeatures.php --- includes/Data/SiteFeatures.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/Data/SiteFeatures.php b/includes/Data/SiteFeatures.php index 9d0f50f32..b16d2fc1c 100644 --- a/includes/Data/SiteFeatures.php +++ b/includes/Data/SiteFeatures.php @@ -7,7 +7,7 @@ final class SiteFeatures { protected static $site_features = array( - 'default' => array(), + 'wp-setup' => array(), 'ecommerce' => array( 'jetpack' => array( 'slug' => 'jetpack', From 19a83c3cf5c874bf7240dc7d5f6550e167533072 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Tue, 6 Dec 2022 11:31:39 +0530 Subject: [PATCH 45/49] Update PluginsController.php --- includes/RestApi/PluginsController.php | 7 ------- 1 file changed, 7 deletions(-) diff --git a/includes/RestApi/PluginsController.php b/includes/RestApi/PluginsController.php index 931a9ba69..039c4dfb8 100644 --- a/includes/RestApi/PluginsController.php +++ b/includes/RestApi/PluginsController.php @@ -90,13 +90,6 @@ public function register_routes() { 'callback' => array( $this, 'get_site_features' ), 'permission_callback' => array( Permissions::class, 'rest_is_authorized_admin' ), ), - ) - ); - - \register_rest_route( - $this->namespace, - $this->rest_base . '/site-features', - array( array( 'methods' => \WP_REST_Server::CREATABLE, 'callback' => array( $this, 'set_site_features' ), From a675648caad04a8c0ee869ca3d9a1aa40357289e Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Tue, 6 Dec 2022 11:44:07 +0530 Subject: [PATCH 46/49] Changed from key to name --- .../components/CheckboxTemplate/CheckboxItem/index.js | 4 ++-- .../components/CheckboxTemplate/CheckboxList/index.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js index b7bd09438..7681fb09e 100644 --- a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/index.js @@ -16,7 +16,7 @@ import { CheckboxControl } from '@wordpress/components'; */ const CheckboxItem = ( { - key, + name, icon, title, desc, @@ -30,7 +30,7 @@ const CheckboxItem = ( { const handleCheck = () => { setIsSelected( ! isSelected ); - callback( key, ! isSelected ); + callback( name, ! isSelected ); }; const handleShowDesc = () => { diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/index.js b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/index.js index d4329618b..51a8808e6 100644 --- a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/index.js +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxList/index.js @@ -23,7 +23,7 @@ const CheckboxList = ( { callback, selectedItems, customItemsList } ) => { const isSelectedDefault = selectedItems[item.slug]; customItems.push( Date: Tue, 6 Dec 2022 11:45:51 +0530 Subject: [PATCH 47/49] Update stylesheet.scss --- .../components/CheckboxTemplate/CheckboxItem/stylesheet.scss | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss index 88c2b4bd3..8c967cac3 100644 --- a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss @@ -93,7 +93,7 @@ $main-border-main: var(--nfd-onboarding-primary-alt); &--shown { border-bottom: none; border-radius: 2px 2px 0px 0px; - background: rgba($white-offset, 0.8); + background: rgba($white-offset, 1); border-top: 1px solid rgba($main-color, 0.1); border-left: 1px solid rgba($main-color, 0.1); border-right: 1px solid rgba($main-color, 0.1); @@ -110,7 +110,7 @@ $main-border-main: var(--nfd-onboarding-primary-alt); border-radius: 0px 0px 2px 2px; transform-origin: top center; width: clamp(15rem, 25vw, 35rem); - background: rgba($white-offset, 0.8); + background: rgba($white-offset, 1); font-size: clamp(0.82rem, 2vw, 0.9rem); border-left: 1px solid rgba($main-color, 0.1); border-right: 1px solid rgba($main-color, 0.1); From 80cd5776cd07985217dd00b9c6b7948f5f242320 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Tue, 6 Dec 2022 11:50:36 +0530 Subject: [PATCH 48/49] Update stylesheet.scss --- .../components/CheckboxTemplate/CheckboxItem/stylesheet.scss | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss index 8c967cac3..54fdfd435 100644 --- a/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss +++ b/src/OnboardingSPA/components/CheckboxTemplate/CheckboxItem/stylesheet.scss @@ -4,6 +4,7 @@ $main-color-dark: var(--wp-admin-theme-color); $main-color-light: var(--nfd-onboarding-white); $main-color: var(--nfd-onboarding-highlighted--rgb); $main-border-main: var(--nfd-onboarding-primary-alt); +$box-shadow: var(--nfd-onboarding-light-gray-highlighted); .checkbox-item { margin: 12px; @@ -92,8 +93,8 @@ $main-border-main: var(--nfd-onboarding-primary-alt); &--shown { border-bottom: none; + background: $box-shadow; border-radius: 2px 2px 0px 0px; - background: rgba($white-offset, 1); border-top: 1px solid rgba($main-color, 0.1); border-left: 1px solid rgba($main-color, 0.1); border-right: 1px solid rgba($main-color, 0.1); @@ -107,10 +108,10 @@ $main-border-main: var(--nfd-onboarding-primary-alt); margin-top: -12px; position: absolute; font-style: italic; + background: $box-shadow; border-radius: 0px 0px 2px 2px; transform-origin: top center; width: clamp(15rem, 25vw, 35rem); - background: rgba($white-offset, 1); font-size: clamp(0.82rem, 2vw, 0.9rem); border-left: 1px solid rgba($main-color, 0.1); border-right: 1px solid rgba($main-color, 0.1); From 633b1a6aa7b43b392ff30a904a457870b461018c Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Tue, 6 Dec 2022 12:12:42 +0530 Subject: [PATCH 49/49] Update index.js --- src/OnboardingSPA/pages/Steps/SiteFeatures/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js b/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js index 9f1f9d6d4..6af7fc52f 100644 --- a/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js +++ b/src/OnboardingSPA/pages/Steps/SiteFeatures/index.js @@ -23,6 +23,7 @@ const StepSiteFeatures = () => { setIsSidebarOpened, setCurrentOnboardingData, setIsDrawerSuppressed, + setIsHeaderNavigationEnabled, } = useDispatch( nfdOnboardingStore ); const { currentStep, currentData } = useSelect( ( select ) => {