Skip to content

Commit

Permalink
Merge branch 'trunk' into fix/download-zip-windows
Browse files Browse the repository at this point in the history
  • Loading branch information
pbking authored Apr 30, 2024
2 parents 8ec8e47 + 058c6fe commit 7a70ba1
Show file tree
Hide file tree
Showing 11 changed files with 144 additions and 293 deletions.
3 changes: 3 additions & 0 deletions admin/class-create-theme.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ) {
Expand Down
9 changes: 9 additions & 0 deletions admin/create-theme/form-messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,4 +103,13 @@ public static function admin_notice_error_themes_file_permissions() {
</div>
<?php
}

public static function admin_notice_error_unsupported_zip_archive() {
$themes_dir = get_theme_root();
?>
<div class="notice notice-error">
<p><?php _e( 'Unable to create a zip file. ZipArchive not available.', 'create-block-theme' ); ?></p>
</div>
<?php
}
}
11 changes: 6 additions & 5 deletions admin/create-theme/theme-zip.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ) {
Expand All @@ -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 );
}

Expand Down
7 changes: 7 additions & 0 deletions includes/class-create-block-theme-api.php
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,13 @@ function rest_export_child_cloned_theme( $request ) {
* Export the theme as a ZIP file.
*/
function rest_export_theme( $request ) {
if ( ! class_exists( 'ZipArchive' ) ) {
return new WP_Error(
'missing_zip_package',
__( 'Unable to create a zip file. ZipArchive not available.', 'create-block-theme' ),
);
}

$theme_slug = wp_get_theme()->get( 'TextDomain' );

// Create ZIP file in the temporary directory.
Expand Down
13 changes: 6 additions & 7 deletions src/editor-sidebar/create-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 );
Expand Down Expand Up @@ -148,12 +150,9 @@ export const CreateThemePanel = ( { createType } ) => {

return (
<PanelBody>
<Heading>
<NavigatorToParentButton icon={ chevronLeft }>
{ __( 'Create Theme', 'create-block-theme' ) }
</NavigatorToParentButton>
</Heading>

<ScreenHeader
title={ __( 'Create Theme', 'create-block-theme' ) }
/>
<VStack>
<TextControl
label={ __( 'Theme name', 'create-block-theme' ) }
Expand Down
13 changes: 6 additions & 7 deletions src/editor-sidebar/create-variation-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@ import {
Button,
TextControl,
} from '@wordpress/components';
import { chevronLeft, copy } from '@wordpress/icons';
import { copy } from '@wordpress/icons';
import { postCreateThemeVariation } from '../resolvers';

import ScreenHeader from './screen-header';

export const CreateVariationPanel = () => {
const { createErrorNotice } = useDispatch( noticesStore );

Expand Down Expand Up @@ -50,12 +52,9 @@ export const CreateVariationPanel = () => {

return (
<PanelBody>
<Heading>
<NavigatorToParentButton icon={ chevronLeft }>
{ __( 'Create Variation', 'create-block-theme' ) }
</NavigatorToParentButton>
</Heading>

<ScreenHeader
title={ __( 'Create Variation', 'create-block-theme' ) }
/>
<VStack>
<Text>
{ __(
Expand Down
71 changes: 50 additions & 21 deletions src/editor-sidebar/save-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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( {
Expand Down Expand Up @@ -61,16 +63,16 @@ export const SaveThemePanel = () => {

return (
<PanelBody>
<Heading>
<NavigatorToParentButton icon={ chevronLeft }>
{ __( 'Save Changes', 'create-block-theme' ) }
</NavigatorToParentButton>
</Heading>

<ScreenHeader
title={ __( 'Save Changes', 'create-block-theme' ) }
/>
<VStack>
<CheckboxControl
label="Save Fonts"
help="Save activated fonts in the Font Library to the theme. Remove deactivated theme fonts from the theme."
label={ __( 'Save Fonts', 'create-block-theme' ) }
help={ __(
'Save activated fonts in the Font Library to the theme. Remove deactivated theme fonts from the theme.',
'create-block-theme'
) }
checked={ saveOptions.saveFonts }
onChange={ () => {
setSaveOptions( {
Expand All @@ -80,8 +82,11 @@ export const SaveThemePanel = () => {
} }
/>
<CheckboxControl
label="Save Style Changes"
help="Save Global Styles values set in the Editor to the theme."
label={ __( 'Save Style Changes', 'create-block-theme' ) }
help={ __(
'Save Global Styles values set in the Editor to the theme.',
'create-block-theme'
) }
checked={ saveOptions.saveStyle }
onChange={ () => {
setSaveOptions( {
Expand All @@ -91,8 +96,14 @@ export const SaveThemePanel = () => {
} }
/>
<CheckboxControl
label="Save Template Changes"
help="Save Template and Template Part changes made in the Editor to the theme."
label={ __(
'Save Template Changes',
'create-block-theme'
) }
help={ __(
'Save Template and Template Part changes made in the Editor to the theme.',
'create-block-theme'
) }
checked={ saveOptions.saveTemplates }
onChange={ () => {
setSaveOptions( {
Expand All @@ -102,8 +113,14 @@ export const SaveThemePanel = () => {
} }
/>
<CheckboxControl
label="Process Only Modified Templates"
help="Process only templates you have modified in the Editor. Any templates you have not modified will be left as is."
label={ __(
'Process Only Modified Templates',
'create-block-theme'
) }
help={ __(
'Process only templates you have modified in the Editor. Any templates you have not modified will be left as is.',
'create-block-theme'
) }
disabled={ ! saveOptions.saveTemplates }
checked={
saveOptions.saveTemplates &&
Expand All @@ -118,8 +135,11 @@ export const SaveThemePanel = () => {
} }
/>
<CheckboxControl
label="Localize Text"
help="Any text in a template will be copied to a pattern and localized."
label={ __( 'Localize Text', 'create-block-theme' ) }
help={ __(
'Any text in a template will be copied to a pattern and localized.',
'create-block-theme'
) }
disabled={ ! saveOptions.saveTemplates }
checked={
saveOptions.saveTemplates && saveOptions.localizeText
Expand All @@ -132,8 +152,11 @@ export const SaveThemePanel = () => {
} }
/>
<CheckboxControl
label="Localize Images"
help="Any images in a template will be copied to a local /assets folder and referenced from there via a pattern."
label={ __( 'Localize Images', 'create-block-theme' ) }
help={ __(
'Any images in a template will be copied to a local /assets folder and referenced from there via a pattern.',
'create-block-theme'
) }
disabled={ ! saveOptions.saveTemplates }
checked={
saveOptions.saveTemplates && saveOptions.localizeImages
Expand All @@ -146,8 +169,14 @@ export const SaveThemePanel = () => {
} }
/>
<CheckboxControl
label="Remove Navigation Refs"
help="Remove Navigation Refs from the theme returning your navigation to the default state."
label={ __(
'Remove Navigation Refs',
'create-block-theme'
) }
help={ __(
'Remove Navigation Refs from the theme returning your navigation to the default state.',
'create-block-theme'
) }
disabled={ ! saveOptions.saveTemplates }
checked={
saveOptions.saveTemplates && saveOptions.removeNavRefs
Expand Down
42 changes: 42 additions & 0 deletions src/editor-sidebar/screen-header.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
import {
// eslint-disable-next-line
__experimentalHStack as HStack,
// eslint-disable-next-line
__experimentalVStack as VStack,
// eslint-disable-next-line
__experimentalSpacer as Spacer,
// eslint-disable-next-line
__experimentalHeading as Heading,
// eslint-disable-next-line
__experimentalNavigatorToParentButton as NavigatorToParentButton,
} from '@wordpress/components';
import { isRTL, __ } from '@wordpress/i18n';
import { chevronRight, chevronLeft } from '@wordpress/icons';

const ScreenHeader = ( { title, onBack } ) => {
return (
<Spacer marginBottom={ 0 } paddingBottom={ 4 }>
<HStack spacing={ 2 }>
<NavigatorToParentButton
style={ { minWidth: 24, padding: 0 } }
icon={ isRTL() ? chevronRight : chevronLeft }
size="small"
label={ __( 'Back', 'create-block-theme' ) }
onClick={ onBack }
/>
<Spacer>
<Heading
level={ 2 }
size={ 13 }
// Need to override the too specific bottom margin for complementary areas.
style={ { margin: 0 } }
>
{ title }
</Heading>
</Spacer>
</HStack>
</Spacer>
);
};

export default ScreenHeader;
Loading

0 comments on commit 7a70ba1

Please sign in to comment.