From 59c0270bba65aa6cff6e0c4e26c851f3e79d051a Mon Sep 17 00:00:00 2001 From: Luis Herranz Date: Wed, 1 Nov 2023 11:33:04 +0100 Subject: [PATCH] Prevent usage of post content block --- packages/block-library/src/query/index.php | 2 +- phpunit/blocks/render-query-test.php | 37 +++++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/packages/block-library/src/query/index.php b/packages/block-library/src/query/index.php index 52e9a7ef68654..86e582fcc55b8 100644 --- a/packages/block-library/src/query/index.php +++ b/packages/block-library/src/query/index.php @@ -195,7 +195,7 @@ function block_core_query_disable_enhanced_pagination( $parsed_block ) { } elseif ( ! empty( $enhanced_query_stack ) && isset( $block_name ) && - 'core/' !== substr( $block_name, 0, 5 ) + ( ! str_starts_with( $block_name, 'core/' ) || 'core/post-content' === $block_name ) ) { foreach ( $enhanced_query_stack as $query_id ) { $dirty_enhanced_queries[ $query_id ] = true; diff --git a/phpunit/blocks/render-query-test.php b/phpunit/blocks/render-query-test.php index 5e6324b08ef79..d98d697ebc976 100644 --- a/phpunit/blocks/render-query-test.php +++ b/phpunit/blocks/render-query-test.php @@ -136,7 +136,7 @@ public function test_rendering_query_with_enhanced_pagination() { * Tests that the `core/query` block adds an extra attribute to disable the * enhanced pagination in the browser when a plugin block is found inside. */ - public function test_rendering_query_with_enhanced_pagination_auto_disabled() { + public function test_rendering_query_with_enhanced_pagination_auto_disabled_when_plugins_blocks_are_found() { global $wp_query, $wp_the_query; $content = <<assertSame( 'true', $p->get_attribute( 'data-wp-navigation-disabled' ) ); } + /** + * Tests that the `core/query` block adds an extra attribute to disable the + * enhanced pagination in the browser when a post content block is found inside. + */ + public function test_rendering_query_with_enhanced_pagination_auto_disabled_when_post_content_block_is_found() { + global $wp_query, $wp_the_query; + + $content = << +
+ + + +
+ +HTML; + + // Set main query to single post. + $wp_query = new WP_Query( + array( + 'posts_per_page' => 1, + ) + ); + + $wp_the_query = $wp_query; + + $output = do_blocks( $content ); + + $p = new WP_HTML_Tag_Processor( $output ); + + $p->next_tag( array( 'class_name' => 'wp-block-query' ) ); + $this->assertSame( 'query-0', $p->get_attribute( 'data-wp-navigation-id' ) ); + $this->assertSame( 'true', $p->get_attribute( 'data-wp-navigation-disabled' ) ); + } + /** * Tests that the correct `core/query` blocks get the attribute that * disables enhanced pagination only if they contain a descendant that is