Skip to content

Commit 35fb597

Browse files
authored
Merge branch 'trunk' into fix/714
2 parents 898fa4b + ffa9186 commit 35fb597

24 files changed

+1604
-1179
lines changed
Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,43 @@
11
<!-- wp:template-part {"slug":"header","tagName":"header"} /-->
22

3-
<!-- wp:query {"tagName":"main","layout":{"inherit":true}} -->
4-
<main class="wp-block-query">
5-
<!-- wp:post-template -->
6-
<!-- wp:group -->
7-
<div class="wp-block-group">
8-
<!-- wp:post-title {"isLink":true} /-->
9-
<!-- wp:post-featured-image {"isLink":true} /-->
10-
<!-- wp:post-content /-->
11-
<!-- wp:group {"layout":{"type":"flex"}, "style":{"typography":{"fontSize":"14px"}}} -->
12-
<div class="wp-block-group" style="font-size:14px">
13-
<!-- wp:post-author {"showAvatar":false,"showBio":false} /-->
14-
<!-- wp:post-date {"isLink":true} /-->
15-
<!-- wp:post-terms {"term":"category"} /-->
16-
<!-- wp:post-terms {"term": "post_tag"} /-->
3+
<!-- wp:group {"tagName":"main","layout":{"type":"constrained"}} -->
4+
<main class="wp-block-group">
5+
<!-- wp:query {"layout":{"inherit":true}} -->
6+
<div class="wp-block-query">
7+
<!-- wp:post-template -->
8+
<!-- wp:group -->
9+
<div class="wp-block-group">
10+
<!-- wp:post-title {"isLink":true} /-->
11+
<!-- wp:post-featured-image {"isLink":true} /-->
12+
<!-- wp:post-content /-->
13+
<!-- wp:group {"layout":{"type":"flex"}, "style":{"typography":{"fontSize":"14px"}}} -->
14+
<div class="wp-block-group" style="font-size:14px">
15+
<!-- wp:post-author {"showAvatar":false,"showBio":false} /-->
16+
<!-- wp:post-date {"isLink":true} /-->
17+
<!-- wp:post-terms {"term":"category"} /-->
18+
<!-- wp:post-terms {"term": "post_tag"} /-->
19+
</div>
20+
<!-- /wp:group -->
21+
<!-- wp:spacer {"height":40} -->
22+
<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>
23+
<!-- /wp:spacer -->
1724
</div>
1825
<!-- /wp:group -->
19-
<!-- wp:spacer {"height":40} -->
20-
<div style="height:40px" aria-hidden="true" class="wp-block-spacer"></div>
21-
<!-- /wp:spacer -->
22-
</div>
23-
<!-- /wp:group -->
24-
<!-- /wp:post-template -->
25-
<!-- wp:group {"layout":{"inherit":true}} -->
26-
<div class="wp-block-group">
27-
<!-- wp:query-pagination -->
28-
<!-- wp:query-pagination-previous /-->
26+
<!-- /wp:post-template -->
27+
<!-- wp:group {"layout":{"inherit":true}} -->
28+
<div class="wp-block-group">
29+
<!-- wp:query-pagination -->
30+
<!-- wp:query-pagination-previous /-->
2931

30-
<!-- wp:query-pagination-numbers /-->
32+
<!-- wp:query-pagination-numbers /-->
3133

32-
<!-- wp:query-pagination-next /-->
33-
<!-- /wp:query-pagination -->
34+
<!-- wp:query-pagination-next /-->
35+
<!-- /wp:query-pagination -->
36+
</div>
37+
<!-- /wp:group -->
3438
</div>
35-
<!-- /wp:group -->
36-
</main>
37-
<!-- /wp:query -->
39+
<!-- /wp:query -->
40+
</main>
41+
<!-- /wp:group -->
3842

3943
<!-- wp:template-part {"slug":"footer","tagName":"footer"} /-->

create-block-theme.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
* Plugin Name: Create Block Theme
66
* Plugin URI: https://wordpress.org/plugins/create-block-theme
77
* Description: Generates a block theme
8-
* Version: 2.4.0
8+
* Version: 2.5.0
99
* Author: WordPress.org
1010
* Author URI: https://wordpress.org/
1111
* License: GNU General Public License v2 or later

includes/class-create-block-theme-api.php

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -239,8 +239,15 @@ function rest_create_child_theme( $request ) {
239239
}
240240

