Make WordPress Core

Changeset 52057


Ignore:
Timestamp:
11/08/2021 10:30:41 PM (3 years ago)
Author:
jorgefilipecosta
Message:

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.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-includes/blocks.php

    r52012 r52057  
    11471147    return $query;
    11481148}
     1149
     1150/**
     1151 * Helper function that returns the proper pagination arrow html for
     1152 * `QueryPaginationNext` and `QueryPaginationPrevious` blocks based
     1153 * on the provided `paginationArrow` from `QueryPagination` context.
     1154 *
     1155 * It's used in QueryPaginationNext and QueryPaginationPrevious blocks.
     1156 *
     1157 * @param WP_Block $block   Block instance.
     1158 * @param boolean  $is_next Flag for hanlding `next/previous` blocks.
     1159 *
     1160 * @return string|null Returns the constructed WP_Query arguments.
     1161 */
     1162function get_query_pagination_arrow( $block, $is_next ) {
     1163    $arrow_map = array(
     1164        'none'    => '',
     1165        'arrow'   => array(
     1166            'next'     => '→',
     1167            'previous' => '←',
     1168        ),
     1169        'chevron' => array(
     1170            'next'     => '»',
     1171            'previous' => '«',
     1172        ),
     1173    );
     1174    if ( ! empty( $block->context['paginationArrow'] ) && array_key_exists( $block->context['paginationArrow'], $arrow_map ) && ! empty( $arrow_map[ $block->context['paginationArrow'] ] ) ) {
     1175        $pagination_type = $is_next ? 'next' : 'previous';
     1176        $arrow_attribute = $block->context['paginationArrow'];
     1177        $arrow           = $arrow_map[ $block->context['paginationArrow'] ][ $pagination_type ];
     1178        $arrow_classes   = "wp-block-query-pagination-$pagination_type-arrow is-arrow-$arrow_attribute";
     1179        return "<span class='$arrow_classes'>$arrow</span>";
     1180    }
     1181    return null;
     1182}
Note: See TracChangeset for help on using the changeset viewer.