From 8e7b8a1837dba53497220cd7fa5b0cb2559c1799 Mon Sep 17 00:00:00 2001 From: jorgefilipecosta Date: Mon, 8 Nov 2021 22:31:58 +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. Built from https://develop.svn.wordpress.org/trunk@52057 git-svn-id: http://core.svn.wordpress.org/trunk@51649 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/blocks.php | 34 ++++++++++++++++++++++++++++++++++ wp-includes/version.php | 2 +- 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/wp-includes/blocks.php b/wp-includes/blocks.php index 97c292d875..5b855e6502 100644 --- a/wp-includes/blocks.php +++ b/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; +} diff --git a/wp-includes/version.php b/wp-includes/version.php index 7c8bb76001..137dfdb152 100644 --- a/wp-includes/version.php +++ b/wp-includes/version.php @@ -16,7 +16,7 @@ * * @global string $wp_version */ -$wp_version = '5.9-alpha-52056'; +$wp_version = '5.9-alpha-52057'; /** * Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.