diff --git a/lib/compat.php b/lib/compat.php index 0f4ea78a7618ee..e38f339030cb5b 100644 --- a/lib/compat.php +++ b/lib/compat.php @@ -175,37 +175,3 @@ function gutenberg_get_post_from_context() { } return get_post(); } - -/** - * Shim that hooks into `pre_render_block` so as to override `render_block` with - * a function that assigns block context. - * - * This can be removed when plugin support requires WordPress 5.5.0+. - * - * @see (TBD Trac Link) - * - * @param string|null $pre_render The pre-rendered content. Defaults to null. - * @param array $parsed_block The parsed block being rendered. - * - * @return string String of rendered HTML. - */ -function gutenberg_render_block_with_assigned_block_context( $pre_render, $parsed_block ) { - global $post; - - // If a non-null value is provided, a filter has run at an earlier priority - // and has already handled custom rendering and should take precedence. - if ( null !== $pre_render ) { - return $pre_render; - } - - $source_block = $parsed_block; - - /** This filter is documented in src/wp-includes/blocks.php */ - $parsed_block = apply_filters( 'render_block_data', $parsed_block, $source_block ); - $context = array( 'postId' => $post->ID ); - $block = new WP_Block( $parsed_block, $context ); - - /** This filter is documented in src/wp-includes/blocks.php */ - return apply_filters( 'render_block', $block->render(), $parsed_block ); -} -add_filter( 'pre_render_block', 'gutenberg_render_block_with_assigned_block_context', 9, 2 ); diff --git a/packages/block-library/src/post-title/index.php b/packages/block-library/src/post-title/index.php index 700d8ea968546f..d6218034553f32 100644 --- a/packages/block-library/src/post-title/index.php +++ b/packages/block-library/src/post-title/index.php @@ -11,12 +11,12 @@ * @return string Returns the filtered post title for the current post wrapped inside "h1" tags. */ function render_block_core_post_title() { - global $_experimental_block; - if ( ! isset( $_experimental_block->context['postId'] ) ) { + $post = gutenberg_get_post_from_context(); + if ( ! $post ) { return ''; } - return '

' . get_the_title( $_experimental_block->context['postId'] ) . '

'; + return '

' . get_the_title( $post ) . '

'; } /** diff --git a/packages/e2e-tests/plugins/block-context.php b/packages/e2e-tests/plugins/block-context.php index 9b1b4c27cdc3c2..380660f6f08ef9 100644 --- a/packages/e2e-tests/plugins/block-context.php +++ b/packages/e2e-tests/plugins/block-context.php @@ -47,18 +47,7 @@ function gutenberg_test_register_context_blocks() { register_block_type( 'gutenberg/test-context-consumer', array( - 'context' => array( 'gutenberg/recordId' ), - 'render_callback' => function() { - global $_experimental_block; - - $record_id = $_experimental_block->context['gutenberg/recordId']; - - if ( ! is_int( $record_id ) ) { - throw new Exception( 'Expected numeric recordId' ); - } - - return 'The record ID is: ' . filter_var( $record_id, FILTER_VALIDATE_INT ); - }, + 'context' => array( 'gutenberg/recordId' ), ) ); } diff --git a/packages/e2e-tests/specs/editor/plugins/block-context.test.js b/packages/e2e-tests/specs/editor/plugins/block-context.test.js index d7536b20f7166a..9f933f8150cf6e 100644 --- a/packages/e2e-tests/specs/editor/plugins/block-context.test.js +++ b/packages/e2e-tests/specs/editor/plugins/block-context.test.js @@ -70,7 +70,12 @@ describe( 'Block context', () => { expect( innerBlockText ).toBe( 'The record ID is: 123' ); } ); - test( 'Block context is reflected in the preview', async () => { + // Disable reason: Block context PHP implementation is temporarily reverted. + // This will be unskipped once the implementation is restored. Skipping was + // the most direct option for revert given time constraints. + + /* eslint-disable-next-line jest/no-disabled-tests */ + test.skip( 'Block context is reflected in the preview', async () => { await insertBlock( 'Test Context Provider' ); const editorPage = page; const previewPage = await openPreviewPage( editorPage ); diff --git a/phpunit/class-block-context-test.php b/phpunit/class-block-context-test.php index 52a4048a64bfa5..769b0e02429168 100644 --- a/phpunit/class-block-context-test.php +++ b/phpunit/class-block-context-test.php @@ -67,6 +67,8 @@ protected function register_block_type( $name, $args ) { * its inner blocks. */ function test_provides_block_context() { + $this->markTestSkipped(); + $provided_context = array(); $this->register_block_type(