From 0bc485ac040d068f84c1e98de5bb0ae3aaa45532 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Wed, 21 Feb 2024 14:19:19 +0530 Subject: [PATCH 1/6] use the add_action func --- includes/WP_Admin.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/includes/WP_Admin.php b/includes/WP_Admin.php index 16e2b5fdb..5ea7815ee 100644 --- a/includes/WP_Admin.php +++ b/includes/WP_Admin.php @@ -148,6 +148,16 @@ public static function enqueue_block_assets() { \do_action( 'enqueue_nfd_wonder_blocks_utilities' ); } + /** + * Adding action hooks that trigger the AI Module generates site meta. + * This needs to be added before the do_action is triggered from AI Module + * + * @return void + */ + public static function instantiate_sitegen_hooks() { + \add_action( 'nfd-ai-site-gen-targetaudience', array( SiteGenService::class, 'set_site_title_and_tagline' ), 10, 1 ); + } + /** * Initialize Plugins and Themes if necessary. * @@ -165,6 +175,7 @@ public static function initialize() { FlowService::initialize_data(); self::register_assets(); + self::instantiate_sitegen_hooks(); } /** From 0bdb748cf8d9c9fe76675b411714aa67a8ff563d Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Wed, 21 Feb 2024 16:10:05 +0530 Subject: [PATCH 2/6] New Option name --- includes/WP_Admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/WP_Admin.php b/includes/WP_Admin.php index 5ea7815ee..3dd65b5e0 100644 --- a/includes/WP_Admin.php +++ b/includes/WP_Admin.php @@ -155,7 +155,7 @@ public static function enqueue_block_assets() { * @return void */ public static function instantiate_sitegen_hooks() { - \add_action( 'nfd-ai-site-gen-targetaudience', array( SiteGenService::class, 'set_site_title_and_tagline' ), 10, 1 ); + \add_action( 'nfd-ai-site-gen-siteconfig', array( SiteGenService::class, 'set_site_title_and_tagline' ), 10, 1 ); } /** From 0c8577e8ef5b98c4ef7420d9bef75a5fab7eb325 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Wed, 21 Feb 2024 16:13:26 +0530 Subject: [PATCH 3/6] Update WP_Admin.php --- includes/WP_Admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/WP_Admin.php b/includes/WP_Admin.php index 3dd65b5e0..0e3b921a5 100644 --- a/includes/WP_Admin.php +++ b/includes/WP_Admin.php @@ -155,7 +155,7 @@ public static function enqueue_block_assets() { * @return void */ public static function instantiate_sitegen_hooks() { - \add_action( 'nfd-ai-site-gen-siteconfig', array( SiteGenService::class, 'set_site_title_and_tagline' ), 10, 1 ); + \add_action( 'newfold/ai/sitemeta-siteconfig:generated', array( SiteGenService::class, 'set_site_title_and_tagline' ), 10, 1 ); } /** From 620be946e5fe04caa8bdba77b33fb4d3aca79483 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Wed, 21 Feb 2024 16:23:20 +0530 Subject: [PATCH 4/6] Update WP_Admin.php --- includes/WP_Admin.php | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/includes/WP_Admin.php b/includes/WP_Admin.php index 0e3b921a5..8ee3dc2e7 100644 --- a/includes/WP_Admin.php +++ b/includes/WP_Admin.php @@ -34,6 +34,7 @@ public function __construct() { if ( 'sitegen' === Data::current_flow() ) { \add_action( 'load-themes.php', array( __CLASS__, 'mark_sitegen_generated_themes' ) ); SiteGenService::pre_set_filter_wonder_blocks_transients(); + SiteGenService::instantiate_site_meta(); } } @@ -148,16 +149,6 @@ public static function enqueue_block_assets() { \do_action( 'enqueue_nfd_wonder_blocks_utilities' ); } - /** - * Adding action hooks that trigger the AI Module generates site meta. - * This needs to be added before the do_action is triggered from AI Module - * - * @return void - */ - public static function instantiate_sitegen_hooks() { - \add_action( 'newfold/ai/sitemeta-siteconfig:generated', array( SiteGenService::class, 'set_site_title_and_tagline' ), 10, 1 ); - } - /** * Initialize Plugins and Themes if necessary. * @@ -175,7 +166,6 @@ public static function initialize() { FlowService::initialize_data(); self::register_assets(); - self::instantiate_sitegen_hooks(); } /** From 8f6cc4c31724333fa64fdb385e00aab5d2643ae1 Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Wed, 21 Feb 2024 16:23:50 +0530 Subject: [PATCH 5/6] Update WP_Admin.php --- includes/WP_Admin.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/WP_Admin.php b/includes/WP_Admin.php index 8ee3dc2e7..a83379e51 100644 --- a/includes/WP_Admin.php +++ b/includes/WP_Admin.php @@ -34,7 +34,7 @@ public function __construct() { if ( 'sitegen' === Data::current_flow() ) { \add_action( 'load-themes.php', array( __CLASS__, 'mark_sitegen_generated_themes' ) ); SiteGenService::pre_set_filter_wonder_blocks_transients(); - SiteGenService::instantiate_site_meta(); + SiteGenService::instantiate_sitegen_hooks(); } } From 8c23f07eac7f081daa720639c76ff385cfc204aa Mon Sep 17 00:00:00 2001 From: Allen Benny Date: Wed, 21 Feb 2024 18:04:13 +0530 Subject: [PATCH 6/6] Update Core Store --- .../NewfoldInterfaceSkeleton/SiteGen/index.js | 22 +++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js b/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js index 1b28cdd1c..788af1cc9 100644 --- a/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js +++ b/src/OnboardingSPA/components/NewfoldInterfaceSkeleton/SiteGen/index.js @@ -1,4 +1,5 @@ import { useEffect, useRef } from '@wordpress/element'; +import { store as coreStore } from '@wordpress/core-data'; import { useLocation } from 'react-router-dom'; import { useSelect, useDispatch } from '@wordpress/data'; @@ -40,6 +41,12 @@ const SiteGen = () => { }; }, [] ); + // Update Title and Tagline on the site. + const { editEntityRecord } = useDispatch( coreStore ); + const { getEditedEntityRecord } = useSelect( ( select ) => { + return select( coreStore ); + }, [] ); + useEffect( () => { document.body.classList.add( `nfd-brand-${ newfoldBrand }` ); }, [ newfoldBrand ] ); @@ -93,7 +100,7 @@ const SiteGen = () => { identifier, skipCache ); - if ( data.body !== null ) { + if ( data !== null ) { currentData.sitegen.siteGenMetaStatus.currentStatus += 1; if ( currentData.sitegen.siteGenMetaStatus.currentStatus === @@ -102,6 +109,13 @@ const SiteGen = () => { currentData.sitegen.skipCache = false; } setCurrentOnboardingData( currentData ); + + if ( identifier === 'site_config' ) { + editEntityRecord( 'root', 'site', undefined, { + title: data.site_title, + description: data.tagline, + } ); + } } } catch ( err ) { if ( retryCount < MAX_RETRIES_SITE_GEN ) { @@ -181,7 +195,10 @@ const SiteGen = () => { }, [ location.pathname ] ); useEffect( () => { - if ( prevSiteGenErrorStatus.current === true && siteGenErrorStatus === false ) { + if ( + prevSiteGenErrorStatus.current === true && + siteGenErrorStatus === false + ) { generateSiteGenData(); syncStoreToDB(); } @@ -191,6 +208,7 @@ const SiteGen = () => { useEffect( () => { initializeThemes(); initializeSettings(); + getEditedEntityRecord( 'root', 'site' ); }, [] ); return (