wppaste
WordPress

wp_doc_link_parse( string $content ): string[]

Since
2.8.0
Source
wp-admin/includes/misc.php:630

Compatibility

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

$contentstring

Return value

string[]
Array of function names.

Performance profile

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

Touches nothing outside its own arguments.

Scaling
Scales with input

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

Instructions
4–38

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

Plugin surface
1 hook

Third-party callbacks on 'documentation_ignore_functions' run inside this call, and their cost is not bounded by anything here.

Called by
0

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

What it touches

  • hookthird-party callbacksapply_filters()called directly

What one call costs · 2 distinct outcomes

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

WhenInstructionsCalls it makes
always4–6none
is_string($content) && !empty($content) && !$t37–38token_get_all(), array_unique(), sort(), apply_filters(), array_unique()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev874–3814
8.5874–3814
8.4874–38143 fewer instructions than PHP 8.3
8.3904–3814
8.2904–3814
8.1904–3814
7.4904–3814

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.

Hooks and filters fired · 1

One hook fires while wp_doc_link_parse() runs, in this order:

  1. apply_filters( documentation_ignore_functions )filterline 672 (+42 into the body)

    Filters the list of functions and classes to be ignored from the documentation lookup.

Uses · 1

  • apply_filters()Calls the callback functions that have been added to a filter hook.

Source code

function wp_doc_link_parse( $content ) {	if ( ! is_string( $content ) || empty( $content ) ) {		return array();	} 	if ( ! function_exists( 'token_get_all' ) ) {		return array();	} 	$tokens           = token_get_all( $content );	$count            = count( $tokens );	$functions        = array();	$ignore_functions = array(); 	for ( $t = 0; $t < $count - 2; $t++ ) {		if ( ! is_array( $tokens[ $t ] ) ) {			continue;		} 		if ( T_STRING === $tokens[ $t ][0] && ( '(' === $tokens[ $t + 1 ] || '(' === $tokens[ $t + 2 ] ) ) {			// If it's a function or class defined locally, there's not going to be any docs available.			if ( ( isset( $tokens[ $t - 2 ][1] ) && in_array( $tokens[ $t - 2 ][1], array( 'function', 'class' ), true ) )				|| ( isset( $tokens[ $t - 2 ][0] ) && T_OBJECT_OPERATOR === $tokens[ $t - 1 ][0] )			) {				$ignore_functions[] = $tokens[ $t ][1];			} 			// Add this to our stack of unique references.			$functions[] = $tokens[ $t ][1];		}	} 	$functions = array_unique( $functions );	sort( $functions ); 	/**	 * Filters the list of functions and classes to be ignored from the documentation lookup.	 *	 * @since 2.8.0	 *	 * @param string[] $ignore_functions Array of names of functions and classes to be ignored.	 */	$ignore_functions = apply_filters( 'documentation_ignore_functions', $ignore_functions ); 	$ignore_functions = array_unique( $ignore_functions ); 	$output = array(); 	foreach ( $functions as $function ) {		if ( in_array( $function, $ignore_functions, true ) ) {			continue;		} 		$output[] = $function;	} 	return $output;}

Changelog

Introduced in 2.8.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 array to string[].verified against source
2.8.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.8.8 tag, from src/wp-admin/includes/misc.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.