Skip to content
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
11 changes: 10 additions & 1 deletion blocks/api/registration.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,14 @@
/**
* External dependencies
*/
import { get, isFunction, some } from 'lodash';
import { get, set, isFunction, some } from 'lodash';

/**
* WordPress dependencies
*/
import { applyFilters } from '@wordpress/hooks';
import { select, dispatch } from '@wordpress/data';
import { deprecated } from '@wordpress/utils';

/**
* Defined behavior of a block type.
Expand Down Expand Up @@ -136,6 +137,14 @@ export function registerBlockType( name, settings ) {
if ( ! settings.icon ) {
settings.icon = 'block-default';
}
if ( 'isPrivate' in settings ) {
deprecated( 'isPrivate', {
version: '3.1',
alternative: 'supports.inserter',
plugin: 'Gutenberg',
} );
set( settings, [ 'supports', 'inserter' ], ! settings.isPrivate );
}

dispatch( 'core/blocks' ).addBlockTypes( settings );

Expand Down
2 changes: 1 addition & 1 deletion core-blocks/block/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ export const name = 'core/block';
export const settings = {
title: __( 'Shared Block' ),
category: 'shared',
isPrivate: true,

attributes: {
ref: {
Expand All @@ -24,6 +23,7 @@ export const settings = {
supports: {
customClassName: false,
html: false,
inserter: false,
},

edit,
Expand Down
7 changes: 7 additions & 0 deletions docs/block-api.md
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,13 @@ className: false,
html: false,
```

- `inserter` (default `true`): By default, all blocks will appear in the Gutenberg inserter. To hide a block so that it can only be inserted programatically, set `inserter` to `false`.

```js
// Hide this block from the inserter.
inserter: false,
```

## Edit and Save

The `edit` and `save` functions define the editor interface with which a user would interact, and the markup to be serialized back when a post is saved. They are the heart of how a block operates, so they are [covered separately](../docs/block-api/block-edit-save.md).
3 changes: 2 additions & 1 deletion docs/reference/deprecated.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ Gutenberg's deprecation policy is intended to support backwards-compatibility fo
- All components in `wp.blocks.*` are removed. Please use `wp.editor.*` instead.
- `wp.blocks.withEditorSettings` is removed. Please use the data module to access the editor settings `wp.data.select( "core/editor" ).getEditorSettings()`.
- All DOM utils in `wp.utils.*` are removed. Please use `wp.dom.*` instead.

- `isPrivate: true` has been removed from the Block API. Please use `supports.inserter: false` instead.

## 3.0.0

- `wp.blocks.registerCoreBlocks` function removed. Please use `wp.coreBlocks.registerCoreBlocks` instead.
Expand Down
4 changes: 2 additions & 2 deletions editor/store/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ import createSelector from 'rememo';
/**
* WordPress dependencies
*/
import { serialize, getBlockType, getBlockTypes } from '@wordpress/blocks';
import { serialize, getBlockType, getBlockTypes, hasBlockSupport } from '@wordpress/blocks';
import { __ } from '@wordpress/i18n';
import { addQueryArgs } from '@wordpress/url';
import { moment } from '@wordpress/date';
Expand Down Expand Up @@ -1235,7 +1235,7 @@ function buildInserterItemFromBlockType( state, allowedBlockTypes, blockType ) {
return null;
}

if ( blockType.isPrivate ) {
if ( ! hasBlockSupport( blockType, 'inserter', true ) ) {
return null;
}

Expand Down
11 changes: 9 additions & 2 deletions editor/store/test/selectors.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ import { filter, property, union } from 'lodash';
* WordPress dependencies
*/
import { __ } from '@wordpress/i18n';
import { registerBlockType, unregisterBlockType, getBlockTypes } from '@wordpress/blocks';
import {
getBlockTypes,
hasBlockSupport,
registerBlockType,
unregisterBlockType,
} from '@wordpress/blocks';
import { moment } from '@wordpress/date';
import { registerCoreBlocks } from '@wordpress/core-blocks';

Expand Down Expand Up @@ -2627,7 +2632,9 @@ describe( 'selectors', () => {
},
};

const blockTypes = getBlockTypes().filter( ( blockType ) => ! blockType.isPrivate );
const blockTypes = getBlockTypes().filter( ( blockType ) =>
hasBlockSupport( blockType, 'inserter', true )
);
expect( getInserterItems( state, true ) ).toHaveLength( blockTypes.length );
} );

Expand Down