Skip to content

Commit

Permalink
Respect enhancedPagination context
Browse files Browse the repository at this point in the history
  • Loading branch information
ockham committed Aug 29, 2024
1 parent f2afb10 commit d9dc1b7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions packages/block-library/src/categories/block.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
"default": true
}
},
"usesContext": [ "enhancedPagination" ],
"supports": {
"align": true,
"html": false,
Expand Down
17 changes: 11 additions & 6 deletions packages/block-library/src/categories/index.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
* Renders the `core/categories` block on server.
*
* @since 5.0.0
* @since 6.7.0 Enable client-side rendering if enhancedPagination context is true.
*
* @param array $attributes The block attributes.
* @param array $attributes The block attributes.
* @param string $content Block default content.
* @param WP_Block $block Block instance.
*
* @return string Returns the categories list/dropdown markup.
*/
function render_block_core_categories( $attributes ) {
function render_block_core_categories( $attributes, $content, $block ) {
static $block_id = 0;
++$block_id;

Expand Down Expand Up @@ -55,11 +58,13 @@ function render_block_core_categories( $attributes ) {
$items_markup = wp_list_categories( $args );
$type = 'list';

$p = new WP_HTML_Tag_Processor( $items_markup );
while ( $p->next_tag( 'a' ) ) {
$p->set_attribute( 'data-wp-on--click', 'core/query::actions.navigate' );
if ( ! empty ( $block->context['enhancedPagination'] ) ) {

Check failure on line 61 in packages/block-library/src/categories/index.php

View workflow job for this annotation

GitHub Actions / PHP coding standards

Space before opening parenthesis of function call prohibited
$p = new WP_HTML_Tag_Processor( $items_markup );
while ( $p->next_tag( 'a' ) ) {
$p->set_attribute( 'data-wp-on--click', 'core/query::actions.navigate' );
}
$items_markup = $p->get_updated_html();
}
$items_markup = $p->get_updated_html();
}

$wrapper_attributes = get_block_wrapper_attributes( array( 'class' => "wp-block-categories-{$type}" ) );
Expand Down

0 comments on commit d9dc1b7

Please sign in to comment.