-
Notifications
You must be signed in to change notification settings - Fork 4.3k
/
Copy pathblocks.php
44 lines (43 loc) · 1.56 KB
/
blocks.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<?php
/**
* Temporary compatibility shims for features present in Gutenberg.
* This file should be removed when WordPress 5.9.0 becomes the lowest
* supported version by this plugin.
*
* @package gutenberg
*/
if ( ! function_exists( 'get_query_pagination_arrow' ) ) {
/**
* 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 "<span class='$arrow_classes'>$arrow</span>";
}
return null;
}
}