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

Use header and footer patterns for template parts #35

Merged
merged 2 commits into from
Jan 31, 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
3 changes: 1 addition & 2 deletions includes/Flows/Flows.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}

/**
Expand Down
2 changes: 1 addition & 1 deletion includes/Mustache/Mustache.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' ),
)
);
}
Expand Down
72 changes: 36 additions & 36 deletions includes/Services/SiteGenService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down Expand Up @@ -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'],
Expand All @@ -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 );
Expand Down Expand Up @@ -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 );
Expand All @@ -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;
Expand Down
3 changes: 0 additions & 3 deletions includes/Services/SitePagesService.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,4 @@ public static function publish_page( $title, $content, $is_template_no_title = f

return \wp_insert_post( $post );
}


}

2 changes: 0 additions & 2 deletions includes/Services/ThemeGeneratorService.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
}


}
Loading