Skip to content

Commit

Permalink
Prevent usage of post content block
Browse files Browse the repository at this point in the history
  • Loading branch information
luisherranz committed Nov 1, 2023
1 parent 14760cb commit 59c0270
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
2 changes: 1 addition & 1 deletion packages/block-library/src/query/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
37 changes: 36 additions & 1 deletion phpunit/blocks/render-query-test.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 = <<<HTML
Expand Down Expand Up @@ -167,6 +167,41 @@ public function test_rendering_query_with_enhanced_pagination_auto_disabled() {
$this->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
<!-- wp:query {"queryId":0,"query":{"inherit":true},"enhancedPagination":true} -->
<div class="wp-block-query">
<!-- wp:post-template {"align":"wide"} -->
<!-- wp:post-content /-->
<!-- /wp:post-template -->
</div>
<!-- /wp:query -->
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
Expand Down

0 comments on commit 59c0270

Please sign in to comment.