| 1 |
<?php |
| 2 |
/** |
| 3 |
* Temporary compatibility shims for features present in Gutenberg. |
| 4 |
* This file should be removed when WordPress 5.9.0 becomes the lowest |
| 5 |
* supported version by this plugin. |
| 6 |
* |
| 7 |
* @package gutenberg |
| 8 |
*/ |
| 9 |
|
| 10 |
if ( ! function_exists( 'get_query_pagination_arrow' ) ) { |
| 11 |
/** |
| 12 |
* Helper function that returns the proper pagination arrow html for |
| 13 |
* `QueryPaginationNext` and `QueryPaginationPrevious` blocks based |
| 14 |
* on the provided `paginationArrow` from `QueryPagination` context. |
| 15 |
* |
| 16 |
* It's used in QueryPaginationNext and QueryPaginationPrevious blocks. |
| 17 |
* |
| 18 |
* @param WP_Block $block Block instance. |
| 19 |
* @param boolean $is_next Flag for hanlding `next/previous` blocks. |
| 20 |
* |
| 21 |
* @return string|null Returns the constructed WP_Query arguments. |
| 22 |
*/ |
| 23 |
function get_query_pagination_arrow( $block, $is_next ) { |
| 24 |
$arrow_map = array( |
| 25 |
'none' => '', |
| 26 |
'arrow' => array( |
| 27 |
'next' => '→', |
| 28 |
'previous' => '←', |
| 29 |
), |
| 30 |
'chevron' => array( |
| 31 |
'next' => '»', |
| 32 |
'previous' => '«', |
| 33 |
), |
| 34 |
); |
| 35 |
if ( ! empty( $block->context['paginationArrow'] ) && array_key_exists( $block->context['paginationArrow'], $arrow_map ) && ! empty( $arrow_map[ $block->context['paginationArrow'] ] ) ) { |
| 36 |
$pagination_type = $is_next ? 'next' : 'previous'; |
| 37 |
$arrow_attribute = $block->context['paginationArrow']; |
| 38 |
$arrow = $arrow_map[ $block->context['paginationArrow'] ][ $pagination_type ]; |
| 39 |
$arrow_classes = "wp-block-query-pagination-$pagination_type-arrow is-arrow-$arrow_attribute"; |
| 40 |
return "<span class='$arrow_classes'>$arrow</span>"; |
| 41 |
} |
| 42 |
return null; |
| 43 |
} |
| 44 |
} |
| 45 |
|