Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Site Title and Tagline #48

Merged
merged 9 commits into from
Feb 21, 2024
59 changes: 56 additions & 3 deletions includes/Services/SiteGenService.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,14 @@
use NewfoldLabs\WP\Module\AI\SiteGen\SiteGen;
use NewfoldLabs\WP\Module\Onboarding\Data\Options;
use NewfoldLabs\WP\Module\Onboarding\Data\Data;
use NewfoldLabs\WP\Module\Onboarding\Data\Flows\Flows;
use NewfoldLabs\WP\Module\Onboarding\Data\Mustache\Mustache;
use NewfoldLabs\WP\Module\Onboarding\Data\Themes;
use NewfoldLabs\WP\Module\Onboarding\Data\Themes\Colors;
use NewfoldLabs\WP\Module\Onboarding\Data\Themes\Fonts;
use NewfoldLabs\WP\Module\Patterns\SiteClassification as PatternsSiteClassification;
use NewfoldLabs\WP\Module\Data\SiteClassification\PrimaryType;
use NewfoldLabs\WP\Module\Data\SiteClassification\SecondaryType;

/**
* Class SiteGenService
Expand All @@ -24,6 +27,7 @@ class SiteGenService {
* @var array
*/
private static $identifiers = array(
'site_config' => 'siteconfig',
'site_classification' => 'siteclassification',
'target_audience' => 'targetaudience',
'content_tones' => 'contenttones',
Expand Down Expand Up @@ -51,6 +55,7 @@ public static function get_identifier_name( $identifier_key ) {
*/
public static function enabled_identifiers() {
return array(
'site_config' => true,
'site_classification' => true,
'target_audience' => true,
'content_tones' => true,
Expand Down Expand Up @@ -92,7 +97,7 @@ public static function is_enabled() {
* @param string|Object $site_info The prompt that configures the Site gen object.
* @param string $identifier The identifier for Generating Site Meta.
* @param boolean $skip_cache To override the cache and fetch the data.
* @return array
* @return array|\WP_Error
*/
public static function instantiate_site_meta( $site_info, $identifier, $skip_cache = false ) {
if ( ! self::is_identifier( $identifier ) ) {
Expand Down Expand Up @@ -821,10 +826,58 @@ public static function publish_sitemap_pages( $site_description, $content_style,
}

/**
* Get the dummy navigation menu items for the Sitegen previews.
* 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 array
* @return void
*/
public static function instantiate_sitegen_hooks() {
\add_action( 'newfold/ai/sitemeta-siteconfig:generated', array( __CLASS__, 'set_site_title_and_tagline' ), 10, 1 );
\add_action( 'newfold/ai/sitemeta-siteclassification:generated', array( __CLASS__, 'set_site_classification' ), 10, 1 );
}

/**
* Sets the Title and Tagline for the site.
*
* @param array $site_details The Site title and site tagline.
* @return boolean
*/
public static function set_site_title_and_tagline( $site_details ) {

// Updates the Site Title
if ( ( ! empty( $site_details['site_title'] ) ) ) {
\update_option( Options::get_option_name( 'blog_name', false ), $site_details['site_title'] );
}

// Updates the Site Desc (Tagline)
if ( ( ! empty( $site_details['tagline'] ) ) ) {
\update_option( Options::get_option_name( 'blog_description', false ), $site_details['tagline'] );
}
return true;
}

/**
* Sets the site classification options that classify the site.
*
* @param array $site_classification The site classification site meta.
* @return void
*/
public static function set_site_classification( $site_classification ) {
if ( isset( $site_classification['primaryType'] ) ) {
$primary_type = new PrimaryType( 'slug', $site_classification['primaryType'] );
$primary_type->save();
}

if ( isset( $site_classification['slug'] ) ) {
$secondary_type = new SecondaryType( 'slug', $site_classification['slug'] );
$secondary_type->save();
}
}

/** Get the dummy navigation menu items for the Sitegen previews.
*
* @return array
*/
public static function get_dummy_navigation_menu_items() {
$prompt = self::get_prompt();
$site_info = array( 'site_description' => $prompt );
Expand Down
Loading