diff --git a/admin/create-theme/theme-styles.php b/admin/create-theme/theme-styles.php index f45b00c6..52b52ffb 100644 --- a/admin/create-theme/theme-styles.php +++ b/admin/create-theme/theme-styles.php @@ -9,6 +9,14 @@ class CBT_Theme_Styles { */ public static function update_style_css( $style_css, $theme ) { + $style_data = get_file_data( + path_join( get_stylesheet_directory(), 'style.css' ), + array( + 'License' => 'License', + 'LicenseURI' => 'License URI', + ) + ); + $current_theme = wp_get_theme(); $css_contents = trim( substr( $style_css, strpos( $style_css, '*/' ) + 2 ) ); $name = stripslashes( $theme['name'] ); @@ -17,39 +25,37 @@ public static function update_style_css( $style_css, $theme ) { $author = stripslashes( $theme['author'] ); $author_uri = $theme['author_uri']; $wp_version = get_bloginfo( 'version' ); + $wp_min = $current_theme->get( 'RequiresWP' ); $version = $theme['version']; $requires_php = $current_theme->get( 'RequiresPHP' ); - $template = $current_theme->get( 'Template' ); $text_domain = $theme['slug']; + $template = $current_theme->get( 'Template' ) ? "\n" . 'Template: ' . $current_theme->get( 'Template' ) : ''; + $license = $style_data['License'] ? $style_data['License'] : 'GNU General Public License v2 or later'; + $license_uri = $style_data['LicenseURI'] ? $style_data['LicenseURI'] : 'http://www.gnu.org/licenses/gpl-2.0.html'; + $tags = CBT_Theme_Tags::theme_tags_list( $theme ); + $css_contents = $css_contents ? "\n\n" . $css_contents : ''; + $copyright = ''; + preg_match( '/^\s*\n((?s).*?)\*\/\s*$/m', $style_css, $matches ); + if ( isset( $matches[1] ) ) { + $copyright = "\n" . $matches[1]; + } - //TODO: These items don't seem to be available via ->get('License') calls - $license = 'GNU General Public License v2 or later'; - $license_uri = 'http://www.gnu.org/licenses/gpl-2.0.html'; - $tags = CBT_Theme_Tags::theme_tags_list( $theme ); - $css_metadata = "/* + return "/* Theme Name: {$name} Theme URI: {$uri} Author: {$author} Author URI: {$author_uri} Description: {$description} -Requires at least: 6.0 +Requires at least: {$wp_min} Tested up to: {$wp_version} Requires PHP: {$requires_php} Version: {$version} License: {$license} -License URI: {$license_uri} -"; - - if ( ! empty( $template ) ) { - $css_metadata .= "Template: {$template}\n"; - } - - $css_metadata .= "Text Domain: {$text_domain} +License URI: {$license_uri}{$template} +Text Domain: {$text_domain} Tags: {$tags} -*/ - +{$copyright}*/{$css_contents} "; - return $css_metadata . $css_contents; } /** diff --git a/includes/class-create-block-theme-api.php b/includes/class-create-block-theme-api.php index d4186935..7af9d3b7 100644 --- a/includes/class-create-block-theme-api.php +++ b/includes/class-create-block-theme-api.php @@ -483,13 +483,14 @@ function rest_save_theme( $request ) { private function sanitize_theme_data( $theme ) { $sanitized_theme['name'] = sanitize_text_field( $theme['name'] ); - $sanitized_theme['description'] = sanitize_text_field( $theme['description'] ); - $sanitized_theme['uri'] = sanitize_text_field( $theme['uri'] ); - $sanitized_theme['author'] = sanitize_text_field( $theme['author'] ); - $sanitized_theme['author_uri'] = sanitize_text_field( $theme['author_uri'] ); - $sanitized_theme['tags_custom'] = sanitize_text_field( $theme['tags_custom'] ); - $sanitized_theme['subfolder'] = sanitize_text_field( $theme['subfolder'] ); - $sanitized_theme['recommended_plugins'] = sanitize_textarea_field( $theme['recommended_plugins'] ); + $sanitized_theme['description'] = sanitize_text_field( $theme['description'] ?? '' ); + $sanitized_theme['uri'] = sanitize_text_field( $theme['uri'] ?? '' ); + $sanitized_theme['author'] = sanitize_text_field( $theme['author'] ?? '' ); + $sanitized_theme['author_uri'] = sanitize_text_field( $theme['author_uri'] ?? '' ); + $sanitized_theme['tags_custom'] = sanitize_text_field( $theme['tags_custom'] ?? '' ); + $sanitized_theme['subfolder'] = sanitize_text_field( $theme['subfolder'] ?? '' ); + $sanitized_theme['version'] = sanitize_text_field( $theme['version'] ?? '' ); + $sanitized_theme['recommended_plugins'] = sanitize_textarea_field( $theme['recommended_plugins'] ?? '' ); $sanitized_theme['template'] = ''; $sanitized_theme['slug'] = sanitize_title( $theme['name'] ); $sanitized_theme['text_domain'] = $sanitized_theme['slug'];