wppaste
WordPress

WP_Interactivity_API::get_directive_entries( WP_Interactivity_API_Directives_Processor $p, string $prefix ): array

Since
6.9.0
Source
wp-includes/interactivity-api/class-wp-interactivity-api.php:931
Parse the HTML element and get all the valid directives with the given prefix.

Compatibility

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

Present in 3 of the 5 tracked releases, added in 6.9.0, and compiles on PHP 7.4 through 8.6-dev.

Parameters

$pWP_Interactivity_API_Directives_Processor
The directives processor instance.
$prefixstring
The directive prefix to filter by.

Return value

array
An array of entries containing the directive namespace, value, suffix, and unique ID.

Performance profile

How much work a call to WP_Interactivity_API::get_directive_entries() 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
12–22

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

Plugin surface
None

Nothing here hands control to plugin code.

Called by
6

6 places in core call this, so the cost is paid more often than your own code shows.

What one call costs · 1 distinct outcome

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

WhenInstructionsCalls it makes
always12–22none

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev9312–2213
8.59312–2213
8.49312–2213
8.39312–2213
8.29312–2213
8.19312–221324 more instructions than PHP 7.4
7.46910–208

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

Used by · 6

Source code

	private function get_directive_entries( WP_Interactivity_API_Directives_Processor $p, string $prefix ): array {		$directive_attributes = $p->get_attribute_names_with_prefix( 'data-wp-' . $prefix );		if ( null === $directive_attributes ) {			return array();		} 		$entries = array();		foreach ( $directive_attributes as $attribute_name ) {			$parsed_directive = $this->parse_directive_name( $attribute_name );			if ( null === $parsed_directive ) {				continue;			} 			[ 'prefix' => $attr_prefix, 'suffix' => $suffix, 'unique_id' => $unique_id ] = $parsed_directive;			// Ensure it is the desired directive.			if ( $prefix !== $attr_prefix ) {				continue;			}			$attribute_value = $p->get_attribute( $attribute_name );			if ( null === $attribute_value ) {				continue;			}			/*			 * The namespace stack can hold false, which data_wp_interactive_processor() pushes for a			 * `data-wp-interactive` whose namespace is invalid and which has no enclosing one to inherit. Only a			 * string names a store, so anything else counts as no default namespace at all.			 */			$default_namespace = array_last( $this->namespace_stack ?? array() );			if ( ! is_string( $default_namespace ) ) {				$default_namespace = null;			} 			list( $namespace, $value ) = $this->extract_directive_value( $attribute_value, $default_namespace );			$entries[]                 = array(				'namespace' => $namespace,				'value'     => $value,				'suffix'    => $suffix,				'unique_id' => $unique_id,			);		}		// Sort directive entries to ensure stable ordering with the client.		// Put nulls first, then sort by suffix and finally by uniqueIds.		usort(			$entries,			function ( $a, $b ) {				$a_suffix = $a['suffix'] ?? '';				$b_suffix = $b['suffix'] ?? '';				if ( $a_suffix !== $b_suffix ) {					return $a_suffix <=> $b_suffix;				}				$a_id = $a['unique_id'] ?? '';				$b_id = $b['unique_id'] ?? '';				return $a_id <=> $b_id;			}		);		return $entries;	}

Changelog

Introduced in 6.9.0. Unchanged from 6.9.7 through 7.1.0.

  1. 6.9.7
  2. 7.0.4
  3. 7.1.0

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

About this page

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