From ed5f56ed94efdf96913730fcb76062299287710e Mon Sep 17 00:00:00 2001 From: David Arenas Date: Mon, 12 Feb 2024 16:28:06 +0100 Subject: [PATCH] Pagination Numbers: Add `data-wp-key` to pagination numbers if enhanced pagination is enabled (#58189) * Add `data-wp-key` to pagination numbers * Use tag index as the `data-wp-key` value Co-authored-by: DAreRodz Co-authored-by: SantosGuillamot Co-authored-by: c4rl0sbr4v0 --- .../src/query-pagination-numbers/index.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/packages/block-library/src/query-pagination-numbers/index.php b/packages/block-library/src/query-pagination-numbers/index.php index 2f9370751f6d25..e6f8b461110407 100644 --- a/packages/block-library/src/query-pagination-numbers/index.php +++ b/packages/block-library/src/query-pagination-numbers/index.php @@ -91,14 +91,17 @@ function render_block_core_query_pagination_numbers( $attributes, $content, $blo } if ( $enhanced_pagination ) { - $p = new WP_HTML_Tag_Processor( $content ); + $p = new WP_HTML_Tag_Processor( $content ); + $tag_index = 0; while ( $p->next_tag( - array( - 'tag_name' => 'a', - 'class_name' => 'page-numbers', - ) + array( 'class_name' => 'page-numbers' ) ) ) { - $p->set_attribute( 'data-wp-on--click', 'core/query::actions.navigate' ); + if ( null === $p->get_attribute( 'data-wp-key' ) ) { + $p->set_attribute( 'data-wp-key', 'index-' . $tag_index++ ); + } + if ( 'A' === $p->get_tag() ) { + $p->set_attribute( 'data-wp-on--click', 'core/query::actions.navigate' ); + } } $content = $p->get_updated_html(); }