From 1787f9048f1fa10b4bc47139acbfa01286d1ed2c Mon Sep 17 00:00:00 2001 From: Aki Hamano <54422211+t-hamano@users.noreply.github.com> Date: Sun, 28 Apr 2024 22:48:43 +0900 Subject: [PATCH 1/5] Editor Sidebar: Improve screen title UI (#605) --- src/editor-sidebar/create-panel.js | 13 +++--- src/editor-sidebar/create-variation-panel.js | 13 +++--- src/editor-sidebar/save-panel.js | 13 +++--- src/editor-sidebar/screen-header.js | 42 ++++++++++++++++++++ src/plugin-sidebar.js | 16 ++++---- 5 files changed, 67 insertions(+), 30 deletions(-) create mode 100644 src/editor-sidebar/screen-header.js diff --git a/src/editor-sidebar/create-panel.js b/src/editor-sidebar/create-panel.js index 7a20470e..7279f8b9 100644 --- a/src/editor-sidebar/create-panel.js +++ b/src/editor-sidebar/create-panel.js @@ -19,7 +19,9 @@ import { TextControl, TextareaControl, } from '@wordpress/components'; -import { chevronLeft, addCard, copy } from '@wordpress/icons'; +import { addCard, copy } from '@wordpress/icons'; + +import ScreenHeader from './screen-header'; export const CreateThemePanel = ( { createType } ) => { const { createErrorNotice } = useDispatch( noticesStore ); @@ -148,12 +150,9 @@ export const CreateThemePanel = ( { createType } ) => { return ( - - - { __( 'Create Theme', 'create-block-theme' ) } - - - + { const { createErrorNotice } = useDispatch( noticesStore ); @@ -50,12 +52,9 @@ export const CreateVariationPanel = () => { return ( - - - { __( 'Create Variation', 'create-block-theme' ) } - - - + { __( diff --git a/src/editor-sidebar/save-panel.js b/src/editor-sidebar/save-panel.js index 1df877a1..25a7319d 100644 --- a/src/editor-sidebar/save-panel.js +++ b/src/editor-sidebar/save-panel.js @@ -14,7 +14,9 @@ import { Button, CheckboxControl, } from '@wordpress/components'; -import { chevronLeft, archive } from '@wordpress/icons'; +import { archive } from '@wordpress/icons'; + +import ScreenHeader from './screen-header'; export const SaveThemePanel = () => { const [ saveOptions, setSaveOptions ] = useState( { @@ -61,12 +63,9 @@ export const SaveThemePanel = () => { return ( - - - { __( 'Save Changes', 'create-block-theme' ) } - - - + { + return ( + + + + + + { title } + + + + + ); +}; + +export default ScreenHeader; diff --git a/src/plugin-sidebar.js b/src/plugin-sidebar.js index 234d7c67..183a3544 100644 --- a/src/plugin-sidebar.js +++ b/src/plugin-sidebar.js @@ -35,7 +35,6 @@ import { edit, code, chevronRight, - chevronLeft, addCard, blockMeta, } from '@wordpress/icons'; @@ -45,6 +44,7 @@ import ThemeJsonEditorModal from './editor-sidebar/json-editor-modal'; import { SaveThemePanel } from './editor-sidebar/save-panel'; import { CreateVariationPanel } from './editor-sidebar/create-variation-panel'; import { ThemeMetadataEditorModal } from './editor-sidebar/metadata-editor-modal'; +import ScreenHeader from './editor-sidebar/screen-header'; import { downloadExportedTheme } from './resolvers'; const CreateBlockThemePlugin = () => { @@ -181,14 +181,12 @@ const CreateBlockThemePlugin = () => { - - - { __( - 'Create Block Theme', - 'create-block-theme' - ) } - - + { __( From b0c48cdfbc1114aadc954a4fc5fc9d16cf8bef14 Mon Sep 17 00:00:00 2001 From: Aki Hamano <54422211+t-hamano@users.noreply.github.com> Date: Sun, 28 Apr 2024 22:58:50 +0900 Subject: [PATCH 2/5] Editor Sidebar: Make save panel text translatable (#603) * Editor Sidebar: Make save panel text translatable * add another missing translation fn --------- Co-authored-by: Vicente Canales --- src/editor-sidebar/save-panel.js | 58 ++++++++++++++++++++++++-------- 1 file changed, 44 insertions(+), 14 deletions(-) diff --git a/src/editor-sidebar/save-panel.js b/src/editor-sidebar/save-panel.js index 25a7319d..ae3b5680 100644 --- a/src/editor-sidebar/save-panel.js +++ b/src/editor-sidebar/save-panel.js @@ -68,8 +68,11 @@ export const SaveThemePanel = () => { /> { setSaveOptions( { @@ -79,8 +82,11 @@ export const SaveThemePanel = () => { } } /> { setSaveOptions( { @@ -90,8 +96,14 @@ export const SaveThemePanel = () => { } } /> { setSaveOptions( { @@ -101,8 +113,14 @@ export const SaveThemePanel = () => { } } /> { } } /> { } } /> { } } /> Date: Wed, 1 May 2024 01:10:57 +0900 Subject: [PATCH 3/5] Check ZipArchive class before zip export (#609) --- admin/class-create-theme.php | 3 +++ admin/create-theme/form-messages.php | 9 +++++++++ includes/class-create-block-theme-api.php | 7 +++++++ src/plugin-sidebar.js | 11 ++++++++--- src/resolvers.js | 3 --- 5 files changed, 27 insertions(+), 6 deletions(-) diff --git a/admin/class-create-theme.php b/admin/class-create-theme.php index 7462f637..16cd3b2a 100644 --- a/admin/class-create-theme.php +++ b/admin/class-create-theme.php @@ -462,6 +462,9 @@ function blockbase_save_theme() { $this->create_blank_theme( $_POST['theme'], $_FILES['screenshot'] ); add_action( 'admin_notices', array( 'Form_Messages', 'admin_notice_blank_success' ) ); + } elseif ( ! class_exists( 'ZipArchive' ) ) { + // Avoid running if ZipArchive is not enabled. + add_action( 'admin_notices', array( 'Form_Messages', 'admin_notice_error_unsupported_zip_archive' ) ); } elseif ( is_child_theme() ) { if ( 'sibling' === $_POST['theme']['type'] ) { if ( '' === $_POST['theme']['name'] ) { diff --git a/admin/create-theme/form-messages.php b/admin/create-theme/form-messages.php index bb94e070..8bd6f770 100644 --- a/admin/create-theme/form-messages.php +++ b/admin/create-theme/form-messages.php @@ -103,4 +103,13 @@ public static function admin_notice_error_themes_file_permissions() { +
+

+
+ get( 'TextDomain' ); // Create ZIP file in the temporary directory. diff --git a/src/plugin-sidebar.js b/src/plugin-sidebar.js index 183a3544..57ba08e6 100644 --- a/src/plugin-sidebar.js +++ b/src/plugin-sidebar.js @@ -46,6 +46,7 @@ import { CreateVariationPanel } from './editor-sidebar/create-variation-panel'; import { ThemeMetadataEditorModal } from './editor-sidebar/metadata-editor-modal'; import ScreenHeader from './editor-sidebar/screen-header'; import { downloadExportedTheme } from './resolvers'; +import { downloadFile } from './utils'; const CreateBlockThemePlugin = () => { const [ isEditorOpen, setIsEditorOpen ] = useState( false ); @@ -56,8 +57,12 @@ const CreateBlockThemePlugin = () => { const { createErrorNotice } = useDispatch( noticesStore ); - const handleExportClick = () => { - downloadExportedTheme().catch( ( error ) => { + const handleExportClick = async () => { + try { + const response = await downloadExportedTheme(); + downloadFile( response ); + } catch ( errorResponse ) { + const error = await errorResponse.json(); const errorMessage = error.message && error.code !== 'unknown_error' ? error.message @@ -66,7 +71,7 @@ const CreateBlockThemePlugin = () => { 'create-block-theme' ); createErrorNotice( errorMessage, { type: 'snackbar' } ); - } ); + } }; return ( diff --git a/src/resolvers.js b/src/resolvers.js index 446669a6..36aa9260 100644 --- a/src/resolvers.js +++ b/src/resolvers.js @@ -1,5 +1,4 @@ import apiFetch from '@wordpress/api-fetch'; -import { downloadFile } from './utils'; export async function fetchThemeJson() { const fetchOptions = { @@ -57,7 +56,5 @@ export async function downloadExportedTheme() { 'Content-Type': 'application/json', }, parse: false, - } ).then( ( response ) => { - downloadFile( response ); } ); } From 6aa9391d9a481d8317094a2cc548e8a00dd79650 Mon Sep 17 00:00:00 2001 From: Aki Hamano <54422211+t-hamano@users.noreply.github.com> Date: Wed, 1 May 2024 01:12:10 +0900 Subject: [PATCH 4/5] Remove unused `UpdateThemePanel` component (#608) --- src/editor-sidebar/update-panel.js | 238 ----------------------------- 1 file changed, 238 deletions(-) delete mode 100644 src/editor-sidebar/update-panel.js diff --git a/src/editor-sidebar/update-panel.js b/src/editor-sidebar/update-panel.js deleted file mode 100644 index c0420194..00000000 --- a/src/editor-sidebar/update-panel.js +++ /dev/null @@ -1,238 +0,0 @@ -import { __ } from '@wordpress/i18n'; -import { useEffect, useState } from '@wordpress/element'; -import { useDispatch, useSelect } from '@wordpress/data'; -import apiFetch from '@wordpress/api-fetch'; -import { store as noticesStore } from '@wordpress/notices'; -import { - // eslint-disable-next-line - __experimentalVStack as VStack, - // eslint-disable-next-line - __experimentalSpacer as Spacer, - // eslint-disable-next-line - __experimentalText as Text, - // eslint-disable-next-line - __experimentalHeading as Heading, - // eslint-disable-next-line - __experimentalNavigatorToParentButton as NavigatorToParentButton, - PanelBody, - Button, - TextControl, - TextareaControl, - ExternalLink, -} from '@wordpress/components'; -import { chevronLeft } from '@wordpress/icons'; - -export const UpdateThemePanel = () => { - const { createErrorNotice } = useDispatch( noticesStore ); - - const [ theme, setTheme ] = useState( { - name: '', - description: '', - uri: '', - version: '', - author: '', - author_uri: '', - tags_custom: '', - recommended_plugins: '', - } ); - - useEffect( () => { - const getThemeReadmeData = async () => { - return apiFetch( { - path: '/create-block-theme/v1/get-readme-data', - method: 'GET', - } ).then( ( response ) => { - if ( response.status === 'SUCCESS' ) { - return response.data; - } - return {}; - } ); - }; - const setThemeReadmeData = async () => { - const themeReadmeData = await getThemeReadmeData(); - setTheme( ( prevTheme ) => ( { - ...prevTheme, - recommended_plugins: themeReadmeData.recommendedPlugins, - } ) ); - }; - setThemeReadmeData(); - }, [] ); - - useSelect( async ( select ) => { - const themeData = select( 'core' ).getCurrentTheme(); - setTheme( { - name: themeData.name.raw, - description: themeData.description.raw, - uri: themeData.theme_uri.raw, - version: themeData.version, - author: themeData.author.raw, - author_uri: themeData.author_uri.raw, - tags_custom: themeData.tags.rendered, - subfolder: - themeData.stylesheet.lastIndexOf( '/' ) > 1 - ? themeData.stylesheet.substring( - 0, - themeData.stylesheet.lastIndexOf( '/' ) - ) - : '', - } ); - }, [] ); - - const handleUpdateClick = () => { - apiFetch( { - path: '/create-block-theme/v1/update', - method: 'POST', - data: theme, - headers: { - 'Content-Type': 'application/json', - }, - } ) - .then( () => { - // eslint-disable-next-line - alert( - __( - 'Theme updated successfully. The editor will now reload.', - 'create-block-theme' - ) - ); - window.location.reload(); - } ) - .catch( ( error ) => { - const errorMessage = - error.message || - __( - 'An error occurred while attempting to update the theme.', - 'create-block-theme' - ); - createErrorNotice( errorMessage, { type: 'snackbar' } ); - } ); - }; - - return ( - - - - { __( 'Theme Info', 'create-block-theme' ) } - - - - - - { __( - 'Edit Metadata properties of the current theme.', - 'create-block-theme' - ) } - - - - - setTheme( { ...theme, description: value } ) - } - placeholder={ __( - 'A short description of the theme', - 'create-block-theme' - ) } - /> - - setTheme( { ...theme, uri: value } ) - } - placeholder={ __( - 'https://github.com/wordpress/twentytwentythree/', - 'create-block-theme' - ) } - /> - - setTheme( { ...theme, author: value } ) - } - placeholder={ __( - 'the WordPress team', - 'create-block-theme' - ) } - /> - - setTheme( { ...theme, author_uri: value } ) - } - placeholder={ __( - 'https://wordpress.org/', - 'create-block-theme' - ) } - /> - - setTheme( { ...theme, version: value } ) - } - placeholder={ __( - 'Version of the theme', - 'create-block-theme' - ) } - /> - - setTheme( { ...theme, tags_custom: value } ) - } - placeholder={ __( - 'A comma-separated collection of tags', - 'create-block-theme' - ) } - /> - - { __( - 'List the recommended plugins for this theme. e.g. contact forms, social media. Plugins must be from the WordPress.org plugin repository.', - 'create-block-theme' - ) } -
- - { __( 'Read more.', 'create-block-theme' ) } - - - } - // eslint-disable-next-line @wordpress/i18n-no-collapsible-whitespace - placeholder={ __( - `Plugin Name -https://wordpress.org/plugins/plugin-name/ -Plugin Description`, - 'create-block-theme' - ) } - value={ theme.recommended_plugins } - onChange={ ( value ) => - setTheme( { ...theme, recommended_plugins: value } ) - } - /> - - setTheme( { ...theme, subfolder: value } ) - } - /> -
- - -
- ); -}; From 058c6fe25598f712567870645d43361955167c8f Mon Sep 17 00:00:00 2001 From: Matias Benedetto Date: Tue, 30 Apr 2024 13:26:49 -0300 Subject: [PATCH 5/5] Fix custom fonts assets path (#601) * fix custom fonts assets path * improve syntax * Update admin/create-theme/theme-zip.php Co-authored-by: Vicente Canales <1157901+vcanales@users.noreply.github.com> --- admin/create-theme/theme-zip.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/admin/create-theme/theme-zip.php b/admin/create-theme/theme-zip.php index 3ba3fb03..d856af5d 100644 --- a/admin/create-theme/theme-zip.php +++ b/admin/create-theme/theme-zip.php @@ -34,7 +34,7 @@ public static function add_activated_fonts_to_zip( $zip, $theme_json_string ) { $theme_json = json_decode( $theme_json_string, true ); $font_families_to_copy = Theme_Fonts::get_user_activated_fonts(); - $theme_font_asset_location = '/assets/fonts/'; + $theme_font_asset_location = 'assets/fonts'; $font_slugs_to_remove = array(); if ( ! $font_families_to_copy ) { @@ -47,14 +47,15 @@ public static function add_activated_fonts_to_zip( $zip, $theme_json_string ) { } $font_slugs_to_remove[] = $font_family['slug']; foreach ( $font_family['fontFace'] as &$font_face ) { - $font_filename = basename( $font_face['src'] ); - $font_dir = wp_get_font_dir(); + $font_filename = basename( $font_face['src'] ); + $font_dir = wp_get_font_dir(); + $font_face_path = path_join( $theme_font_asset_location, $font_filename ); if ( str_contains( $font_face['src'], $font_dir['url'] ) ) { - $zip->addFileToTheme( $font_dir['path'] . '/' . $font_filename, $theme_font_asset_location . '/' . $font_filename ); + $zip->addFileToTheme( path_join( $font_dir['path'], $font_filename ), $font_face_path ); } else { // otherwise download it from wherever it is hosted $tmp_file = download_url( $font_face['src'] ); - $zip->addFileToTheme( $tmp_file, $theme_font_asset_location . '/' . $font_filename ); + $zip->addFileToTheme( $tmp_file, $font_face_path ); unlink( $tmp_file ); }