Skip to content

Commit

Permalink
Require queryId for enhanced pagination. (#55720)
Browse files Browse the repository at this point in the history
  • Loading branch information
peterwilsoncc authored and mikachan committed Oct 31, 2023
1 parent d965341 commit de980d5
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions packages/block-library/src/query/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,14 @@
*
* @since 6.4.0
*
* @param array $attributes Block attributes.
* @param string $content Block default content.
* @param string $block Block instance.
* @param array $attributes Block attributes.
* @param string $content Block default content.
* @param WP_Block $block The block instance.
*
* @return string Returns the modified output of the query block.
*/
function render_block_core_query( $attributes, $content, $block ) {
if ( $attributes['enhancedPagination'] ) {
if ( $attributes['enhancedPagination'] && isset( $attributes['queryId'] ) ) {
$p = new WP_HTML_Tag_Processor( $content );
if ( $p->next_tag() ) {
// Add the necessary directives.
Expand Down Expand Up @@ -67,11 +67,14 @@ class="wp-block-query__enhanced-pagination-animation"
if ( ! wp_script_is( $view_asset ) ) {
$script_handles = $block->block_type->view_script_handles;
// If the script is not needed, and it is still in the `view_script_handles`, remove it.
if ( ! $attributes['enhancedPagination'] && in_array( $view_asset, $script_handles, true ) ) {
if (
( ! $attributes['enhancedPagination'] || ! isset( $attributes['queryId'] ) )
&& in_array( $view_asset, $script_handles, true )
) {
$block->block_type->view_script_handles = array_diff( $script_handles, array( $view_asset ) );
}
// If the script is needed, but it was previously removed, add it again.
if ( $attributes['enhancedPagination'] && ! in_array( $view_asset, $script_handles, true ) ) {
if ( $attributes['enhancedPagination'] && isset( $attributes['queryId'] ) && ! in_array( $view_asset, $script_handles, true ) ) {
$block->block_type->view_script_handles = array_merge( $script_handles, array( $view_asset ) );
}
}
Expand All @@ -80,11 +83,14 @@ class="wp-block-query__enhanced-pagination-animation"
if ( ! wp_style_is( $style_asset ) ) {
$style_handles = $block->block_type->style_handles;
// If the styles are not needed, and they are still in the `style_handles`, remove them.
if ( ! $attributes['enhancedPagination'] && in_array( $style_asset, $style_handles, true ) ) {
if (
( ! $attributes['enhancedPagination'] || ! isset( $attributes['queryId'] ) )
&& in_array( $style_asset, $style_handles, true )
) {
$block->block_type->style_handles = array_diff( $style_handles, array( $style_asset ) );
}
// If the styles are needed, but they were previously removed, add them again.
if ( $attributes['enhancedPagination'] && ! in_array( $style_asset, $style_handles, true ) ) {
if ( $attributes['enhancedPagination'] && isset( $attributes['queryId'] ) && ! in_array( $style_asset, $style_handles, true ) ) {
$block->block_type->style_handles = array_merge( $style_handles, array( $style_asset ) );
}
}
Expand Down

0 comments on commit de980d5

Please sign in to comment.