[ Index ] |
PHP Cross Reference of WordPress Trunk (Updated Daily) |
[Summary view] [Print] [Text view]
1 <?php 2 /** 3 * Server-side rendering of the `core/query-pagination-previous` block. 4 * 5 * @package WordPress 6 */ 7 8 /** 9 * Renders the `core/query-pagination-previous` block on the server. 10 * 11 * @param array $attributes Block attributes. 12 * @param string $content Block default content. 13 * @param WP_Block $block Block instance. 14 * 15 * @return string Returns the previous posts link for the query. 16 */ 17 function render_block_core_query_pagination_previous( $attributes, $content, $block ) { 18 $page_key = isset( $block->context['queryId'] ) ? 'query-' . $block->context['queryId'] . '-page' : 'query-page'; 19 $enhanced_pagination = isset( $block->context['enhancedPagination'] ) && $block->context['enhancedPagination']; 20 $page = empty( $_GET[ $page_key ] ) ? 1 : (int) $_GET[ $page_key ]; 21 22 $wrapper_attributes = get_block_wrapper_attributes(); 23 $show_label = isset( $block->context['showLabel'] ) ? (bool) $block->context['showLabel'] : true; 24 $default_label = __( 'Previous Page' ); 25 $label_text = isset( $attributes['label'] ) && ! empty( $attributes['label'] ) ? esc_html( $attributes['label'] ) : $default_label; 26 $label = $show_label ? $label_text : ''; 27 $pagination_arrow = get_query_pagination_arrow( $block, false ); 28 if ( ! $label ) { 29 $wrapper_attributes .= ' aria-label="' . $label_text . '"'; 30 } 31 if ( $pagination_arrow ) { 32 $label = $pagination_arrow . $label; 33 } 34 $content = ''; 35 // Check if the pagination is for Query that inherits the global context 36 // and handle appropriately. 37 if ( isset( $block->context['query']['inherit'] ) && $block->context['query']['inherit'] ) { 38 $filter_link_attributes = static function () use ( $wrapper_attributes ) { 39 return $wrapper_attributes; 40 }; 41 42 add_filter( 'previous_posts_link_attributes', $filter_link_attributes ); 43 $content = get_previous_posts_link( $label ); 44 remove_filter( 'previous_posts_link_attributes', $filter_link_attributes ); 45 } elseif ( 1 !== $page ) { 46 $content = sprintf( 47 '<a href="%1$s" %2$s>%3$s</a>', 48 esc_url( add_query_arg( $page_key, $page - 1 ) ), 49 $wrapper_attributes, 50 $label 51 ); 52 } 53 54 if ( $enhanced_pagination && isset( $content ) ) { 55 $p = new WP_HTML_Tag_Processor( $content ); 56 if ( $p->next_tag( 57 array( 58 'tag_name' => 'a', 59 'class_name' => 'wp-block-query-pagination-previous', 60 ) 61 ) ) { 62 $p->set_attribute( 'data-wp-key', 'query-pagination-previous' ); 63 $p->set_attribute( 'data-wp-on--click', 'core/query::actions.navigate' ); 64 $p->set_attribute( 'data-wp-on--mouseenter', 'core/query::actions.prefetch' ); 65 $p->set_attribute( 'data-wp-watch', 'core/query::callbacks.prefetch' ); 66 $content = $p->get_updated_html(); 67 } 68 } 69 70 return $content; 71 } 72 73 /** 74 * Registers the `core/query-pagination-previous` block on the server. 75 */ 76 function register_block_core_query_pagination_previous() { 77 register_block_type_from_metadata( 78 __DIR__ . '/query-pagination-previous', 79 array( 80 'render_callback' => 'render_block_core_query_pagination_previous', 81 ) 82 ); 83 } 84 add_action( 'init', 'register_block_core_query_pagination_previous' );
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
Generated : Wed Apr 24 08:20:01 2024 | Cross-referenced by PHPXref |