Skip to content

Commit 699c855

Browse files
committed
Blocks: Add context fields to WP_Block_Type
New block context related fields were added as part of WordPress/gutenberg#22686. This changest backports them to WP_Block_Type class. Props aduth, spacedmonkey, mcsf, epiqueras. Fixes #47656. git-svn-id: https://develop.svn.wordpress.org/trunk@48117 602fd350-edb4-49c9-b593-d223f7449a82
1 parent 8e0e6bc commit 699c855

File tree

3 files changed

+37
-7
lines changed

3 files changed

+37
-7
lines changed

src/wp-admin/includes/post.php

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2234,19 +2234,33 @@ function get_block_categories( $post ) {
22342234
function get_block_editor_server_block_settings() {
22352235
$block_registry = WP_Block_Type_Registry::get_instance();
22362236
$blocks = array();
2237-
$keys_to_pick = array( 'title', 'description', 'icon', 'category', 'keywords', 'parent', 'supports', 'attributes', 'styles', 'textdomain', 'example' );
2237+
$fields_to_pick = array(
2238+
'title' => 'title',
2239+
'description' => 'description',
2240+
'icon' => 'icon',
2241+
'category' => 'category',
2242+
'keywords' => 'keywords',
2243+
'parent' => 'parent',
2244+
'supports' => 'supports',
2245+
'attributes' => 'attributes',
2246+
'provides_context' => 'providesContext',
2247+
'uses_context' => 'usesContext',
2248+
'styles' => 'styles',
2249+
'textdomain' => 'textdomain',
2250+
'example' => 'example',
2251+
);
22382252

22392253
foreach ( $block_registry->get_all_registered() as $block_name => $block_type ) {
2240-
foreach ( $keys_to_pick as $key ) {
2241-
if ( ! isset( $block_type->{ $key } ) ) {
2254+
foreach ( $fields_to_pick as $field => $key ) {
2255+
if ( ! isset( $block_type->{ $field } ) ) {
22422256
continue;
22432257
}
22442258

22452259
if ( ! isset( $blocks[ $block_name ] ) ) {
22462260
$blocks[ $block_name ] = array();
22472261
}
22482262

2249-
$blocks[ $block_name ][ $key ] = $block_type->{ $key };
2263+
$blocks[ $block_name ][ $key ] = $block_type->{ $field };
22502264
}
22512265
}
22522266

src/wp-includes/class-wp-block-type.php

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,9 @@ class WP_Block_Type {
7474

7575
/**
7676
* @since 5.5.0
77-
* @var array
77+
* @var array|null
7878
*/
79-
public $supports = array();
79+
public $supports = null;
8080

8181
/**
8282
* @since 5.5.0
@@ -100,6 +100,22 @@ class WP_Block_Type {
100100
*/
101101
public $attributes = null;
102102

103+
/**
104+
* Context values inherited by blocks of this type.
105+
*
106+
* @since 5.5.0
107+
* @var array
108+
*/
109+
public $uses_context = array();
110+
111+
/**
112+
* Context provided by blocks of this type.
113+
*
114+
* @since 5.5.0
115+
* @var array|null
116+
*/
117+
public $provides_context = null;
118+
103119
/**
104120
* Block type editor script handle.
105121
*

tests/phpunit/tests/admin/includesPost.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -844,7 +844,7 @@ function test_get_block_editor_server_block_settings() {
844844
'category' => 'common',
845845
'icon' => 'text',
846846
'keywords' => array(),
847-
'supports' => array(),
847+
'usesContext' => array(),
848848
'styles' => array(),
849849
),
850850
$blocks[ $name ]

0 commit comments

Comments
 (0)