diff --git a/blocks/library/block/index.js b/blocks/library/block/index.js index 5f2bf19366cda..c2a360d49fdc9 100644 --- a/blocks/library/block/index.js +++ b/blocks/library/block/index.js @@ -171,10 +171,6 @@ const EnhancedReusableBlockEdit = compose( [ export const name = 'core/block'; export const settings = { - title: __( 'Shared Block' ), - - isPrivate: true, - edit: EnhancedReusableBlockEdit, save: () => null, diff --git a/blocks/library/block/index.php b/blocks/library/block/index.php index d9e079d24d2bf..e1c47bd6c7a7f 100644 --- a/blocks/library/block/index.php +++ b/blocks/library/block/index.php @@ -33,10 +33,12 @@ function gutenberg_render_block_core_reusable_block( $attributes ) { } register_block_type( 'core/block', array( + 'title' => __( 'Shared Block', 'gutenberg' ), 'category' => 'shared', 'supports' => array( 'customClassName' => false, 'html' => false, + 'insertable' => false, ), 'attributes' => array( 'ref' => array( diff --git a/blocks/library/categories/index.js b/blocks/library/categories/index.js index 83f9dad2ef769..e75bd0ebd1639 100644 --- a/blocks/library/categories/index.js +++ b/blocks/library/categories/index.js @@ -1,8 +1,3 @@ -/** - * WordPress dependencies - */ -import { __ } from '@wordpress/i18n'; - /** * Internal dependencies */ @@ -13,12 +8,6 @@ import CategoriesBlock from './block'; export const name = 'core/categories'; export const settings = { - title: __( 'Categories' ), - - description: __( 'Shows a list of your site\'s categories.' ), - - icon: 'list-view', - getEditWrapperProps( attributes ) { const { align } = attributes; if ( 'left' === align || 'right' === align || 'full' === align ) { diff --git a/blocks/library/categories/index.php b/blocks/library/categories/index.php index 4b16003135c9f..2d4d814fd0c4f 100644 --- a/blocks/library/categories/index.php +++ b/blocks/library/categories/index.php @@ -89,6 +89,9 @@ function onCatChange() { */ function register_block_core_categories() { register_block_type( 'core/categories', array( + 'title' => __( 'Categories', 'gutenberg' ), + 'description' => __( 'Shows a list of your site\'s categories.', 'gutenberg' ), + 'icon' => 'list-view', 'category' => 'widgets', 'supports' => array( 'html' => false, diff --git a/blocks/library/latest-posts/index.js b/blocks/library/latest-posts/index.js index b78c6581247cb..c207a485183c4 100644 --- a/blocks/library/latest-posts/index.js +++ b/blocks/library/latest-posts/index.js @@ -1,8 +1,3 @@ -/** - * WordPress dependencies - */ -import { __ } from '@wordpress/i18n'; - /** * Internal dependencies */ @@ -13,14 +8,6 @@ import LatestPostsBlock from './block'; export const name = 'core/latest-posts'; export const settings = { - title: __( 'Latest Posts' ), - - description: __( 'Shows a list of your site\'s most recent posts.' ), - - icon: 'list-view', - - keywords: [ __( 'recent posts' ) ], - getEditWrapperProps( attributes ) { const { align } = attributes; if ( 'left' === align || 'right' === align || 'wide' === align || 'full' === align ) { diff --git a/blocks/library/latest-posts/index.php b/blocks/library/latest-posts/index.php index cd103e632783d..8d8942ccd8c73 100644 --- a/blocks/library/latest-posts/index.php +++ b/blocks/library/latest-posts/index.php @@ -70,6 +70,12 @@ function render_block_core_latest_posts( $attributes ) { */ function register_block_core_latest_posts() { register_block_type( 'core/latest-posts', array( + 'title' => __( 'Latest Posts', 'gutenberg' ), + 'description' => __( 'Shows a list of your site\'s most recent posts.', 'gutenberg' ), + 'icon' => 'list-view', + 'keywords' => array( + __( 'recent posts', 'gutenberg' ), + ), 'category' => 'widgets', 'supports' => array( 'html' => false, diff --git a/blocks/test/server-registered.json b/blocks/test/server-registered.json index f2a3ceb20849d..5855ce9848e1c 100644 --- a/blocks/test/server-registered.json +++ b/blocks/test/server-registered.json @@ -1 +1 @@ -{"core\/block":{"category":"shared","supports":{"customClassName":false,"html":false},"attributes":{"ref":{"type":"number"}}},"core\/categories":{"category":"widgets","supports":{"html":false},"attributes":{"showPostCounts":{"type":"boolean","default":false},"displayAsDropdown":{"type":"boolean","default":false},"showHierarchy":{"type":"boolean","default":false},"align":{"type":"string"}}},"core\/latest-posts":{"category":"widgets","supports":{"html":false},"attributes":{"categories":{"type":"string"},"postsToShow":{"type":"number","default":5},"displayPostDate":{"type":"boolean","default":false},"postLayout":{"type":"string","default":"list"},"columns":{"type":"number","default":3},"align":{"type":"string","default":"center"},"order":{"type":"string","default":"desc"},"orderBy":{"type":"string","default":"date"}}}} \ No newline at end of file +{"core\/block":{"title":"Shared Block","category":"shared","supports":{"customClassName":false,"html":false,"insertable":false},"attributes":{"ref":{"type":"number"}}},"core\/categories":{"title":"Categories","description":"Shows a list of your site's categories.","category":"widgets","icon":"list-view","supports":{"html":false},"attributes":{"showPostCounts":{"type":"boolean","default":false},"displayAsDropdown":{"type":"boolean","default":false},"showHierarchy":{"type":"boolean","default":false},"align":{"type":"string"}}},"core\/latest-posts":{"title":"Latest Posts","description":"Shows a list of your site's most recent posts.","category":"widgets","icon":"list-view","keywords":["recent posts"],"supports":{"html":false},"attributes":{"categories":{"type":"string"},"postsToShow":{"type":"number","default":5},"displayPostDate":{"type":"boolean","default":false},"postLayout":{"type":"string","default":"list"},"columns":{"type":"number","default":3},"align":{"type":"string","default":"center"},"order":{"type":"string","default":"desc"},"orderBy":{"type":"string","default":"date"}}}} \ No newline at end of file diff --git a/docs/block-api.md b/docs/block-api.md index 27061c0a5c75e..3ceb4545e72bc 100644 --- a/docs/block-api.md +++ b/docs/block-api.md @@ -298,6 +298,13 @@ className: false, html: false, ``` +- `insertable` (default `true`): By default, Gutenberg will show all blocks in the inserter. To disable this behavior, set `insertable` to `false`. + +```js +// Hide from the inserter. +insertable: 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](https://wordpress.org/gutenberg/handbook/block-edit-save/). diff --git a/editor/store/selectors.js b/editor/store/selectors.js index 6e2ccbf6a3473..10d26b99d691c 100644 --- a/editor/store/selectors.js +++ b/editor/store/selectors.js @@ -19,7 +19,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'; @@ -1183,7 +1183,7 @@ function buildInserterItemFromBlockType( state, enabledBlockTypes, blockType ) { return null; } - if ( blockType.isPrivate ) { + if ( ! hasBlockSupport( blockType, 'insertable', true ) ) { return null; } diff --git a/editor/store/test/selectors.js b/editor/store/test/selectors.js index ccc3fc33cfc47..baf305553982f 100644 --- a/editor/store/test/selectors.js +++ b/editor/store/test/selectors.js @@ -7,7 +7,13 @@ import { filter, property, union } from 'lodash'; * WordPress dependencies */ import { __ } from '@wordpress/i18n'; -import { registerBlockType, unregisterBlockType, registerCoreBlocks, getBlockTypes } from '@wordpress/blocks'; +import { + getBlockTypes, + hasBlockSupport, + registerBlockType, + registerCoreBlocks, + unregisterBlockType, +} from '@wordpress/blocks'; import { moment } from '@wordpress/date'; /** @@ -2433,7 +2439,7 @@ describe( 'selectors', () => { }, }; - const blockTypes = getBlockTypes().filter( blockType => ! blockType.isPrivate ); + const blockTypes = getBlockTypes().filter( blockType => hasBlockSupport( blockType, 'insertable', true ) ); expect( getInserterItems( state ) ).toHaveLength( blockTypes.length ); } ); diff --git a/lib/class-wp-block-type.php b/lib/class-wp-block-type.php index 0d948419ce370..61ee0856ca344 100644 --- a/lib/class-wp-block-type.php +++ b/lib/class-wp-block-type.php @@ -22,14 +22,46 @@ class WP_Block_Type { */ public $name; + /** + * Block type title. + * + * @since 2.6.0 + * @var string + */ + public $title; + + /** + * Block type description. + * + * @since 2.6.0 + * @var string + */ + public $description; + /** * Block type category. * - * @since 2.5.0 + * @since 2.6.0 * @var string */ public $category; + /** + * Block type icon. + * + * @since 2.6.0 + * @var string + */ + public $icon; + + /** + * Block type keywords. + * + * @since 2.6.0 + * @var array + */ + public $keywords; + /** * Block type render callback. * @@ -41,7 +73,7 @@ class WP_Block_Type { /** * Block type supports property schemas. * - * @since 2.5.0 + * @since 2.6.0 * @var array */ public $supports; @@ -189,7 +221,7 @@ public function set_props( $args ) { /** * Filters settings for the block just before it gets registered. * - * @since 2.5.0 + * @since 2.6.0 */ public function filter_settings() { if ( ! has_filter( 'register_block_type' ) ) { @@ -197,7 +229,11 @@ public function filter_settings() { } $this->set_props( apply_filters( 'register_block_type', array( + 'name' => $this->name, + 'description' => $this->description, 'category' => $this->category, + 'icon' => $this->icon, + 'keywords' => $this->keywords, 'supports' => $this->supports, 'attributes' => $this->attributes, 'render_callback' => $this->render_callback, diff --git a/lib/client-assets.php b/lib/client-assets.php index ebd72a4397fa5..b81e69d6977ff 100644 --- a/lib/client-assets.php +++ b/lib/client-assets.php @@ -660,7 +660,7 @@ function gutenberg_get_post_to_edit( $post_id ) { function gutenberg_prepare_blocks_for_js() { $block_registry = WP_Block_Type_Registry::get_instance(); $blocks = array(); - $keys_to_pick = array( 'title', 'icon', 'category', 'keywords', 'supports', 'attributes' ); + $keys_to_pick = array( 'title', 'description', 'category', 'icon', 'keywords', 'supports', 'attributes' ); foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) { foreach ( $keys_to_pick as $key ) {