wppaste
WordPress

do_shortcode_tag( array $m ): string

Since
2.5.0
Source
wp-includes/shortcodes.php:392
Regular Expression callable for do_shortcode() for calling shortcode hook.

Compatibility

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

$marray
Regular expression match array.
  • $0string

    Entire matched shortcode text.
  • $1string

    Optional second opening bracket for escaping shortcodes.
  • $2string

    Shortcode name.
  • $3string

    Shortcode arguments list.
  • $4string

    Optional self closing slash.
  • $5string

    Content of a shortcode when it wraps some content.
  • $6string

    Optional second closing bracket for escaping shortcodes.

Return value

string
Shortcode output.

Performance profile

How much work a call to do_shortcode_tag() 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–53

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

Plugin surface
2 hooks

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

Called by
1

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

What it touches

  • hookthird-party callbacksapply_filters()called directly

Further down the call graph this can also reach query, option, cache, serialize 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 · 4 distinct outcomes

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

WhenInstructionsCalls it makes
always12none
is_callable() && $return !== false28–31shortcode_parse_atts(), is_callable(), apply_filters()
!is_callable()31–34shortcode_parse_atts(), is_callable(), __(), sprintf(), _doing_it_wrong()
is_callable() && $return === false49–53shortcode_parse_atts(), is_callable(), apply_filters(), call_user_func(), apply_filters()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev7312–535
8.57312–535
8.47312–5353 fewer instructions than PHP 8.3
8.37615–535
8.27615–535
8.17615–5351 fewer instruction than PHP 7.4
7.47715–545

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

2 hooks fire while do_shortcode_tag() runs, in this order:

  1. apply_filters( pre_do_shortcode_tag )filterline 427 (+35 into the body)

    Filters whether to call a shortcode callback.

  2. apply_filters( do_shortcode_tag )filterline 447 (+55 into the body)

    Filters the output created by a shortcode callback.

Uses · 4

Used by · 1

Source code

function do_shortcode_tag( $m ) {	global $shortcode_tags; 	// Allow [[foo]] syntax for escaping a tag.	if ( '[' === $m[1] && ']' === $m[6] ) {		return substr( $m[0], 1, -1 );	} 	$tag  = $m[2];	$attr = shortcode_parse_atts( $m[3] ); 	if ( ! is_callable( $shortcode_tags[ $tag ] ) ) {		_doing_it_wrong(			__FUNCTION__,			/* translators: %s: Shortcode tag. */			sprintf( __( 'Attempting to parse a shortcode without a valid callback: %s' ), $tag ),			'4.3.0'		);		return $m[0];	} 	/**	 * Filters whether to call a shortcode callback.	 *	 * Returning a non-false value from filter will short-circuit the	 * shortcode generation process, returning that value instead.	 *	 * @since 4.7.0	 * @since 6.5.0 The `$attr` parameter is always an array.	 *	 * @param false|string $output Short-circuit return value. Either false or the value to replace the shortcode with.	 * @param string       $tag    Shortcode name.	 * @param array        $attr   Shortcode attributes array, can be empty if the original arguments string cannot be parsed.	 * @param array        $m      Regular expression match array.	 */	$return = apply_filters( 'pre_do_shortcode_tag', false, $tag, $attr, $m );	if ( false !== $return ) {		return $return;	} 	$content = isset( $m[5] ) ? $m[5] : null; 	$output = $m[1] . call_user_func( $shortcode_tags[ $tag ], $attr, $content, $tag ) . $m[6]; 	/**	 * Filters the output created by a shortcode callback.	 *	 * @since 4.7.0	 * @since 6.5.0 The `$attr` parameter is always an array.	 *	 * @param string $output Shortcode output.	 * @param string $tag    Shortcode name.	 * @param array  $attr   Shortcode attributes array, can be empty if the original arguments string cannot be parsed.	 * @param array  $m      Regular expression match array.	 */	return apply_filters( 'do_shortcode_tag', $output, $tag, $attr, $m );}

Changelog

Introduced in 2.5.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 6.7.7 tag, from src/wp-includes/shortcodes.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.