From d3ffe65742c2f4f7390dd42a4469c4324ebf1250 Mon Sep 17 00:00:00 2001 From: Jason Crist Date: Thu, 16 May 2024 11:37:47 -0400 Subject: [PATCH] Use only major.minor version in 'Tested up to' field (#635) Co-authored-by: Matias Benedetto --- admin/create-theme/theme-readme.php | 4 ++-- admin/create-theme/theme-styles.php | 4 ++-- admin/create-theme/theme-utils.php | 11 +++++++++++ tests/CbtThemeReadme/create.php | 2 +- tests/CbtThemeReadme/update.php | 2 +- 5 files changed, 17 insertions(+), 6 deletions(-) diff --git a/admin/create-theme/theme-readme.php b/admin/create-theme/theme-readme.php index ef2a3a96..d904c8b7 100644 --- a/admin/create-theme/theme-readme.php +++ b/admin/create-theme/theme-readme.php @@ -49,7 +49,7 @@ public static function create( $theme ) { $author = $theme['author'] ?? ''; $author_uri = $theme['author_uri'] ?? ''; $copy_year = $theme['copyright_year'] ?? gmdate( 'Y' ); - $wp_version = $theme['wp_version'] ?? get_bloginfo( 'version' ); + $wp_version = $theme['wp_version'] ?? 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'; @@ -201,7 +201,7 @@ public static function update( $theme, $readme_content = '' ) { // Theme data. $description = $theme['description'] ?? ''; $author = $theme['author'] ?? ''; - $wp_version = $theme['wp_version'] ?? get_bloginfo( 'version' ); + $wp_version = $theme['wp_version'] ?? CBT_Theme_Utils::get_current_wordpress_version(); $image_credits = $theme['image_credits'] ?? ''; $recommended_plugins = $theme['recommended_plugins'] ?? ''; diff --git a/admin/create-theme/theme-styles.php b/admin/create-theme/theme-styles.php index 52b52ffb..6864f98b 100644 --- a/admin/create-theme/theme-styles.php +++ b/admin/create-theme/theme-styles.php @@ -24,7 +24,7 @@ public static function update_style_css( $style_css, $theme ) { $uri = $theme['uri']; $author = stripslashes( $theme['author'] ); $author_uri = $theme['author_uri']; - $wp_version = get_bloginfo( 'version' ); + $wp_version = CBT_Theme_Utils::get_current_wordpress_version(); $wp_min = $current_theme->get( 'RequiresWP' ); $version = $theme['version']; $requires_php = $current_theme->get( 'RequiresPHP' ); @@ -67,7 +67,7 @@ public static function build_style_css( $theme ) { $uri = $theme['uri']; $author = stripslashes( $theme['author'] ); $author_uri = $theme['author_uri']; - $wp_version = get_bloginfo( 'version' ); + $wp_version = CBT_Theme_Utils::get_current_wordpress_version(); $text_domain = sanitize_title( $name ); if ( isset( $theme['template'] ) ) { $template = $theme['template']; diff --git a/admin/create-theme/theme-utils.php b/admin/create-theme/theme-utils.php index 9eecacff..372fb579 100644 --- a/admin/create-theme/theme-utils.php +++ b/admin/create-theme/theme-utils.php @@ -208,4 +208,15 @@ public static function replace_screenshot( $new_screenshot_path ) { return CBT_Theme_Utils::copy_screenshot( $new_screenshot_path ); } + /** + * Get the current WordPress version. + * + * @return string The current WordPress in the format x.x (major.minor) + * Example: 6.5 + */ + public static function get_current_wordpress_version() { + $wp_version = get_bloginfo( 'version' ); + $wp_version_parts = explode( '.', $wp_version ); + return $wp_version_parts[0] . '.' . $wp_version_parts[1]; + } } diff --git a/tests/CbtThemeReadme/create.php b/tests/CbtThemeReadme/create.php index 2ecf1ad5..f9d4b0e5 100644 --- a/tests/CbtThemeReadme/create.php +++ b/tests/CbtThemeReadme/create.php @@ -25,7 +25,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_wp_version = 'Tested up to: ' . $data['wp_version'] ?? get_bloginfo( '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']; $expected_license_uri = 'License URI: ' . $data['license_uri']; diff --git a/tests/CbtThemeReadme/update.php b/tests/CbtThemeReadme/update.php index c760ff87..2af65782 100644 --- a/tests/CbtThemeReadme/update.php +++ b/tests/CbtThemeReadme/update.php @@ -22,7 +22,7 @@ public function test_update( $data ) { $readme_without_newlines = str_replace( "\n", '', $readme ); $expected_author = 'Contributors: ' . $data['author']; - $expected_wp_version = 'Tested up to: ' . $data['wp_version'] ?? get_bloginfo( 'version' ); + $expected_wp_version = 'Tested up to: ' . $data['wp_version'] ?? CBT_Theme_Utils::get_current_wordpress_version(); $expected_image_credits = '== Images ==' . $data['image_credits']; $expected_recommended_plugins = '== Recommended Plugins ==' . $data['recommended_plugins'];