From 8e25b5b87778f2a6747078534abb533fb1ad5702 Mon Sep 17 00:00:00 2001 From: Jeff Ong Date: Tue, 17 Sep 2024 16:51:56 -0400 Subject: [PATCH] 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',