Blocks: Add context fields to WP_Block_Type

New block context related fields were added as part of https://github.com/WordPress/gutenberg/pull/22686. This changest backports them to WP_Block_Type class.

Props aduth, spacedmonkey, mcsf, epiqueras.
Fixes #47656.  


Built from https://develop.svn.wordpress.org/trunk@48117


git-svn-id: http://core.svn.wordpress.org/trunk@47886 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
gziolo 2020-06-22 10:26:14 +00:00
parent aa98d37cad
commit 29ffb31cb3
3 changed files with 37 additions and 7 deletions

View File

@ -2234,11 +2234,25 @@ function get_block_categories( $post ) {
function get_block_editor_server_block_settings() { function get_block_editor_server_block_settings() {
$block_registry = WP_Block_Type_Registry::get_instance(); $block_registry = WP_Block_Type_Registry::get_instance();
$blocks = array(); $blocks = array();
$keys_to_pick = array( 'title', 'description', 'icon', 'category', 'keywords', 'parent', 'supports', 'attributes', 'styles', 'textdomain', 'example' ); $fields_to_pick = array(
'title' => 'title',
'description' => 'description',
'icon' => 'icon',
'category' => 'category',
'keywords' => 'keywords',
'parent' => 'parent',
'supports' => 'supports',
'attributes' => 'attributes',
'provides_context' => 'providesContext',
'uses_context' => 'usesContext',
'styles' => 'styles',
'textdomain' => 'textdomain',
'example' => 'example',
);
foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) { foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) {
foreach ( $keys_to_pick as $key ) { foreach ( $fields_to_pick as $field => $key ) {
if ( ! isset( $block_type->{ $key } ) ) { if ( ! isset( $block_type->{ $field } ) ) {
continue; continue;
} }
@ -2246,7 +2260,7 @@ function get_block_editor_server_block_settings() {
$blocks[ $block_name ] = array(); $blocks[ $block_name ] = array();
} }
$blocks[ $block_name ][ $key ] = $block_type->{ $key }; $blocks[ $block_name ][ $key ] = $block_type->{ $field };
} }
} }

View File

@ -74,9 +74,9 @@ class WP_Block_Type {
/** /**
* @since 5.5.0 * @since 5.5.0
* @var array * @var array|null
*/ */
public $supports = array(); public $supports = null;
/** /**
* @since 5.5.0 * @since 5.5.0
@ -100,6 +100,22 @@ class WP_Block_Type {
*/ */
public $attributes = null; public $attributes = null;
/**
* Context values inherited by blocks of this type.
*
* @since 5.5.0
* @var array
*/
public $uses_context = array();
/**
* Context provided by blocks of this type.
*
* @since 5.5.0
* @var array|null
*/
public $provides_context = null;
/** /**
* Block type editor script handle. * Block type editor script handle.
* *

View File

@ -13,7 +13,7 @@
* *
* @global string $wp_version * @global string $wp_version
*/ */
$wp_version = '5.5-alpha-48116'; $wp_version = '5.5-alpha-48117';
/** /**
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema. * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.