wppaste
WordPress

block_core_query_disable_enhanced_pagination( array $parsed_block ): array

Since
6.4.0
Source
wp-includes/blocks/query.php:84
Traverse the tree of blocks looking for any plugin block (i.e., a block from an installed plugin) inside a Query block with the enhanced pagination enabled. If at least one is found, the enhanced pagination is effectively disabled to prevent any potential incompatibilities.

Compatibility

WordPress
since 6.4.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

$parsed_blockarray
The block being rendered.

Return value

array
Returns the parsed block, unmodified.

Performance profile

How much work a call to block_core_query_disable_enhanced_pagination() 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
Trivial

Touches nothing outside its own arguments.

Scaling
Constant

No loop in the body: the same number of instructions runs whatever you pass in.

Instructions
11–39

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

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 one call costs · 5 distinct outcomes

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

WhenInstructionsCalls it makes
always11–17none
!isset($dirty_enhanced_queries) && !empty($enhanced_query_stack)20–26array_pop()
!isset($dirty_enhanced_queries) && empty($enhanced_query_stack)25–31array_pop(), remove_filter()
isset($dirty_enhanced_queries) && !empty($enhanced_query_stack)28–34wp_interactivity_config(), array_pop()
isset($dirty_enhanced_queries) && empty($enhanced_query_stack)33–39wp_interactivity_config(), array_pop(), remove_filter()

Across PHP versions

Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 110 instructions, 11–39 executed per call, 18 branches. The work does not change between versions.

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 · 5

Source code

function block_core_query_disable_enhanced_pagination( $parsed_block ) {	static $enhanced_query_stack   = array();	static $dirty_enhanced_queries = array();	static $render_query_callback  = null; 	$block_name              = $parsed_block['blockName'];	$block_type              = WP_Block_Type_Registry::get_instance()->get_registered( $block_name );	$has_enhanced_pagination = isset( $parsed_block['attrs']['enhancedPagination'] ) && true === $parsed_block['attrs']['enhancedPagination'] && isset( $parsed_block['attrs']['queryId'] );	/*	 * Client side navigation can be true in two states:	 *  - supports.interactivity = true;	 *  - supports.interactivity.clientNavigation = true;	 */	$supports_client_navigation = ( isset( $block_type->supports['interactivity']['clientNavigation'] ) && true === $block_type->supports['interactivity']['clientNavigation'] )		|| ( isset( $block_type->supports['interactivity'] ) && true === $block_type->supports['interactivity'] ); 	if ( 'core/query' === $block_name && $has_enhanced_pagination ) {		$enhanced_query_stack[] = $parsed_block['attrs']['queryId']; 		if ( ! isset( $render_query_callback ) ) {			/**			 * Filter that disables the enhanced pagination feature during block			 * rendering when a plugin block has been found inside. It does so			 * by adding an attribute called `data-wp-navigation-disabled` which			 * is later handled by the front-end logic.			 *			 * @param string   $content  The block content.			 * @param array    $block    The full block, including name and attributes.			 * @return string Returns the modified output of the query block.			 */			$render_query_callback = static function ( $content, $block ) use ( &$enhanced_query_stack, &$dirty_enhanced_queries, &$render_query_callback ) {				$has_enhanced_pagination = isset( $block['attrs']['enhancedPagination'] ) && true === $block['attrs']['enhancedPagination'] && isset( $block['attrs']['queryId'] ); 				if ( ! $has_enhanced_pagination ) {					return $content;				} 				if ( isset( $dirty_enhanced_queries[ $block['attrs']['queryId'] ] ) ) {					// Disable navigation in the router store config.					wp_interactivity_config( 'core/router', array( 'clientNavigationDisabled' => true ) );					$dirty_enhanced_queries[ $block['attrs']['queryId'] ] = null;				} 				array_pop( $enhanced_query_stack ); 				if ( empty( $enhanced_query_stack ) ) {					remove_filter( 'render_block_core/query', $render_query_callback );					$render_query_callback = null;				} 				return $content;			}; 			add_filter( 'render_block_core/query', $render_query_callback, 10, 2 );		}	} elseif (		! empty( $enhanced_query_stack ) &&		isset( $block_name ) &&		( ! $supports_client_navigation )	) {		foreach ( $enhanced_query_stack as $query_id ) {			$dirty_enhanced_queries[ $query_id ] = true;		}	} 	return $parsed_block;}

Changelog

Introduced in 6.4.0. One change between 6.7.7 and 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.

6.8.8
Return type changed from string to array.verified against source
6.4.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.1.0 tag, from src/wp-includes/blocks/query.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.