wp/wp-includes/blocks/query-pagination-next.php
changeset 19 3d72ae0968f4
parent 18 be944660c56a
child 21 48c4eec2b7e6
equal deleted inserted replaced
18:be944660c56a 19:3d72ae0968f4
    18 	$page_key = isset( $block->context['queryId'] ) ? 'query-' . $block->context['queryId'] . '-page' : 'query-page';
    18 	$page_key = isset( $block->context['queryId'] ) ? 'query-' . $block->context['queryId'] . '-page' : 'query-page';
    19 	$page     = empty( $_GET[ $page_key ] ) ? 1 : (int) $_GET[ $page_key ];
    19 	$page     = empty( $_GET[ $page_key ] ) ? 1 : (int) $_GET[ $page_key ];
    20 	$max_page = isset( $block->context['query']['pages'] ) ? (int) $block->context['query']['pages'] : 0;
    20 	$max_page = isset( $block->context['query']['pages'] ) ? (int) $block->context['query']['pages'] : 0;
    21 
    21 
    22 	$wrapper_attributes = get_block_wrapper_attributes();
    22 	$wrapper_attributes = get_block_wrapper_attributes();
    23 	$default_label      = __( 'Next Page »' );
    23 	$default_label      = __( 'Next Page' );
    24 	$label              = isset( $attributes['label'] ) && ! empty( $attributes['label'] ) ? $attributes['label'] : $default_label;
    24 	$label              = isset( $attributes['label'] ) && ! empty( $attributes['label'] ) ? esc_html( $attributes['label'] ) : $default_label;
    25 	$content            = '';
    25 	$pagination_arrow   = get_query_pagination_arrow( $block, true );
       
    26 
       
    27 	if ( $pagination_arrow ) {
       
    28 		$label .= $pagination_arrow;
       
    29 	}
       
    30 	$content = '';
    26 
    31 
    27 	// Check if the pagination is for Query that inherits the global context.
    32 	// Check if the pagination is for Query that inherits the global context.
    28 	if ( isset( $block->context['query']['inherit'] ) && $block->context['query']['inherit'] ) {
    33 	if ( isset( $block->context['query']['inherit'] ) && $block->context['query']['inherit'] ) {
    29 		$filter_link_attributes = function() use ( $wrapper_attributes ) {
    34 		$filter_link_attributes = function() use ( $wrapper_attributes ) {
    30 			return $wrapper_attributes;
    35 			return $wrapper_attributes;
    37 			$max_page = $wp_query->max_num_pages;
    42 			$max_page = $wp_query->max_num_pages;
    38 		}
    43 		}
    39 		$content = get_next_posts_link( $label, $max_page );
    44 		$content = get_next_posts_link( $label, $max_page );
    40 		remove_filter( 'next_posts_link_attributes', $filter_link_attributes );
    45 		remove_filter( 'next_posts_link_attributes', $filter_link_attributes );
    41 	} elseif ( ! $max_page || $max_page > $page ) {
    46 	} elseif ( ! $max_page || $max_page > $page ) {
    42 		$custom_query = new WP_Query( build_query_vars_from_query_block( $block, $page ) );
    47 		$custom_query           = new WP_Query( build_query_vars_from_query_block( $block, $page ) );
    43 		if ( (int) $custom_query->max_num_pages !== $page ) {
    48 		$custom_query_max_pages = (int) $custom_query->max_num_pages;
       
    49 		if ( $custom_query_max_pages && $custom_query_max_pages !== $page ) {
    44 			$content = sprintf(
    50 			$content = sprintf(
    45 				'<a href="%1$s" %2$s>%3$s</a>',
    51 				'<a href="%1$s" %2$s>%3$s</a>',
    46 				esc_url( add_query_arg( $page_key, $page + 1 ) ),
    52 				esc_url( add_query_arg( $page_key, $page + 1 ) ),
    47 				$wrapper_attributes,
    53 				$wrapper_attributes,
    48 				$label
    54 				$label