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

Upgrade to Theme Customizations Instead of Child Themes #613

Merged
merged 5 commits into from
Sep 11, 2024
Merged
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
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
"require": {
"mustache/mustache": "^2.14",
"wp-cli/wp-config-transformer": "^1.3",
"newfold-labs/wp-module-onboarding-data": "^1.1",
"newfold-labs/wp-module-onboarding-data": "^1.0",
"newfold-labs/wp-module-patterns": "^2.1",
"newfold-labs/wp-module-facebook": "^1.0",
"newfold-labs/wp-module-migration": "^1.0",
Expand Down
14 changes: 7 additions & 7 deletions composer.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

53 changes: 37 additions & 16 deletions includes/RestApi/FlowController.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
use NewfoldLabs\WP\Module\Onboarding\Data\Services\FlowService;
use NewfoldLabs\WP\Module\Onboarding\Services\PluginService;
use NewfoldLabs\WP\Module\Onboarding\Data\Services\SiteGenService;
use NewfoldLabs\WP\Module\Onboarding\Services\GlobalStylesService;
use NewfoldLabs\WP\Module\Onboarding\Services\StatusService;
use NewfoldLabs\WP\Module\Onboarding\Services\TemplatePartsService;

/**
* Class FlowController
Expand Down Expand Up @@ -128,51 +130,70 @@ public function save_onboarding_flow_data( \WP_REST_Request $request ) {
}

/**
* Flow completion API for child theme generation, verify child theme and publish site pages.
* Handles the completion of different onboarding flows.
*
* @param \WP_REST_Request $request The incoming request.
* This function processes the completion of various onboarding flows,
* such as site generation and site page publishing, and updates global
* styles and template parts if necessary.
*
* @param \WP_REST_Request $request The request object containing the flow parameter.
*
* @return \WP_REST_Response|\WP_Error
* @return \WP_REST_Response|\WP_Error A WP_REST_Response object on success, or a WP_Error object on failure.
*/
public function complete( $request ) {
// Retrieve the 'flow' parameter from the request
$flow = $request->get_param( 'flow' );

if ( 'sitegen' === $flow ) {
$flow_data_option = \get_option( Options::get_option_name( 'flow' ), false );
// Read flow data from the WordPress options table
$flow_data_option = FlowService::read_data_from_wp_option( false );
// Check if flow data does not exist or 'data' key is not set
if ( false === $flow_data_option || ! isset( $flow_data_option['data'] ) ) {
return new \WP_Error(
'nfd_onboarding_error',
'Flow data does not exist to generate a child theme.',
__( 'Flow data does not exist to generate a child theme.', 'wp-module-onboarding' ),
array( 'status' => 500 )
);
}
// Retrieve homepage data and the active homepage from the flow data
$homepage_data = $flow_data_option['sitegen']['homepages']['data'];
$active_homepage = $flow_data_option['sitegen']['homepages']['active'];
// Complete the Sitegen flow using the retrieved data
SiteGenService::complete( $active_homepage, $homepage_data );
return new \WP_REST_Response(
array(),
201
);
}

$site_pages_publish_request = new \WP_REST_Request(
// If the flow is not 'sitegen', proceed with publishing site pages
$site_pages_publish_request = new \WP_REST_Request(
'POST',
'/newfold-onboarding/v1/site-pages/publish'
);
$site_pages_publish_response = \rest_do_request( $site_pages_publish_request );
// Execute the request to publish site pages
$site_pages_publish_response = rest_do_request( $site_pages_publish_request );
if ( $site_pages_publish_response->is_error() ) {
return $site_pages_publish_response->as_error();
}
$child_theme_generation_request = new \WP_REST_Request(
'POST',
'/newfold-onboarding/v1/themes/child/generate'
);
$child_theme_generation_response = \rest_do_request( $child_theme_generation_request );
if ( $child_theme_generation_response->is_error() ) {
return $child_theme_generation_response->as_error();

// Get the post ID of the active custom global styles and update it
$active_custom_global_styles_post_id = GlobalStylesService::get_active_custom_global_styles_post_id();
$status = GlobalStylesService::update_diy_global_style_variation( $active_custom_global_styles_post_id, );
if ( is_wp_error( $status ) ) {
return $status;
}

// Update the selected template parts
$status = TemplatePartsService::update_diy_selected_template_parts();
if ( is_wp_error( $status ) ) {
return $status;
}

// Return a successful response after completing all processes
return new \WP_REST_Response(
array(),
array(
'message' => __( 'Success.', 'wp-module-onboarding' ),
),
201
);
}
Expand Down
3 changes: 1 addition & 2 deletions includes/RestApi/RestApi.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ final class RestApi {
*/
protected $controllers = array(
'NewfoldLabs\\WP\\Module\\Onboarding\\RestApi\\SiteImagesController',
'NewfoldLabs\\WP\\Module\\Onboarding\\RestApi\\Themes\\ThemeGeneratorController',
'NewfoldLabs\\WP\\Module\\Onboarding\\RestApi\\PluginsController',
'NewfoldLabs\\WP\\Module\\Onboarding\\RestApi\\Themes\\ThemeVariationsController',
'NewfoldLabs\WP\\Module\\Onboarding\\RestApi\\Themes\\ApprovedThemesController',
Expand Down Expand Up @@ -56,4 +55,4 @@ public function register_routes() {
$instance->register_routes();
}
}
} // END /NewfoldLabs/WP/Module/Onboarding/RestApi()
}
Loading
Loading