Skip to content

Commit

Permalink
Fix uploading background images in stylebook view.
Browse files Browse the repository at this point in the history
  • Loading branch information
tellthemachines committed Dec 20, 2024
1 parent dea955c commit 66c37f3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions packages/edit-site/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@
"@wordpress/icons": "*",
"@wordpress/keyboard-shortcuts": "*",
"@wordpress/keycodes": "*",
"@wordpress/media-utils": "5.14.0",
"@wordpress/notices": "*",
"@wordpress/patterns": "*",
"@wordpress/plugins": "*",
Expand Down
18 changes: 16 additions & 2 deletions packages/edit-site/src/components/style-book/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ import {
useEffect,
} from '@wordpress/element';
import { ENTER, SPACE } from '@wordpress/keycodes';
import { uploadMedia } from '@wordpress/media-utils';
import { store as coreStore } from '@wordpress/core-data';

/**
* Internal dependencies
Expand Down Expand Up @@ -361,10 +363,22 @@ export const StyleBookPreview = ( { userConfig = {}, isStatic = false } ) => {
[]
);

const canUserUploadMedia = useSelect(
( select ) =>
select( coreStore ).canUser( 'create', {
kind: 'root',
name: 'media',
} ),
[]
);

// Update block editor settings because useMultipleOriginColorsAndGradients fetch colours from there.
useEffect( () => {
dispatch( blockEditorStore ).updateSettings( siteEditorSettings );
}, [ siteEditorSettings ] );
dispatch( blockEditorStore ).updateSettings( {
...siteEditorSettings,
mediaUpload: canUserUploadMedia ? uploadMedia : undefined,
} );
}, [ siteEditorSettings, canUserUploadMedia ] );

const [ section, onChangeSection ] = useSection();

Expand Down

0 comments on commit 66c37f3

Please sign in to comment.