Skip to content

Commit

Permalink
Try generating the minimum versions instead.
Browse files Browse the repository at this point in the history
  • Loading branch information
jffng committed Sep 12, 2024
1 parent 08aa63e commit f3d352a
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 11 deletions.
7 changes: 7 additions & 0 deletions includes/class-create-block-theme-editor-tools.php
Original file line number Diff line number Diff line change
Expand Up @@ -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' );
}
Expand Down
13 changes: 2 additions & 11 deletions src/editor-sidebar/metadata-editor-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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( {
Expand Down
21 changes: 21 additions & 0 deletions src/utils/generate-versions.js
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit f3d352a

Please sign in to comment.