wppaste
WordPress

render_block_core_query_pagination_numbers( array $attributes, string $content, WP_Block $block ): string

Since
5.8.0
Source
wp-includes/blocks/query-pagination-numbers.php:21
Renders the core/query-pagination-numbers block on the server.

Compatibility

WordPress
since 5.8.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$attributesarray
Block attributes.
$contentstring
Block default content.
$blockWP_Block
Block instance.

Return value

string
Returns the pagination numbers for the Query.

Performance profile

How much work a call to render_block_core_query_pagination_numbers() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Heavy

Reads stored settings via get_option(), cached per request but not free on a cold cache.

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
58–122

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 173.

Plugin surface
None

Nothing here hands control to plugin code.

Called by
0

Nothing in core calls this; the cost is only what you spend yourself.

What it touches

  • hookthird-party callbacksapply_filters()one call below render_block_core_query_pagination_numbers()
  • optionoption read or writeget_option()one call below render_block_core_query_pagination_numbers()

Further down the call graph this can also reach cache, serialize, query and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 6 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost render_block_core_query_pagination_numbers() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
empty($content)58–69get_block_wrapper_attributes(), paginate_links()
!empty($content)64–75get_block_wrapper_attributes(), paginate_links(), sprintf()
!empty($content) && !->next_tag()77–88get_block_wrapper_attributes(), paginate_links(), paged(), ->next_tag(), ->get_updated_html(), sprintf()
!isset($value) && empty($content)82–103get_block_wrapper_attributes(), build_query_vars_from_query_block(), prev_next(), paginate_links(), wp_reset_postdata()
!isset($value) && !empty($content)88–109get_block_wrapper_attributes(), build_query_vars_from_query_block(), prev_next(), paginate_links(), wp_reset_postdata(), sprintf()
!isset($value) && !empty($content) && !->next_tag()101–122get_block_wrapper_attributes(), build_query_vars_from_query_block(), prev_next(), paginate_links(), wp_reset_postdata(), paged(), ->next_tag(), ->get_updated_html(), sprintf()

This body has more branch combinations than are worth enumerating, so the table covers the outcomes found first rather than every one that exists.

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev17358–12221
8.517358–12221
8.417358–122213 fewer instructions than PHP 8.3
8.317658–12521
8.217658–12521
8.117658–125216 fewer instructions than PHP 7.4
7.418259–12921

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Uses · 6

Source code

function render_block_core_query_pagination_numbers( $attributes, $content, $block ) {	$page_key            = isset( $block->context['queryId'] ) ? 'query-' . $block->context['queryId'] . '-page' : 'query-page';	$enhanced_pagination = (bool) ( $block->context['enhancedPagination'] ?? false );	$page                = empty( $_GET[ $page_key ] ) ? 1 : (int) $_GET[ $page_key ];	$max_page            = (int) ( $block->context['query']['pages'] ?? 0 ); 	$wrapper_attributes = get_block_wrapper_attributes();	$content            = '';	global $wp_query;	$mid_size = isset( $block->attributes['midSize'] ) ? (int) $block->attributes['midSize'] : null;	if ( isset( $block->context['query']['inherit'] ) && $block->context['query']['inherit'] ) {		// Take into account if we have set a bigger `max page`		// than what the query has.		$total         = ! $max_page || $max_page > $wp_query->max_num_pages ? $wp_query->max_num_pages : $max_page;		$paginate_args = array(			'prev_next' => false,			'total'     => $total,		);		if ( null !== $mid_size ) {			$paginate_args['mid_size'] = $mid_size;		}		$content = paginate_links( $paginate_args );	} else {		$block_query = new WP_Query( build_query_vars_from_query_block( $block, $page ) );		// `paginate_links` works with the global $wp_query, so we have to		// temporarily switch it with our custom query.		$prev_wp_query = $wp_query;		$wp_query      = $block_query;		$total         = ! $max_page || $max_page > $wp_query->max_num_pages ? $wp_query->max_num_pages : $max_page;		$paginate_args = array(			'base'      => '%_%',			'format'    => "?$page_key=%#%",			'current'   => max( 1, $page ),			'total'     => $total,			'prev_next' => false,		);		if ( null !== $mid_size ) {			$paginate_args['mid_size'] = $mid_size;		}		if ( 1 !== $page ) {			/**			 * `paginate_links` doesn't use the provided `format` when the page is `1`.			 * This is great for the main query as it removes the extra query params			 * making the URL shorter, but in the case of multiple custom queries is			 * problematic. It results in returning an empty link which ends up with			 * a link to the current page.			 *			 * A way to address this is to add a `fake` query arg with no value that			 * is the same for all custom queries. This way the link is not empty and			 * preserves all the other existent query args.			 *			 * @see https://developer.wordpress.org/reference/functions/paginate_links/			 *			 * The proper fix of this should be in core. Track Ticket:			 * @see https://core.trac.wordpress.org/ticket/53868			 *			 * TODO: After two WP versions (starting from the WP version the core patch landed),			 * we should remove this and call `paginate_links` with the proper new arg.			 */			$paginate_args['add_args'] = array( 'cst' => '' );		}		// We still need to preserve `paged` query param if exists, as is used		// for Queries that inherit from global context.		$paged = empty( $_GET['paged'] ) ? null : (int) $_GET['paged'];		if ( $paged ) {			$paginate_args['add_args'] = array( 'paged' => $paged );		}		$content = paginate_links( $paginate_args );		wp_reset_postdata(); // Restore original Post Data.		$wp_query = $prev_wp_query;	} 	if ( empty( $content ) ) {		return '';	} 	if ( $enhanced_pagination ) {		$p         = new WP_HTML_Tag_Processor( $content );		$tag_index = 0;		while ( $p->next_tag(

Changelog

Introduced in 5.8.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/blocks/query-pagination-numbers.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.