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

SiteGen Flow: Populate customised Typography while generating the child theme #98

Merged
merged 2 commits into from
Jun 25, 2024
Merged
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
25 changes: 25 additions & 0 deletions includes/Services/SiteGenService.php
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,30 @@ public static function complete( $active_homepage, $homepage_data ) {
return true;
}

/**
* Populates the the fonts in the Theme's styles.
*
* @param object $theme_styles Theme styles json data.
* @param object $homepage_styles Customized Homepage styles.
* @return object $theme_styles Updated theme styles.
*/
public static function populate_fonts_in_theme_styles( $theme_styles, $homepage_styles ) {

if ( ! empty( $homepage_styles['blocks'] ) && isset( $homepage_styles['blocks'][0] ) ) {
$first_block = $homepage_styles['blocks'][0];

if ( isset( $first_block['core/heading'] ) && isset( $first_block['core/heading']['typography']['fontFamily'] ) ) {
$theme_styles['blocks']['core/heading']['typography']['fontFamily'] = $first_block['core/heading']['typography']['fontFamily'];
}

if ( isset( $first_block['core/body'] ) && isset( $first_block['core/body']['typography']['fontFamily'] ) ) {
$theme_styles['typography']['fontFamily'] = $first_block['core/body']['typography']['fontFamily'];
}
}

return $theme_styles;
}

/**
* Generates a child theme for the sitegen flow.
*
Expand Down Expand Up @@ -292,6 +316,7 @@ public static function generate_child_theme( $data ) {
$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(
Expand Down
Loading