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

Backports for 5.6 Beta 2 #26442

Merged
merged 13 commits into from Oct 27, 2020
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file
Failed to load files.

Always

Just for now

@@ -4,6 +4,10 @@ on:
pull_request:
paths-ignore:
- '**.md'
push:
branches: [master]
paths-ignore:
- '**.md'

jobs:
test:
@@ -1,8 +1,13 @@
name: React Native E2E Tests (iOS)

on:
pull_request:
paths-ignore:
- '**.md'
push:
branches: [master]
paths-ignore:
- '**.md'

jobs:
test:
@@ -1,6 +1,8 @@
{
"core": "WordPress/WordPress",
"plugins": [ "." ],
"plugins": [
"."
],
"env": {
"tests": {
"mappings": {
@@ -11,7 +11,7 @@
"issues": "https://github.com/WordPress/gutenberg/issues"
},
"require-dev": {
"dealerdirect/phpcodesniffer-composer-installer": "^0.6",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
"squizlabs/php_codesniffer": "^3.5",
"phpcompatibility/php-compatibility": "^9.3",
"wp-coding-standards/wpcs": "^2.2",
@@ -23,6 +23,6 @@
},
"scripts": {
"format": "phpcbf --standard=phpcs.xml.dist --report-summary --report-source",
"lint": "phpcs --standard=phpcs.xml.dist"
"lint": "phpcs --standard=phpcs.xml.dist --runtime-set ignore_warnings_on_exit 1"
}
}

Some generated files are not rendered by default. Learn more.

@@ -19,6 +19,13 @@ class WP_Block_Supports {
*/
private $block_supports = array();

/**
* Tracks the current block to be rendered.
*
* @var array
*/
public static $block_to_render = null;

/**
* Container for the main instance of the class.
*
@@ -67,13 +74,12 @@ public function register( $block_support_name, $block_support_config ) {
* Generates an array of HTML attributes, such as classes, by applying to
* the given block all of the features that the block supports.
*
* @param array $parsed_block Block as parsed from content.
* @return array Array of HTML attributes.
*/
public function apply_block_supports( $parsed_block ) {
$block_attributes = $parsed_block['attrs'];
public function apply_block_supports() {
$block_attributes = self::$block_to_render['attrs'];
$block_type = WP_Block_Type_Registry::get_instance()->get_registered(
$parsed_block['blockName']
self::$block_to_render['blockName']
);

// If no render_callback, assume styles have been previously handled.
@@ -144,8 +150,7 @@ private function register_attributes() {
* @return string String of HTML classes.
*/
function get_block_wrapper_attributes( $extra_attributes = array() ) {
global $current_parsed_block;
$new_attributes = WP_Block_Supports::get_instance()->apply_block_supports( $current_parsed_block );
$new_attributes = WP_Block_Supports::get_instance()->apply_block_supports();

if ( empty( $new_attributes ) && empty( $extra_attributes ) ) {
return '';
@@ -191,4 +196,29 @@ function get_block_wrapper_attributes( $extra_attributes = array() ) {
return implode( ' ', $normalized_attributes );
}

/**
* Callback hooked to the register_block_type_args filter.
*
* This hooks into block registration to wrap the render_callback
* of dynamic blocks with a closure that keeps track of the
* current block to be rendered.
*
* @param array $args Block attributes.
* @return array Block attributes.
*/
function wp_block_supports_track_block_to_render( $args ) {
if ( null !== $args['render_callback'] ) {
$block_render_callback = $args['render_callback'];
$args['render_callback'] = function( $attributes, $content, $block ) use ( $block_render_callback ) {
$parent_block = WP_Block_Supports::$block_to_render;
WP_Block_Supports::$block_to_render = $block->parsed_block;
$result = $block_render_callback( $attributes, $content, $block );
WP_Block_Supports::$block_to_render = $parent_block;
return $result;
};
}
return $args;
}

add_action( 'init', array( 'WP_Block_Supports', 'init' ), 22 );
add_filter( 'register_block_type_args', 'wp_block_supports_track_block_to_render' );
@@ -203,7 +203,6 @@ public function __get( $name ) {
*/
public function render( $options = array() ) {
global $post;
global $current_parsed_block;
$options = array_replace(
array(
'dynamic' => true,
@@ -217,14 +216,9 @@ public function render( $options = array() ) {
if ( ! $options['dynamic'] || empty( $this->block_type->skip_inner_blocks ) ) {
$index = 0;
foreach ( $this->inner_content as $chunk ) {
if ( is_string( $chunk ) ) {
$block_content .= $chunk;
} else {
$parent_parsed_block = $current_parsed_block;
$current_parsed_block = $this->inner_blocks[ $index ]->parsed_block;
$block_content .= $this->inner_blocks[ $index++ ]->render();
$current_parsed_block = $parent_parsed_block;
}
$block_content .= is_string( $chunk ) ?
$chunk :
$this->inner_blocks[ $index++ ]->render();
}
}

ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.