diff --git a/includes/Flows/Flows.php b/includes/Flows/Flows.php index 8e6401b..6c681e6 100644 --- a/includes/Flows/Flows.php +++ b/includes/Flows/Flows.php @@ -322,9 +322,8 @@ public static function is_sitegen() { if ( ! $flow_data || empty( $flow_data['activeFlow'] ) ) { return false; } - - return 'sitegen' === $flow_data['activeFlow']; + return 'sitegen' === $flow_data['activeFlow']; } /** diff --git a/includes/Mustache/Mustache.php b/includes/Mustache/Mustache.php index 4349551..b04e2d6 100644 --- a/includes/Mustache/Mustache.php +++ b/includes/Mustache/Mustache.php @@ -19,7 +19,7 @@ class Mustache { public function __construct() { $this->mustache_engine = new \Mustache_Engine( array( - 'loader' => new \Mustache_Loader_FilesystemLoader( dirname( __FILE__ ) . '/Templates' ), + 'loader' => new \Mustache_Loader_FilesystemLoader( __DIR__ . '/Templates' ), ) ); } diff --git a/includes/Services/SiteGenService.php b/includes/Services/SiteGenService.php index d482384..66585b5 100644 --- a/includes/Services/SiteGenService.php +++ b/includes/Services/SiteGenService.php @@ -134,33 +134,33 @@ public static function complete( $active_homepage, $homepage_data ) { \update_option( Options::get_option_name( 'show_on_front', false ), 'page' ); } - foreach ( $homepage_data as $index => $data ) { - if ( ! $data['isFavorite'] && $data['slug'] !== $active_homepage['slug'] ) { - continue; - } - $title = $data['title']; - $content = $data['content']; - $post_id = SitePagesService::publish_page( - $title, - $content, - true, - array( - 'nf_dc_page' => 'home', - ) - ); - if ( is_wp_error( $post_id ) ) { - return $post_id; - } - if ( $active_homepage['slug'] === $data['slug'] ) { - \update_option( Options::get_option_name( 'page_on_front', false ), $post_id ); - } + $title = $active_homepage['title']; + $content = $active_homepage['content']; + $post_id = SitePagesService::publish_page( + $title, + $content, + true, + array( + 'nf_dc_page' => 'home', + ) + ); + + if ( is_wp_error( $post_id ) ) { + return $post_id; + } - self::generate_child_theme( $data ); + \update_option( Options::get_option_name( 'page_on_front', false ), $post_id ); - ThemeGeneratorService::activate_theme( $active_homepage['slug'] ); + self::generate_child_theme( $active_homepage ); + foreach ( $homepage_data as $index => $data ) { + if ( $data['isFavorite'] && $data['slug'] !== $active_homepage['slug'] ) { + self::generate_child_theme( $data ); + } } + ThemeGeneratorService::activate_theme( $active_homepage['slug'] ); + return true; } @@ -225,6 +225,15 @@ public static function generate_child_theme( $data ) { $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'], @@ -248,6 +257,7 @@ public static function generate_child_theme( $data ) { '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, ); $child_theme_written = ThemeGeneratorService::write_child_theme( $child_theme_data ); @@ -413,20 +423,8 @@ public static function process_homepages_response( $last_version_number = self::get_last_version_number( $existing_homepages ); $version_number = $last_version_number + 1; - foreach ( $homepages as $key => $blocks ) { - - if ( ! is_array( $blocks ) ) { - continue; - } - - $filtered_blocks = array_filter( - $blocks, - function ( $value ) { - return ! is_null( $value ); - } - ); + foreach ( $homepages as $slug => $data ) { - $content = implode( '', $filtered_blocks ); // Select a random palette and check against the parent's palette. $palette_index = array_rand( $color_palettes ); $selected_palette = self::transform_palette( $color_palettes[ $palette_index ], $palette_index ); @@ -436,7 +434,9 @@ function ( $value ) { 'slug' => $homepage_slug, 'title' => __( 'Version ', 'wp-module-onboarding' ) . $version_number, 'isFavorite' => false, - 'content' => $content, + 'content' => $data['content'], + 'header' => $data['header'], + 'footer' => $data['footer'], 'color' => $selected_palette, ); ++$version_number; diff --git a/includes/Services/SitePagesService.php b/includes/Services/SitePagesService.php index e38befc..043872e 100644 --- a/includes/Services/SitePagesService.php +++ b/includes/Services/SitePagesService.php @@ -33,7 +33,4 @@ public static function publish_page( $title, $content, $is_template_no_title = f return \wp_insert_post( $post ); } - - } - diff --git a/includes/Services/ThemeGeneratorService.php b/includes/Services/ThemeGeneratorService.php index 63b8884..adc919d 100644 --- a/includes/Services/ThemeGeneratorService.php +++ b/includes/Services/ThemeGeneratorService.php @@ -226,6 +226,4 @@ public static function generate_screenshot( $parent_theme_dir, $child_theme_dir public static function get_site_url_hash( $length = 8 ) { return substr( hash( 'sha256', site_url() ), 0, $length ); } - - }