From 0f0735a8882370393571c0613ecbbf6dda4b1db0 Mon Sep 17 00:00:00 2001 From: Jorge Costa Date: Mon, 8 Nov 2021 22:30:41 +0000 Subject: [PATCH] Add: get_query_pagination_arrow function to core. Fixes a crash that is happening when using an FSE theme because a function required is missing. Ports the function from the Gutenberg plugin. Props oandregal, youknowriad. git-svn-id: https://develop.svn.wordpress.org/trunk@52057 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-includes/blocks.php | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/src/wp-includes/blocks.php b/src/wp-includes/blocks.php index 97c292d875..5b855e6502 100644 --- a/src/wp-includes/blocks.php +++ b/src/wp-includes/blocks.php @@ -1146,3 +1146,37 @@ function build_query_vars_from_query_block( $block, $page ) { } return $query; } + +/** + * Helper function that returns the proper pagination arrow html for + * `QueryPaginationNext` and `QueryPaginationPrevious` blocks based + * on the provided `paginationArrow` from `QueryPagination` context. + * + * It's used in QueryPaginationNext and QueryPaginationPrevious blocks. + * + * @param WP_Block $block Block instance. + * @param boolean $is_next Flag for hanlding `next/previous` blocks. + * + * @return string|null Returns the constructed WP_Query arguments. + */ +function get_query_pagination_arrow( $block, $is_next ) { + $arrow_map = array( + 'none' => '', + 'arrow' => array( + 'next' => '→', + 'previous' => '←', + ), + 'chevron' => array( + 'next' => '»', + 'previous' => '«', + ), + ); + if ( ! empty( $block->context['paginationArrow'] ) && array_key_exists( $block->context['paginationArrow'], $arrow_map ) && ! empty( $arrow_map[ $block->context['paginationArrow'] ] ) ) { + $pagination_type = $is_next ? 'next' : 'previous'; + $arrow_attribute = $block->context['paginationArrow']; + $arrow = $arrow_map[ $block->context['paginationArrow'] ][ $pagination_type ]; + $arrow_classes = "wp-block-query-pagination-$pagination_type-arrow is-arrow-$arrow_attribute"; + return "$arrow"; + } + return null; +}