From f3d352a0d0fd72fa9502368fda8655c0b3d94f30 Mon Sep 17 00:00:00 2001 From: Jeff Ong Date: Thu, 12 Sep 2024 12:37:13 -0400 Subject: [PATCH] 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; +}