Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Block editor]: Add setting to disable Openverse integration #47404

Merged
merged 2 commits into from
Jan 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions packages/block-editor/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -659,6 +659,7 @@ _Properties_
- _canLockBlocks_ `boolean`: Whether the user can manage Block Lock state
- _codeEditingEnabled_ `boolean`: Whether or not the user can switch to the code editor
- _generateAnchors_ `boolean`: Enable/Disable auto anchor generation for Heading blocks
- _enableOpenverseMediaCategory_ `boolean`: Enable/Disable the Openverse media category in the inserter.
- _\_\_experimentalCanUserUseUnfilteredHTML_ `boolean`: Whether the user should be able to use unfiltered HTML or the HTML should be filtered e.g., to remove elements considered insecure like iframes.
- _\_\_experimentalClearBlockSelection_ `boolean`: Whether the block editor should clear selection on mousedown when a block is not clicked.
- _\_\_experimentalBlockDirectory_ `boolean`: Whether the user has enabled the Block Directory
Expand Down
39 changes: 24 additions & 15 deletions packages/block-editor/src/components/inserter/media-tab/hooks.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,20 +71,18 @@ export function useMediaResults( category, query = {} ) {
}

function useInserterMediaCategories() {
const { inserterMediaCategories, allowedMimeTypes } = useSelect(
( select ) => {
const { getSettings } = select( blockEditorStore );
const {
__unstableInserterMediaCategories,
allowedMimeTypes: _allowedMimeTypes,
} = getSettings();
return {
inserterMediaCategories: __unstableInserterMediaCategories,
allowedMimeTypes: _allowedMimeTypes,
};
},
[]
);
const {
inserterMediaCategories,
allowedMimeTypes,
enableOpenverseMediaCategory,
} = useSelect( ( select ) => {
const settings = select( blockEditorStore ).getSettings();
return {
inserterMediaCategories: settings.__unstableInserterMediaCategories,
allowedMimeTypes: settings.allowedMimeTypes,
enableOpenverseMediaCategory: settings.enableOpenverseMediaCategory,
};
}, [] );
// The allowed `mime_types` can be altered by `upload_mimes` filter and restrict
// some of them. In this case we shouldn't add the category to the available media
// categories list in the inserter.
Expand All @@ -93,6 +91,13 @@ function useInserterMediaCategories() {
return;
}
return inserterMediaCategories.filter( ( category ) => {
// Check if Openverse category is enabled.
if (
! enableOpenverseMediaCategory &&
category.name === 'openverse'
) {
return false;
}
// When a category has set `isExternalResource` to `true`, we
// don't need to check for allowed mime types, as they are used
// for restricting uploads for this media type and not for
Expand All @@ -104,7 +109,11 @@ function useInserterMediaCategories() {
mimeType.startsWith( `${ category.mediaType }/` )
);
} );
}, [ inserterMediaCategories, allowedMimeTypes ] );
}, [
inserterMediaCategories,
allowedMimeTypes,
enableOpenverseMediaCategory,
] );
return allowedCategories;
}

Expand Down
4 changes: 4 additions & 0 deletions packages/block-editor/src/store/defaults.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export const PREFERENCES_DEFAULTS = {
* @property {boolean} canLockBlocks Whether the user can manage Block Lock state
* @property {boolean} codeEditingEnabled Whether or not the user can switch to the code editor
* @property {boolean} generateAnchors Enable/Disable auto anchor generation for Heading blocks
* @property {boolean} enableOpenverseMediaCategory Enable/Disable the Openverse media category in the inserter.
* @property {boolean} __experimentalCanUserUseUnfilteredHTML Whether the user should be able to use unfiltered HTML or the HTML should be filtered e.g., to remove elements considered insecure like iframes.
* @property {boolean} __experimentalClearBlockSelection Whether the block editor should clear selection on mousedown when a block is not clicked.
* @property {boolean} __experimentalBlockDirectory Whether the user has enabled the Block Directory
Expand Down Expand Up @@ -156,6 +157,9 @@ export const SETTINGS_DEFAULTS = {
// Allows to disable block locking interface.
canLockBlocks: true,

// Allows to disable Openverse media category in the inserter.
enableOpenverseMediaCategory: true,

__experimentalCanUserUseUnfilteredHTML: false,
__experimentalClearBlockSelection: true,
__experimentalBlockDirectory: false,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ function useBlockEditorSettings( settings, hasTemplate ) {
'keepCaretInsideBlock',
'maxWidth',
'onUpdateDefaultBlockStyles',
'enableOpenverseMediaCategory',
'styles',
'template',
'templateLock',
Expand Down