Skip to content

Commit

Permalink
Use a dynamic value for Requires at least when theme readme and style…
Browse files Browse the repository at this point in the history
….css are created.
  • Loading branch information
jffng committed Sep 17, 2024
1 parent f983c4e commit 8e25b5b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
3 changes: 2 additions & 1 deletion includes/create-theme/theme-readme.php
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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}
Expand Down
3 changes: 2 additions & 1 deletion includes/create-theme/theme-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ) ) {
Expand All @@ -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}
Expand Down
8 changes: 8 additions & 0 deletions tests/CbtThemeReadme/create.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
Expand All @@ -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.' );

Expand Down Expand Up @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand All @@ -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',
Expand Down

0 comments on commit 8e25b5b

Please sign in to comment.