From 2b4f79af673380d3cfbc8910a9295920eb44e931 Mon Sep 17 00:00:00 2001 From: Jeff Ong Date: Wed, 4 Sep 2024 14:13:45 -0400 Subject: [PATCH 01/12] Add a field for required wordpress version. --- src/editor-sidebar/metadata-editor-modal.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/editor-sidebar/metadata-editor-modal.js b/src/editor-sidebar/metadata-editor-modal.js index ffb78dc6..dd1ccf33 100644 --- a/src/editor-sidebar/metadata-editor-modal.js +++ b/src/editor-sidebar/metadata-editor-modal.js @@ -45,6 +45,7 @@ export const ThemeMetadataEditorModal = ( { onRequestClose } ) => { description: '', uri: '', version: '', + wp_version: '', author: '', author_uri: '', tags_custom: '', @@ -65,6 +66,7 @@ export const ThemeMetadataEditorModal = ( { onRequestClose } ) => { description: themeData.description.raw, uri: themeData.theme_uri.raw, version: themeData.version, + wp_version: themeData.requires_wp, author: themeData.author.raw, author_uri: themeData.author_uri.raw, tags_custom: themeData.tags.rendered, @@ -212,6 +214,18 @@ export const ThemeMetadataEditorModal = ( { onRequestClose } ) => { 'create-block-theme' ) } /> + + setTheme( { ...theme, wp_version: value } ) + } + /* translators: %s: minimum WordPress version required. */ + placeholder={ __( '5.9', 'create-block-theme' ) } + /> Date: Wed, 4 Sep 2024 14:15:42 -0400 Subject: [PATCH 02/12] Add a minimum required version if none exists. --- includes/create-theme/theme-styles.php | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/includes/create-theme/theme-styles.php b/includes/create-theme/theme-styles.php index 6864f98b..0865c9df 100644 --- a/includes/create-theme/theme-styles.php +++ b/includes/create-theme/theme-styles.php @@ -26,15 +26,18 @@ public static function update_style_css( $style_css, $theme ) { $author_uri = $theme['author_uri']; $wp_version = CBT_Theme_Utils::get_current_wordpress_version(); $wp_min = $current_theme->get( 'RequiresWP' ); - $version = $theme['version']; - $requires_php = $current_theme->get( 'RequiresPHP' ); - $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 = ''; + if ( ! $wp_min ) { + $wp_min = '5.9'; + } + $version = $theme['version']; + $requires_php = $current_theme->get( 'RequiresPHP' ); + $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]; From b1d1558edea9a222483ba08bb7953c9565ab723c Mon Sep 17 00:00:00 2001 From: Jeff Ong Date: Thu, 5 Sep 2024 15:47:21 -0400 Subject: [PATCH 03/12] Sanitize the requires_wp attribute. --- includes/class-create-block-theme-api.php | 1 + includes/create-theme/theme-styles.php | 24 +++++++++++------------ 2 files changed, 12 insertions(+), 13 deletions(-) diff --git a/includes/class-create-block-theme-api.php b/includes/class-create-block-theme-api.php index 1593ebe0..3e50b574 100644 --- a/includes/class-create-block-theme-api.php +++ b/includes/class-create-block-theme-api.php @@ -458,6 +458,7 @@ private function sanitize_theme_data( $theme ) { $sanitized_theme['subfolder'] = sanitize_text_field( $theme['subfolder'] ?? '' ); $sanitized_theme['version'] = sanitize_text_field( $theme['version'] ?? '' ); $sanitized_theme['screenshot'] = sanitize_text_field( $theme['screenshot'] ?? '' ); + $sanitized_theme['requires_wp'] = sanitize_text_field( $theme['requires_wp'] ?? '' ); $sanitized_theme['recommended_plugins'] = sanitize_textarea_field( $theme['recommended_plugins'] ?? '' ); $sanitized_theme['font_credits'] = sanitize_textarea_field( $theme['font_credits'] ?? '' ); $sanitized_theme['image_credits'] = sanitize_textarea_field( $theme['image_credits'] ?? '' ); diff --git a/includes/create-theme/theme-styles.php b/includes/create-theme/theme-styles.php index 0865c9df..ca31e9fd 100644 --- a/includes/create-theme/theme-styles.php +++ b/includes/create-theme/theme-styles.php @@ -25,19 +25,17 @@ public static function update_style_css( $style_css, $theme ) { $author = stripslashes( $theme['author'] ); $author_uri = $theme['author_uri']; $wp_version = CBT_Theme_Utils::get_current_wordpress_version(); - $wp_min = $current_theme->get( 'RequiresWP' ); - if ( ! $wp_min ) { - $wp_min = '5.9'; - } - $version = $theme['version']; - $requires_php = $current_theme->get( 'RequiresPHP' ); - $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 = ''; + $wp_min = $theme['requires_wp']; + $wp_min = $wp_min ? $wp_min : '6.0'; + $version = $theme['version']; + $requires_php = $current_theme->get( 'RequiresPHP' ); + $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]; From 09e3679aa59c0813297abdc5e8c2875c771138d5 Mon Sep 17 00:00:00 2001 From: Jeff Ong Date: Thu, 5 Sep 2024 15:48:03 -0400 Subject: [PATCH 04/12] Use SelectControl instead of TextControl and rename attribute to requires_wp. --- src/editor-sidebar/metadata-editor-modal.js | 33 +++++++++++++++------ 1 file changed, 24 insertions(+), 9 deletions(-) diff --git a/src/editor-sidebar/metadata-editor-modal.js b/src/editor-sidebar/metadata-editor-modal.js index dd1ccf33..f8f72b40 100644 --- a/src/editor-sidebar/metadata-editor-modal.js +++ b/src/editor-sidebar/metadata-editor-modal.js @@ -18,6 +18,7 @@ import { FormTokenField, Modal, Button, + SelectControl, TextControl, TextareaControl, ExternalLink, @@ -39,13 +40,25 @@ const ALLOWED_SCREENSHOT_MEDIA_TYPES = [ 'image/avif', ]; +const WP_MINIMUM_VERSIONS = [ + '5.9', + '6.0', + '6.1', + '6.2', + '6.3', + '6.4', + '6.5', + '6.6', + '6.7', +]; + export const ThemeMetadataEditorModal = ( { onRequestClose } ) => { const [ theme, setTheme ] = useState( { name: '', description: '', uri: '', version: '', - wp_version: '', + requires_wp: '', author: '', author_uri: '', tags_custom: '', @@ -66,7 +79,7 @@ export const ThemeMetadataEditorModal = ( { onRequestClose } ) => { description: themeData.description.raw, uri: themeData.theme_uri.raw, version: themeData.version, - wp_version: themeData.requires_wp, + requires_wp: themeData.requires_wp, author: themeData.author.raw, author_uri: themeData.author_uri.raw, tags_custom: themeData.tags.rendered, @@ -214,17 +227,19 @@ export const ThemeMetadataEditorModal = ( { onRequestClose } ) => { 'create-block-theme' ) } /> - - setTheme( { ...theme, wp_version: value } ) - } - /* translators: %s: minimum WordPress version required. */ - placeholder={ __( '5.9', 'create-block-theme' ) } + value={ theme.requires_wp } + options={ WP_MINIMUM_VERSIONS.map( ( version ) => ( { + label: version, + value: version, + } ) ) } + onChange={ ( value ) => { + setTheme( { ...theme, requires_wp: value } ); + } } /> Date: Wed, 11 Sep 2024 17:14:38 -0400 Subject: [PATCH 05/12] Update includes/create-theme/theme-styles.php Co-authored-by: Grant Kinney --- includes/create-theme/theme-styles.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/includes/create-theme/theme-styles.php b/includes/create-theme/theme-styles.php index ca31e9fd..16d62e49 100644 --- a/includes/create-theme/theme-styles.php +++ b/includes/create-theme/theme-styles.php @@ -25,8 +25,7 @@ public static function update_style_css( $style_css, $theme ) { $author = stripslashes( $theme['author'] ); $author_uri = $theme['author_uri']; $wp_version = CBT_Theme_Utils::get_current_wordpress_version(); - $wp_min = $theme['requires_wp']; - $wp_min = $wp_min ? $wp_min : '6.0'; + $wp_min = isset( $theme['requires_wp'] ) && $theme['requires_wp'] ? $theme['requires_wp'] : '6.0'; $version = $theme['version']; $requires_php = $current_theme->get( 'RequiresPHP' ); $text_domain = $theme['slug']; From f3d352a0d0fd72fa9502368fda8655c0b3d94f30 Mon Sep 17 00:00:00 2001 From: Jeff Ong Date: Thu, 12 Sep 2024 12:37:13 -0400 Subject: [PATCH 06/12] Try generating the minimum versions instead. --- .../class-create-block-theme-editor-tools.php | 7 +++++++ src/editor-sidebar/metadata-editor-modal.js | 13 ++---------- src/utils/generate-versions.js | 21 +++++++++++++++++++ 3 files changed, 30 insertions(+), 11 deletions(-) create mode 100644 src/utils/generate-versions.js diff --git a/includes/class-create-block-theme-editor-tools.php b/includes/class-create-block-theme-editor-tools.php index a88d18af..876f2363 100644 --- a/includes/class-create-block-theme-editor-tools.php +++ b/includes/class-create-block-theme-editor-tools.php @@ -38,6 +38,13 @@ function create_block_theme_sidebar_enqueue() { 'create-block-theme-slot-fill', ); + global $wp_version; + wp_add_inline_script( + 'create-block-theme-slot-fill', + 'const WP_VERSION = "' . $wp_version . '";', + 'before' + ); + // Enable localization in the plugin sidebar. wp_set_script_translations( 'create-block-theme-slot-fill', 'create-block-theme' ); } diff --git a/src/editor-sidebar/metadata-editor-modal.js b/src/editor-sidebar/metadata-editor-modal.js index f8f72b40..2cc2b87f 100644 --- a/src/editor-sidebar/metadata-editor-modal.js +++ b/src/editor-sidebar/metadata-editor-modal.js @@ -30,6 +30,7 @@ import { MediaUpload, MediaUploadCheck } from '@wordpress/block-editor'; */ import { postUpdateThemeMetadata, fetchReadmeData } from '../resolvers'; import { getFontsCreditsText } from '../utils/fonts'; +import { generateWpVersions } from '../utils/generate-versions'; const ALLOWED_SCREENSHOT_MEDIA_TYPES = [ 'image/png', @@ -40,17 +41,7 @@ const ALLOWED_SCREENSHOT_MEDIA_TYPES = [ 'image/avif', ]; -const WP_MINIMUM_VERSIONS = [ - '5.9', - '6.0', - '6.1', - '6.2', - '6.3', - '6.4', - '6.5', - '6.6', - '6.7', -]; +const WP_MINIMUM_VERSIONS = generateWpVersions( WP_VERSION ); // eslint-disable-line no-undef export const ThemeMetadataEditorModal = ( { onRequestClose } ) => { const [ theme, setTheme ] = useState( { diff --git a/src/utils/generate-versions.js b/src/utils/generate-versions.js new file mode 100644 index 00000000..75c20859 --- /dev/null +++ b/src/utils/generate-versions.js @@ -0,0 +1,21 @@ +export function generateWpVersions( versionString ) { + const version = versionString.split( '-' )[ 0 ]; + let [ major, minor ] = version.split( '.' ).slice( 0, 2 ).map( Number ); + + const versions = []; + + // Iterate through the versions from current to 5.9 + while ( major > 5 || ( major === 5 && minor >= 9 ) ) { + versions.push( `${ major }.${ minor }` ); + + // Decrement minor version + if ( minor === 0 ) { + minor = 9; // Wrap around if minor is 0, decrement the major version + major--; + } else { + minor--; + } + } + + return versions; +} From 416b149e4c243ebc2cf4b7653b86b5a12c3e7a03 Mon Sep 17 00:00:00 2001 From: Jeff Ong Date: Tue, 17 Sep 2024 16:41:14 -0400 Subject: [PATCH 07/12] Ensure Required WP version is updated when readme is updated. --- includes/create-theme/theme-readme.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/includes/create-theme/theme-readme.php b/includes/create-theme/theme-readme.php index 2da3b57c..f3274dff 100644 --- a/includes/create-theme/theme-readme.php +++ b/includes/create-theme/theme-readme.php @@ -210,6 +210,7 @@ public static function update( $theme, $readme_content = '' ) { $description = $theme['description'] ?? ''; $author = $theme['author'] ?? ''; $wp_version = $theme['wp_version'] ?? CBT_Theme_Utils::get_current_wordpress_version(); + $wp_min = $theme['requires_wp'] ?? CBT_Theme_Utils::get_current_wordpress_version(); $image_credits = $theme['image_credits'] ?? ''; $recommended_plugins = $theme['recommended_plugins'] ?? ''; $font_credits = $theme['font_credits'] ?? ''; @@ -220,6 +221,9 @@ public static function update( $theme, $readme_content = '' ) { // Update Author/Contributors. $readme_content = self::add_or_update_prop( 'Contributors', $author, $readme_content ); + // Update Required WordPress version. + $readme_content = self::add_or_update_prop( 'Requires at least', $wp_min, $readme_content ); + // Update "Tested up to" version. $readme_content = self::add_or_update_prop( 'Tested up to', $wp_version, $readme_content ); From f983c4e2dc630fe81a7b36fb25eee6a506b8533d Mon Sep 17 00:00:00 2001 From: Jeff Ong Date: Tue, 17 Sep 2024 16:41:36 -0400 Subject: [PATCH 08/12] Use current wordpress version if none is provided. --- includes/create-theme/theme-styles.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/includes/create-theme/theme-styles.php b/includes/create-theme/theme-styles.php index 16d62e49..b5732e2d 100644 --- a/includes/create-theme/theme-styles.php +++ b/includes/create-theme/theme-styles.php @@ -25,7 +25,7 @@ public static function update_style_css( $style_css, $theme ) { $author = stripslashes( $theme['author'] ); $author_uri = $theme['author_uri']; $wp_version = CBT_Theme_Utils::get_current_wordpress_version(); - $wp_min = isset( $theme['requires_wp'] ) && $theme['requires_wp'] ? $theme['requires_wp'] : '6.0'; + $wp_min = $theme['requires_wp'] ?? CBT_Theme_Utils::get_current_wordpress_version(); $version = $theme['version']; $requires_php = $current_theme->get( 'RequiresPHP' ); $text_domain = $theme['slug']; From 8e25b5b87778f2a6747078534abb533fb1ad5702 Mon Sep 17 00:00:00 2001 From: Jeff Ong Date: Tue, 17 Sep 2024 16:51:56 -0400 Subject: [PATCH 09/12] Use a dynamic value for Requires at least when theme readme and style.css are created. --- includes/create-theme/theme-readme.php | 3 ++- includes/create-theme/theme-styles.php | 3 ++- tests/CbtThemeReadme/create.php | 8 ++++++++ 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/includes/create-theme/theme-readme.php b/includes/create-theme/theme-readme.php index f3274dff..4a9be1b7 100644 --- a/includes/create-theme/theme-readme.php +++ b/includes/create-theme/theme-readme.php @@ -50,6 +50,7 @@ public static function create( $theme ) { $author_uri = $theme['author_uri'] ?? ''; $copy_year = $theme['copyright_year'] ?? gmdate( 'Y' ); $wp_version = $theme['wp_version'] ?? CBT_Theme_Utils::get_current_wordpress_version(); + $requires_wp = $theme['requires_wp'] ?? CBT_Theme_Utils::get_current_wordpress_version(); $required_php_version = $theme['required_php_version'] ?? '5.7'; $license = $theme['license'] ?? 'GPLv2 or later'; $license_uri = $theme['license_uri'] ?? 'http://www.gnu.org/licenses/gpl-2.0.html'; @@ -67,7 +68,7 @@ public static function create( $theme ) { // Adds the Theme section. $theme_section_content = " Contributors: {$author} -Requires at least: 6.0 +Requires at least: {$requires_wp} Tested up to: {$wp_version} Requires PHP: {$required_php_version} License: {$license} diff --git a/includes/create-theme/theme-styles.php b/includes/create-theme/theme-styles.php index b5732e2d..fb97b128 100644 --- a/includes/create-theme/theme-styles.php +++ b/includes/create-theme/theme-styles.php @@ -67,6 +67,7 @@ public static function build_style_css( $theme ) { $uri = $theme['uri']; $author = stripslashes( $theme['author'] ); $author_uri = $theme['author_uri']; + $wp_min = $theme['requires_wp'] ?? CBT_Theme_Utils::get_current_wordpress_version(); $wp_version = CBT_Theme_Utils::get_current_wordpress_version(); $text_domain = sanitize_title( $name ); if ( isset( $theme['template'] ) ) { @@ -85,7 +86,7 @@ public static function build_style_css( $theme ) { 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: 5.7 Version: {$version} diff --git a/tests/CbtThemeReadme/create.php b/tests/CbtThemeReadme/create.php index 6faff42c..3c738c4b 100644 --- a/tests/CbtThemeReadme/create.php +++ b/tests/CbtThemeReadme/create.php @@ -28,6 +28,7 @@ public function test_create( $data ) { $expected_uri = 'Theme URI: ' . $data['uri']; $expected_author = 'Contributors: ' . $data['author']; $expected_author_uri = 'Author URI: ' . $data['author_uri']; + $expected_requires_wp = 'Requires at least: ' . $data['requires_wp'] ?? CBT_Theme_Utils::get_current_wordpress_version(); $expected_wp_version = 'Tested up to: ' . $data['wp_version'] ?? CBT_Theme_Utils::get_current_wordpress_version(); $expected_php_version = 'Requires PHP: ' . $data['required_php_version']; $expected_license = 'License: ' . $data['license']; @@ -46,6 +47,7 @@ public function test_create( $data ) { $this->assertStringContainsString( $expected_name, $readme_without_newlines, 'The expected name is missing.' ); $this->assertStringContainsString( $expected_author, $readme_without_newlines, 'The expected author is missing.' ); + $this->assertStringContainsString( $expected_requires_wp, $readme_without_newlines, 'The expected Requires at least version is missing.' ); $this->assertStringContainsString( $expected_wp_version, $readme_without_newlines, 'The expected WP version is missing.' ); $this->assertStringContainsString( $expected_recommended_plugins, $readme_without_newlines, 'The expected recommended plugins are missing.' ); @@ -94,6 +96,7 @@ public function data_test_create() { 'author_uri' => 'https://example.com/author', 'copyright_year' => '2077', 'wp_version' => '12.12', + 'requires_wp' => '12.12', 'required_php_version' => '10.0', 'license' => 'GPLv2 or later', 'license_uri' => 'https://www.gnu.org/licenses/gpl-2.0.html', @@ -110,6 +113,7 @@ public function data_test_create() { 'author' => 'New theme author', 'author_uri' => 'https://example.com/author', 'copyright_year' => '2078', + 'requires_wp' => '12.12', 'wp_version' => '13.13', 'required_php_version' => '11.0', 'license' => 'GPLv2 or later', @@ -128,6 +132,7 @@ public function data_test_create() { 'author' => 'New theme author', 'author_uri' => 'https://example.com/author', 'copyright_year' => '2079', + 'requires_wp' => '12.12', 'wp_version' => '14.14', 'required_php_version' => '12.0', 'license' => 'GPLv2 or later', @@ -146,6 +151,7 @@ public function data_test_create() { 'author' => 'New theme author', 'author_uri' => 'https://example.com/author', 'copyright_year' => '2077', + 'requires_wp' => '12.12', 'wp_version' => '12.12', 'required_php_version' => '10.0', 'license' => 'GPLv2 or later', @@ -162,6 +168,7 @@ public function data_test_create() { 'author' => 'New theme author', 'author_uri' => 'https://example.com/author', 'copyright_year' => '2077', + 'requires_wp' => '12.12', 'wp_version' => '12.12', 'required_php_version' => '10.0', 'license' => 'GPLv2 or later', @@ -182,6 +189,7 @@ public function data_test_create() { 'author' => 'New theme author', 'author_uri' => 'https://example.com/author', 'copyright_year' => '2077', + 'requires_wp' => '12.12', 'wp_version' => '12.12', 'required_php_version' => '10.0', 'license' => 'GPLv2 or later', From 52bbdb5608fa821fee831ff671899d994f3576ad Mon Sep 17 00:00:00 2001 From: Jeff Ong Date: Tue, 17 Sep 2024 16:58:18 -0400 Subject: [PATCH 10/12] Make variable names consistent. --- includes/create-theme/theme-readme.php | 4 ++-- includes/create-theme/theme-styles.php | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/includes/create-theme/theme-readme.php b/includes/create-theme/theme-readme.php index 4a9be1b7..6c3136c9 100644 --- a/includes/create-theme/theme-readme.php +++ b/includes/create-theme/theme-readme.php @@ -211,7 +211,7 @@ public static function update( $theme, $readme_content = '' ) { $description = $theme['description'] ?? ''; $author = $theme['author'] ?? ''; $wp_version = $theme['wp_version'] ?? CBT_Theme_Utils::get_current_wordpress_version(); - $wp_min = $theme['requires_wp'] ?? CBT_Theme_Utils::get_current_wordpress_version(); + $requires_wp = $theme['requires_wp'] ?? CBT_Theme_Utils::get_current_wordpress_version(); $image_credits = $theme['image_credits'] ?? ''; $recommended_plugins = $theme['recommended_plugins'] ?? ''; $font_credits = $theme['font_credits'] ?? ''; @@ -223,7 +223,7 @@ public static function update( $theme, $readme_content = '' ) { $readme_content = self::add_or_update_prop( 'Contributors', $author, $readme_content ); // Update Required WordPress version. - $readme_content = self::add_or_update_prop( 'Requires at least', $wp_min, $readme_content ); + $readme_content = self::add_or_update_prop( 'Requires at least', $requires_wp, $readme_content ); // Update "Tested up to" version. $readme_content = self::add_or_update_prop( 'Tested up to', $wp_version, $readme_content ); diff --git a/includes/create-theme/theme-styles.php b/includes/create-theme/theme-styles.php index fb97b128..3bd70e4c 100644 --- a/includes/create-theme/theme-styles.php +++ b/includes/create-theme/theme-styles.php @@ -25,7 +25,7 @@ public static function update_style_css( $style_css, $theme ) { $author = stripslashes( $theme['author'] ); $author_uri = $theme['author_uri']; $wp_version = CBT_Theme_Utils::get_current_wordpress_version(); - $wp_min = $theme['requires_wp'] ?? CBT_Theme_Utils::get_current_wordpress_version(); + $requires_wp = $theme['requires_wp'] ?? CBT_Theme_Utils::get_current_wordpress_version(); $version = $theme['version']; $requires_php = $current_theme->get( 'RequiresPHP' ); $text_domain = $theme['slug']; @@ -46,7 +46,7 @@ public static function update_style_css( $style_css, $theme ) { Author: {$author} Author URI: {$author_uri} Description: {$description} -Requires at least: {$wp_min} +Requires at least: {$requires_wp} Tested up to: {$wp_version} Requires PHP: {$requires_php} Version: {$version} @@ -67,7 +67,7 @@ public static function build_style_css( $theme ) { $uri = $theme['uri']; $author = stripslashes( $theme['author'] ); $author_uri = $theme['author_uri']; - $wp_min = $theme['requires_wp'] ?? CBT_Theme_Utils::get_current_wordpress_version(); + $requires_wp = $theme['requires_wp'] ?? CBT_Theme_Utils::get_current_wordpress_version(); $wp_version = CBT_Theme_Utils::get_current_wordpress_version(); $text_domain = sanitize_title( $name ); if ( isset( $theme['template'] ) ) { @@ -86,7 +86,7 @@ public static function build_style_css( $theme ) { Author: {$author} Author URI: {$author_uri} Description: {$description} -Requires at least: {$wp_min} +Requires at least: {$requires_wp} Tested up to: {$wp_version} Requires PHP: 5.7 Version: {$version} From b3b33861b5a1621dde5bb278cca3ba99e62f804b Mon Sep 17 00:00:00 2001 From: Jeff Ong Date: Wed, 18 Sep 2024 13:53:58 -0400 Subject: [PATCH 11/12] Check for empty string and use current wordpress version as fallback. --- includes/create-theme/theme-readme.php | 4 ++-- includes/create-theme/theme-styles.php | 4 ++-- tests/CbtThemeReadme/update.php | 3 +++ 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/includes/create-theme/theme-readme.php b/includes/create-theme/theme-readme.php index 6c3136c9..be428bbc 100644 --- a/includes/create-theme/theme-readme.php +++ b/includes/create-theme/theme-readme.php @@ -50,7 +50,7 @@ public static function create( $theme ) { $author_uri = $theme['author_uri'] ?? ''; $copy_year = $theme['copyright_year'] ?? gmdate( 'Y' ); $wp_version = $theme['wp_version'] ?? CBT_Theme_Utils::get_current_wordpress_version(); - $requires_wp = $theme['requires_wp'] ?? CBT_Theme_Utils::get_current_wordpress_version(); + $requires_wp = ( '' === $theme['requires_wp'] ) ? CBT_Theme_Utils::get_current_wordpress_version() : $theme['requires_wp']; $required_php_version = $theme['required_php_version'] ?? '5.7'; $license = $theme['license'] ?? 'GPLv2 or later'; $license_uri = $theme['license_uri'] ?? 'http://www.gnu.org/licenses/gpl-2.0.html'; @@ -211,7 +211,7 @@ public static function update( $theme, $readme_content = '' ) { $description = $theme['description'] ?? ''; $author = $theme['author'] ?? ''; $wp_version = $theme['wp_version'] ?? CBT_Theme_Utils::get_current_wordpress_version(); - $requires_wp = $theme['requires_wp'] ?? CBT_Theme_Utils::get_current_wordpress_version(); + $requires_wp = ( '' === $theme['requires_wp'] ) ? CBT_Theme_Utils::get_current_wordpress_version() : $theme['requires_wp']; $image_credits = $theme['image_credits'] ?? ''; $recommended_plugins = $theme['recommended_plugins'] ?? ''; $font_credits = $theme['font_credits'] ?? ''; diff --git a/includes/create-theme/theme-styles.php b/includes/create-theme/theme-styles.php index 3bd70e4c..e1fb4cb7 100644 --- a/includes/create-theme/theme-styles.php +++ b/includes/create-theme/theme-styles.php @@ -25,7 +25,7 @@ public static function update_style_css( $style_css, $theme ) { $author = stripslashes( $theme['author'] ); $author_uri = $theme['author_uri']; $wp_version = CBT_Theme_Utils::get_current_wordpress_version(); - $requires_wp = $theme['requires_wp'] ?? CBT_Theme_Utils::get_current_wordpress_version(); + $requires_wp = ( '' === $theme['requires_wp'] ) ? CBT_Theme_Utils::get_current_wordpress_version() : $theme['requires_wp']; $version = $theme['version']; $requires_php = $current_theme->get( 'RequiresPHP' ); $text_domain = $theme['slug']; @@ -67,7 +67,7 @@ public static function build_style_css( $theme ) { $uri = $theme['uri']; $author = stripslashes( $theme['author'] ); $author_uri = $theme['author_uri']; - $requires_wp = $theme['requires_wp'] ?? CBT_Theme_Utils::get_current_wordpress_version(); + $requires_wp = ( '' === $theme['requires_wp'] ) ? CBT_Theme_Utils::get_current_wordpress_version() : $theme['requires_wp']; $wp_version = CBT_Theme_Utils::get_current_wordpress_version(); $text_domain = sanitize_title( $name ); if ( isset( $theme['template'] ) ) { diff --git a/tests/CbtThemeReadme/update.php b/tests/CbtThemeReadme/update.php index d6ca9012..6144f47e 100644 --- a/tests/CbtThemeReadme/update.php +++ b/tests/CbtThemeReadme/update.php @@ -48,6 +48,7 @@ public function data_test_update() { 'description' => 'New theme description', 'author' => 'New theme author', 'wp_version' => '12.12', + 'requires_wp' => '', 'image_credits' => 'New image credits', 'recommended_plugins' => 'New recommended plugins', 'font_credits' => 'Example font credits text', @@ -58,6 +59,7 @@ public function data_test_update() { 'description' => 'New theme description', 'author' => 'New theme author', 'wp_version' => '12.12', + 'requires_wp' => '', 'image_credits' => 'New image credits', 'recommended_plugins' => 'New recommended plugins', ), @@ -71,6 +73,7 @@ public function data_test_update() { 'description' => 'New theme description', 'author' => 'New theme author', 'wp_version' => '12.12', + 'requires_wp' => '', 'image_credits' => "New image credits \r\n New image credits 2", 'recommended_plugins' => "Plugin1 \r\n Plugin2 \r\n Plugin3", 'font_credits' => "Font1 \r\n Font2 \r\n Font3", From 2f9225f097fd0cdf1ed3dc6159fd6048d6d3d257 Mon Sep 17 00:00:00 2001 From: Jeff Ong Date: Wed, 18 Sep 2024 13:54:16 -0400 Subject: [PATCH 12/12] Add minimum version to additional metadata panel. --- src/editor-sidebar/create-panel.js | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/src/editor-sidebar/create-panel.js b/src/editor-sidebar/create-panel.js index b80aa1fb..951c03a0 100644 --- a/src/editor-sidebar/create-panel.js +++ b/src/editor-sidebar/create-panel.js @@ -14,6 +14,7 @@ import { __experimentalText as Text, PanelBody, Button, + SelectControl, TextControl, TextareaControl, } from '@wordpress/components'; @@ -28,6 +29,9 @@ import { createClonedTheme, createChildTheme, } from '../resolvers'; +import { generateWpVersions } from '../utils/generate-versions'; + +const WP_MINIMUM_VERSIONS = generateWpVersions( WP_VERSION ); // eslint-disable-line no-undef export const CreateThemePanel = ( { createType } ) => { const { createErrorNotice } = useDispatch( noticesStore ); @@ -47,6 +51,7 @@ export const CreateThemePanel = ( { createType } ) => { author: '', author_uri: '', tags_custom: '', + requires_wp: '', subfolder, } ); @@ -195,6 +200,20 @@ export const CreateThemePanel = ( { createType } ) => { 'create-block-theme' ) } /> + ( { + label: version, + value: version, + } ) ) } + onChange={ ( value ) => { + setTheme( { ...theme, requires_wp: value } ); + } } + />
{ createType === 'createClone' && (