Skip to content

Commit

Permalink
remove the code to geenrate child theme
Browse files Browse the repository at this point in the history
  • Loading branch information
amartya-dev committed Jan 31, 2025
1 parent ccf4da1 commit acad99c
Showing 1 changed file with 0 additions and 111 deletions.
111 changes: 0 additions & 111 deletions includes/Services/SitegenService.php
Original file line number Diff line number Diff line change
Expand Up @@ -311,117 +311,6 @@ public static function update_styles_for_sitegen( $data ) {
GlobalStylesService::update_global_style_variation( $active_global_styles_post_id, $active_theme_json_data['styles'], $active_theme_json_data['settings'] );
}

/**
* Generates a child theme for the sitegen flow.
*
* @param array $data Data on each homepage and it's corresponding styles.
* @return true|\WP_Error
*/
public static function generate_child_theme( $data ) {
global $wp_filesystem;
ThemeGeneratorService::connect_to_filesystem();
$parent_theme_slug = 'yith-wonder';
$parent_theme_exists = ( \wp_get_theme( $parent_theme_slug ) )->exists();
if ( ! $parent_theme_exists ) {
return new \WP_Error(
'nfd_onboarding_error',
'Parent theme is missing to generate the child theme.',
array( 'status' => 500 )
);
}

/*
Activate the parent theme if it is not active.
This is necessary to register the parent theme's block patterns.
*/
$active_theme = Themes::get_active_theme();
if ( $active_theme !== $parent_theme_slug ) {
ThemeGeneratorService::activate_theme( $parent_theme_slug );
}

// Generate the necessary slugs and paths.
$themes_dir = dirname( \get_stylesheet_directory() );
$parent_theme_dir = $themes_dir . '/' . $parent_theme_slug;
$child_theme_slug = $data['slug'];
$child_theme_dir = $themes_dir . '/' . $child_theme_slug;

$theme_json_file = $parent_theme_dir . '/theme.json';
if ( ! $wp_filesystem->exists( $theme_json_file ) ) {
return false;
}
$theme_json = $wp_filesystem->get_contents( $theme_json_file );
$theme_json_data = json_decode( $theme_json, true );

$theme_json_data['settings']['color']['palette'] = $data['color']['palette'];
$theme_json_data['styles'] = self::populate_fonts_in_theme_styles( $theme_json_data['styles'], $data['styles'] );

if ( ! $theme_json_data ) {
return new \WP_Error(
'nfd_onboarding_error',
'Could not generate theme.json',
array( 'status' => 500 )
);
}

$current_brand = Data::current_brand();
$customer = \wp_get_current_user();

$default_site_titles_dashed = array( 'welcome', 'wordpress-site' );
$site_title = \get_bloginfo( 'name' );
$site_title_dashed = \sanitize_title_with_dashes( $site_title );
if ( empty( $site_title ) || in_array( $site_title_dashed, $default_site_titles_dashed, true ) ) {
$site_title = $current_brand['brand'] . '-' . ThemeGeneratorService::get_site_url_hash();
}

$part_patterns = array();
if ( ! empty( $data['header'] ) ) {
$part_patterns['header'] = $data['header'];
}

if ( ! empty( $data['footer'] ) ) {
$part_patterns['footer'] = $data['footer'];
}

$theme_style_data = array(
'current_brand' => Data::current_brand(),
'brand' => $current_brand['brand'],
'brand_name' => $current_brand['name'] ? $current_brand['name'] : 'Newfold Digital',
'theme_name' => $data['title'],
'site_title' => $site_title,
'site_url' => \site_url(),
'author' => $customer->user_firstname,
'parent_theme_slug' => $parent_theme_slug,
'child_theme_slug' => $child_theme_slug,
);

$mustache = new Mustache();
$child_theme_stylesheet_comment = $mustache->render_template( 'themeStylesheet', $theme_style_data );

// Write the child theme to the filesystem under themes.
$child_theme_data = array(
'parent_theme_slug' => $parent_theme_slug,
'child_theme_slug' => $child_theme_slug,
'parent_theme_dir' => $parent_theme_dir,
'child_theme_dir' => $child_theme_dir,
'child_theme_json' => \wp_json_encode( $theme_json_data ),
'child_theme_stylesheet_comment' => $child_theme_stylesheet_comment,
'part_patterns' => $part_patterns,
'theme_screenshot_dir' => realpath( __DIR__ . '/../assets/images' ),
'theme_screenshot' => isset( $data['screenshot'] ) ? $data['screenshot'] : false,
);

$child_theme_written = ThemeGeneratorService::write_child_theme( $child_theme_data );
if ( true !== $child_theme_written ) {
return new \WP_Error(
'nfd_onboarding_error',
$child_theme_written,
array( 'status' => 500 )
);
}

return true;
}

/**
* Gets the preview homepages
*
Expand Down

0 comments on commit acad99c

Please sign in to comment.