241241
function rest_create_variation( $request ) {
242+
$options = $request->get_params();
243+
244+
$save_fonts = isset( $options['saveFonts'] ) && true === $options['saveFonts'];
242245

243-
$response = CBT_Theme_JSON::add_theme_json_variation_to_local( 'variation', $this->sanitize_theme_data( $request->get_params() ) );
246+
$response = CBT_Theme_JSON::add_theme_json_variation_to_local(
247+
'variation',
248+
$this->sanitize_theme_data( $options ),
249+
$save_fonts
250+
);
244251

245252
wp_cache_flush();
246253

@@ -466,6 +473,7 @@ private function sanitize_theme_data( $theme ) {
466473
$sanitized_theme['subfolder'] = sanitize_text_field( $theme['subfolder'] ?? '' );
467474
$sanitized_theme['version'] = sanitize_text_field( $theme['version'] ?? '' );
468475
$sanitized_theme['screenshot'] = sanitize_text_field( $theme['screenshot'] ?? '' );
476+
$sanitized_theme['requires_wp'] = sanitize_text_field( $theme['requires_wp'] ?? '' );
469477
$sanitized_theme['recommended_plugins'] = sanitize_textarea_field( $theme['recommended_plugins'] ?? '' );
470478
$sanitized_theme['font_credits'] = sanitize_textarea_field( $theme['font_credits'] ?? '' );
471479
$sanitized_theme['image_credits'] = sanitize_textarea_field( $theme['image_credits'] ?? '' );

includes/class-create-block-theme-editor-tools.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ function create_block_theme_sidebar_enqueue() {
3838
'create-block-theme-slot-fill',
3939
);
4040

41+
global $wp_version;
42+
wp_add_inline_script(
43+
'create-block-theme-slot-fill',
44+
'const WP_VERSION = "' . $wp_version . '";',
45+
'before'
46+
);
47+
4148
// Enable localization in the plugin sidebar.
4249
wp_set_script_translations( 'create-block-theme-slot-fill', 'create-block-theme' );
4350
}

includes/create-theme/resolver_additions.php

Lines changed: 28 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,11 +65,7 @@ public static function export_theme_data( $content, $extra_theme_data = null ) {
6565
}
6666

6767
// Merge the User Data
68-
if ( class_exists( 'WP_Theme_JSON_Resolver_Gutenberg' ) ) {
69-
$theme->merge( WP_Theme_JSON_Resolver_Gutenberg::get_user_data() );
70-
} else {
71-
$theme->merge( static::get_user_data() );
72-
}
68+
$theme->merge( static::get_user_data() );
7369

7470
// Merge the extra theme data received as a parameter
7571
if ( ! empty( $extra_theme_data ) ) {
@@ -93,8 +89,33 @@ public static function export_theme_data( $content, $extra_theme_data = null ) {
9389
$schema = 'https://schemas.wp.org/' . $theme_json_version . '/theme.json';
9490
}
9591
$data['$schema'] = $schema;
96-
$theme_json = wp_json_encode( $data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
97-
return preg_replace( '~(?:^|\G)\h{4}~m', "\t", $theme_json );
92+
return static::stringify( $data );
93+
}
94+
95+
/**
96+
* Get the user data.
97+
*
98+
* This is a copy of the parent function with the addition of the Gutenberg resolver.
99+
*
100+
* @return array
101+
*/
102+
public static function get_user_data() {
103+
// Determine the correct method to retrieve user data
104+
return class_exists( 'WP_Theme_JSON_Resolver_Gutenberg' )
105+
? WP_Theme_JSON_Resolver_Gutenberg::get_user_data()
106+
: parent::get_user_data();
107+
}
108+
109+
/**
110+
* Stringify the array data.
111+
*
112+
* $data is an array of data to be converted to a JSON string.
113+
* @return string JSON string.
114+
*/
115+
public static function stringify( $data ) {
116+
$data = wp_json_encode( $data, JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
117+
// Convert spaces to tabs
118+
return preg_replace( '~(?:^|\G)\h{4}~m', "\t", $data );
98119
}
99120

100121
public static function get_theme_file_contents() {

includes/create-theme/theme-fonts.php

Lines changed: 26 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -112,19 +112,18 @@ public static function make_filename_from_fontface( $font_face, $src, $src_index
112112
return $font_filename;
113113
}
114114

115-
public static function copy_activated_fonts_to_theme() {
116-
$font_families_to_copy = self::get_user_activated_fonts();
117-
118-
if ( is_null( $font_families_to_copy ) ) {
119-
return;
120-
}
121-
122-
$theme_json = CBT_Theme_JSON_Resolver::get_theme_file_contents();
115+
/*
116+
* Copy the font assets to the theme.
117+
*
118+
* @param array $font_families The font families to copy.
119+
* @return array $font_families The font families with the font face src updated to the theme font asset location.
120+
*/
121+
public static function copy_font_assets_to_theme( $font_families ) {
123122
$theme_font_asset_location = path_join( get_stylesheet_directory(), 'assets/fonts/' );
124123
// Create the font asset directory if it does not exist.
125124
wp_mkdir_p( $theme_font_asset_location );
126125

127-
foreach ( $font_families_to_copy as &$font_family ) {
126+
foreach ( $font_families as &$font_family ) {
128127
if ( ! isset( $font_family['fontFace'] ) ) {
129128
continue;
130129
}
@@ -139,6 +138,10 @@ public static function copy_activated_fonts_to_theme() {
139138
// if it is a string, cast it to an array
140139
$font_face['src'] = (array) $font_face['src'];
141140
foreach ( $font_face['src'] as $font_src_index => &$font_src ) {
141+
if ( str_starts_with( $font_src, 'file:' ) ) {
142+
// If the font source starts with 'file:' then it's already a theme asset.
143+
continue;
144+
}
142145
$font_filename = basename( $font_src );
143146
$font_pretty_filename = self::make_filename_from_fontface( $font_face, $font_src, $font_src_index );
144147
$font_face_path = path_join( $font_family_dir_path, $font_pretty_filename );
@@ -158,9 +161,22 @@ public static function copy_activated_fonts_to_theme() {
158161
}
159162
}
160163

164+
return $font_families;
165+
}
166+
167+
public static function copy_activated_fonts_to_theme() {
168+
$font_families_to_copy = self::get_user_activated_fonts();
169+
170+
if ( is_null( $font_families_to_copy ) ) {
171+
return;
172+
}
173+
174+
$theme_json = CBT_Theme_JSON_Resolver::get_theme_file_contents();
175+
$copied_font_families = self::copy_font_assets_to_theme( $font_families_to_copy );
176+
161177
$theme_json['settings']['typography']['fontFamilies'] = array_merge(
162178
$theme_json['settings']['typography']['fontFamilies'] ?? array(),
163-
$font_families_to_copy
179+
$copied_font_families
164180
);
165181

166182
$user_settings = CBT_Theme_JSON_Resolver::get_user_data()->get_settings();

includes/create-theme/theme-json.php

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public static function add_theme_json_to_local( $export_type ) {
99
);
1010
}
1111

12-
public static function add_theme_json_variation_to_local( $export_type, $theme ) {
12+
public static function add_theme_json_variation_to_local( $export_type, $theme, $save_fonts = false ) {
1313
$variation_path = get_stylesheet_directory() . DIRECTORY_SEPARATOR . 'styles' . DIRECTORY_SEPARATOR;
1414

1515
if ( ! file_exists( $variation_path ) ) {
@@ -20,18 +20,28 @@ public static function add_theme_json_variation_to_local( $export_type, $theme )
2020
return new WP_Error( 'variation_already_exists', __( 'Variation already exists.', 'create-block-theme' ) );
2121
}
2222

23-
$_POST['theme']['variation_slug'] = $theme['slug'];
24-
25-
$extra_theme_data = array(
26-
'version' => WP_Theme_JSON::LATEST_SCHEMA,
27-
'title' => $theme['name'],
28-
);
29-
30-
$variation_theme_json = CBT_Theme_JSON_Resolver::export_theme_data( $export_type, $extra_theme_data );
23+
$theme_json = class_exists( 'WP_Theme_JSON_Gutenberg' ) ? new WP_Theme_JSON_Gutenberg() : new WP_Theme_JSON();
24+
$user_data = CBT_Theme_JSON_Resolver::get_user_data();
25+
$theme_json->merge( $user_data );
26+
$variation = $theme_json->get_data();
27+
$variation['title'] = $theme['name'];
28+
29+
if (
30+
$save_fonts &&
31+
isset( $variation['settings']['typography']['fontFamilies'] )
32+
) {
33+
$font_families = $variation['settings']['typography']['fontFamilies'];
34+
// Copy the font assets to the theme assets folder.
35+
$copied_font_families = CBT_Theme_Fonts::copy_font_assets_to_theme( $font_families );
36+
// Update the the variation theme json with the font families with the new paths.
37+
$variation['settings']['typography']['fontFamilies'] = $copied_font_families;
38+
}
3139

3240
file_put_contents(
3341
$variation_path . $theme['slug'] . '.json',
34-
$variation_theme_json
42+
CBT_Theme_JSON_Resolver::stringify( $variation )
3543
);
44+
45+
return $variation;
3646
}
3747
}

includes/create-theme/theme-patterns.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ public static function pattern_from_template( $template, $new_slug = null ) {
99
/**
1010
* Title: {$template->slug}
1111
* Slug: {$pattern_slug}
12-
* Categories: hidden
1312
* Inserter: no
1413
*/
1514
?>

includes/create-theme/theme-readme.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ public static function create( $theme ) {
5050
$author_uri = $theme['author_uri'] ?? '';
5151
$copy_year = $theme['copyright_year'] ?? gmdate( 'Y' );
5252
$wp_version = $theme['wp_version'] ?? CBT_Theme_Utils::get_current_wordpress_version();
53+
$requires_wp = ( '' === $theme['requires_wp'] ) ? CBT_Theme_Utils::get_current_wordpress_version() : $theme['requires_wp'];
5354
$required_php_version = $theme['required_php_version'] ?? '5.7';
5455
$license = $theme['license'] ?? 'GPLv2 or later';
5556
$license_uri = $theme['license_uri'] ?? 'http://www.gnu.org/licenses/gpl-2.0.html';
@@ -67,7 +68,7 @@ public static function create( $theme ) {
6768
// Adds the Theme section.
6869
$theme_section_content = "
6970
Contributors: {$author}
70-
Requires at least: 6.0
71+
Requires at least: {$requires_wp}
7172
Tested up to: {$wp_version}
7273
Requires PHP: {$required_php_version}
7374
License: {$license}
@@ -210,6 +211,7 @@ public static function update( $theme, $readme_content = '' ) {
210211
$description = $theme['description'] ?? '';
211212
$author = $theme['author'] ?? '';
212213
$wp_version = $theme['wp_version'] ?? CBT_Theme_Utils::get_current_wordpress_version();
214+
$requires_wp = ( '' === $theme['requires_wp'] ) ? CBT_Theme_Utils::get_current_wordpress_version() : $theme['requires_wp'];
213215
$image_credits = $theme['image_credits'] ?? '';
214216
$recommended_plugins = $theme['recommended_plugins'] ?? '';
215217
$font_credits = $theme['font_credits'] ?? '';
@@ -220,6 +222,9 @@ public static function update( $theme, $readme_content = '' ) {
220222
// Update Author/Contributors.
221223
$readme_content = self::add_or_update_prop( 'Contributors', $author, $readme_content );
222224

225+
// Update Required WordPress version.
226+
$readme_content = self::add_or_update_prop( 'Requires at least', $requires_wp, $readme_content );
227+
223228
// Update "Tested up to" version.
224229
$readme_content = self::add_or_update_prop( 'Tested up to', $wp_version, $readme_content );
225230

includes/create-theme/theme-styles.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public static function update_style_css( $style_css, $theme ) {
2525
$author = stripslashes( $theme['author'] );
2626
$author_uri = $theme['author_uri'];
2727
$wp_version = CBT_Theme_Utils::get_current_wordpress_version();
28-
$wp_min = $current_theme->get( 'RequiresWP' );
28+
$requires_wp = ( '' === $theme['requires_wp'] ) ? CBT_Theme_Utils::get_current_wordpress_version() : $theme['requires_wp'];
2929
$version = $theme['version'];
3030
$requires_php = $current_theme->get( 'RequiresPHP' );
3131
$text_domain = $theme['slug'];
@@ -46,7 +46,7 @@ public static function update_style_css( $style_css, $theme ) {
4646
Author: {$author}
4747
Author URI: {$author_uri}
4848
Description: {$description}
49-
Requires at least: {$wp_min}
49+
Requires at least: {$requires_wp}
5050
Tested up to: {$wp_version}
5151
Requires PHP: {$requires_php}
5252
Version: {$version}
@@ -67,6 +67,7 @@ public static function build_style_css( $theme ) {
6767
$uri = $theme['uri'];
6868
$author = stripslashes( $theme['author'] );
6969
$author_uri = $theme['author_uri'];
70+
$requires_wp = ( '' === $theme['requires_wp'] ) ? CBT_Theme_Utils::get_current_wordpress_version() : $theme['requires_wp'];
7071
$wp_version = CBT_Theme_Utils::get_current_wordpress_version();
7172
$text_domain = sanitize_title( $name );
7273
if ( isset( $theme['template'] ) ) {
@@ -85,7 +86,7 @@ public static function build_style_css( $theme ) {
8586
Author: {$author}
8687
Author URI: {$author_uri}
8788
Description: {$description}
88-
Requires at least: 6.0
89+
Requires at least: {$requires_wp}
8990
Tested up to: {$wp_version}
9091
Requires PHP: 5.7
9192
Version: {$version}

0 commit comments

Comments
 (0)