@@ -311,117 +311,6 @@ public static function update_styles_for_sitegen( $data ) {
311
311
GlobalStylesService::update_global_style_variation ( $ active_global_styles_post_id , $ active_theme_json_data ['styles ' ], $ active_theme_json_data ['settings ' ] );
312
312
}
313
313
314
- /**
315
- * Generates a child theme for the sitegen flow.
316
- *
317
- * @param array $data Data on each homepage and it's corresponding styles.
318
- * @return true|\WP_Error
319
- */
320
- public static function generate_child_theme ( $ data ) {
321
- global $ wp_filesystem ;
322
- ThemeGeneratorService::connect_to_filesystem ();
323
- $ parent_theme_slug = 'yith-wonder ' ;
324
- $ parent_theme_exists = ( \wp_get_theme ( $ parent_theme_slug ) )->exists ();
325
- if ( ! $ parent_theme_exists ) {
326
- return new \WP_Error (
327
- 'nfd_onboarding_error ' ,
328
- 'Parent theme is missing to generate the child theme. ' ,
329
- array ( 'status ' => 500 )
330
- );
331
- }
332
-
333
- /*
334
- Activate the parent theme if it is not active.
335
- This is necessary to register the parent theme's block patterns.
336
- */
337
- $ active_theme = Themes::get_active_theme ();
338
- if ( $ active_theme !== $ parent_theme_slug ) {
339
- ThemeGeneratorService::activate_theme ( $ parent_theme_slug );
340
- }
341
-
342
- // Generate the necessary slugs and paths.
343
- $ themes_dir = dirname ( \get_stylesheet_directory () );
344
- $ parent_theme_dir = $ themes_dir . '/ ' . $ parent_theme_slug ;
345
- $ child_theme_slug = $ data ['slug ' ];
346
- $ child_theme_dir = $ themes_dir . '/ ' . $ child_theme_slug ;
347
-
348
- $ theme_json_file = $ parent_theme_dir . '/theme.json ' ;
349
- if ( ! $ wp_filesystem ->exists ( $ theme_json_file ) ) {
350
- return false ;
351
- }
352
- $ theme_json = $ wp_filesystem ->get_contents ( $ theme_json_file );
353
- $ theme_json_data = json_decode ( $ theme_json , true );
354
-
355
- $ theme_json_data ['settings ' ]['color ' ]['palette ' ] = $ data ['color ' ]['palette ' ];
356
- $ theme_json_data ['styles ' ] = self ::populate_fonts_in_theme_styles ( $ theme_json_data ['styles ' ], $ data ['styles ' ] );
357
-
358
- if ( ! $ theme_json_data ) {
359
- return new \WP_Error (
360
- 'nfd_onboarding_error ' ,
361
- 'Could not generate theme.json ' ,
362
- array ( 'status ' => 500 )
363
- );
364
- }
365
-
366
- $ current_brand = Data::current_brand ();
367
- $ customer = \wp_get_current_user ();
368
-
369
- $ default_site_titles_dashed = array ( 'welcome ' , 'wordpress-site ' );
370
- $ site_title = \get_bloginfo ( 'name ' );
371
- $ site_title_dashed = \sanitize_title_with_dashes ( $ site_title );
372
- if ( empty ( $ site_title ) || in_array ( $ site_title_dashed , $ default_site_titles_dashed , true ) ) {
373
- $ site_title = $ current_brand ['brand ' ] . '- ' . ThemeGeneratorService::get_site_url_hash ();
374
- }
375
-
376
- $ part_patterns = array ();
377
- if ( ! empty ( $ data ['header ' ] ) ) {
378
- $ part_patterns ['header ' ] = $ data ['header ' ];
379
- }
380
-
381
- if ( ! empty ( $ data ['footer ' ] ) ) {
382
- $ part_patterns ['footer ' ] = $ data ['footer ' ];
383
- }
384
-
385
- $ theme_style_data = array (
386
- 'current_brand ' => Data::current_brand (),
387
- 'brand ' => $ current_brand ['brand ' ],
388
- 'brand_name ' => $ current_brand ['name ' ] ? $ current_brand ['name ' ] : 'Newfold Digital ' ,
389
- 'theme_name ' => $ data ['title ' ],
390
- 'site_title ' => $ site_title ,
391
- 'site_url ' => \site_url (),
392
- 'author ' => $ customer ->user_firstname ,
393
- 'parent_theme_slug ' => $ parent_theme_slug ,
394
- 'child_theme_slug ' => $ child_theme_slug ,
395
- );
396
-
397
- $ mustache = new Mustache ();
398
- $ child_theme_stylesheet_comment = $ mustache ->render_template ( 'themeStylesheet ' , $ theme_style_data );
399
-
400
- // Write the child theme to the filesystem under themes.
401
- $ child_theme_data = array (
402
- 'parent_theme_slug ' => $ parent_theme_slug ,
403
- 'child_theme_slug ' => $ child_theme_slug ,
404
- 'parent_theme_dir ' => $ parent_theme_dir ,
405
- 'child_theme_dir ' => $ child_theme_dir ,
406
- 'child_theme_json ' => \wp_json_encode ( $ theme_json_data ),
407
- 'child_theme_stylesheet_comment ' => $ child_theme_stylesheet_comment ,
408
- 'part_patterns ' => $ part_patterns ,
409
- 'theme_screenshot_dir ' => realpath ( __DIR__ . '/../assets/images ' ),
410
- 'theme_screenshot ' => isset ( $ data ['screenshot ' ] ) ? $ data ['screenshot ' ] : false ,
411
- );
412
-
413
- $ child_theme_written = ThemeGeneratorService::write_child_theme ( $ child_theme_data );
414
- if ( true !== $ child_theme_written ) {
415
- return new \WP_Error (
416
- 'nfd_onboarding_error ' ,
417
- $ child_theme_written ,
418
- array ( 'status ' => 500 )
419
- );
420
- }
421
-
422
- return true ;
423
- }
424
-
425
314
/**
426
315
* Gets the preview homepages
427
316
*
0 commit comments