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

Generate Extra Site Pages #437

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions includes/RestApi/FlowController.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,18 @@ public function save_onboarding_flow_data( \WP_REST_Request $request ) {
public function complete( $request ) {
$flow = $request->get_param( 'flow' );
if ( 'sitegen' === $flow ) {

// Publish Site Pages before saving Child Theme.
$sitegen_site_pages_request = new \WP_REST_Request(
'POST',
'/newfold-onboarding/v1/site-pages/sitegen-publish'
);
$sitegen_site_pages_request = \rest_do_request( $sitegen_site_pages_request );
if ( $sitegen_site_pages_request->is_error() ) {
return $sitegen_site_pages_request->as_error();
}

// Generate Child Theme
$flow_data_option = \get_option( Options::get_option_name( 'flow' ), false );
if ( false === $flow_data_option || ! isset( $flow_data_option['data'] ) ) {
return new \WP_Error(
Expand Down
50 changes: 50 additions & 0 deletions includes/RestApi/SitePagesController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use NewfoldLabs\WP\Module\Onboarding\Permissions;
use NewfoldLabs\WP\Module\Onboarding\Data\Options;
use NewfoldLabs\WP\Module\Onboarding\Data\Patterns;
use NewfoldLabs\WP\Module\Onboarding\Data\Services\SiteGenService;
use NewfoldLabs\WP\Module\Onboarding\Data\Services\WonderBlocksService;

/**
Expand Down Expand Up @@ -40,6 +41,16 @@ public function register_routes() {
'permission_callback' => array( Permissions::class, 'custom_post_authorized_admin' ),
)
);

\register_rest_route(
$this->namespace,
$this->rest_base . '/sitegen-publish',
array(
'methods' => \WP_REST_Server::CREATABLE,
'callback' => array( $this, 'publish_sitegen_site_pages' ),
'permission_callback' => array( Permissions::class, 'custom_post_authorized_admin' ),
)
);
}

/**
Expand Down Expand Up @@ -151,6 +162,45 @@ private function set_site_pages( $site_pages_pattern_slugs ) {
return true;
}


/**
* Publishes all the Site Pages for Sitegen Pages
*
* @return \WP_REST_Response|\WP_Error
*/
public function publish_sitegen_site_pages() {
// Make an AI Call, Iterate over it and publish all the pages that are returned.
$site_description = SiteGenService::get_prompt();
$site_info = array( 'site_description' => $site_description );

$target_audience = SiteGenService::instantiate_site_meta( $site_info, 'target_audience' );
if ( is_wp_error( $target_audience ) ) {
return $target_audience;
}

$content_style = SiteGenService::instantiate_site_meta( $site_info, 'content_tones' );
if ( is_wp_error( $content_style ) ) {
return $content_style;
}

$sitemap = SiteGenService::instantiate_site_meta( $site_info, 'sitemap' );
if ( is_wp_error( $sitemap ) ) {
return $sitemap;
}

$site_pages = SiteGenService::generate_site_pages( $site_description, $content_style, $target_audience, $sitemap );

foreach ( $site_pages as $key => $site_page ) {

$page_data = $this->publish_page( $key, $site_page['content'], false );
if ( is_wp_error( $page_data ) ) {
return $page_data;
}
}

return true;
}

/**
* Set the Publish Page
*
Expand Down
Loading