wp_targeted_link_rel_callback( array $matches ): string
- Since
- 5.1.0, 5.6.0
- Source
wp-includes/formatting.php:3357
rel="noopener" string to HTML A element.Description
Will not duplicate an existing 'noopener' value to avoid invalidating the HTML.
Compatibility
Deprecated in WordPress 6.7.0. Kept for back-compatibility; avoid it in new code.
- WordPress
- since 5.6.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
$matchesarray- Single match.
Return value
string- HTML A Element with
rel="noopener"in addition to any existing values.
Performance profile
How much work a call to wp_targeted_link_rel_callback() 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
- Scaling
- Constant
- Instructions
- 28–70
- Plugin surface
- 1 hook
- Called by
- 0
Touches nothing outside its own arguments.
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 74.
Third-party callbacks on 'wp_targeted_link_rel' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
apply_filters()called directly - regexregular expression over the whole input
preg_split()called directly
Further down the call graph this can also reach option, 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 · 3 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost wp_targeted_link_rel_callback() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 28–33 | _deprecated_function(), wp_allowed_protocols(), wp_kses_hair(), apply_filters() |
| always | 47–53 | _deprecated_function(), wp_allowed_protocols(), wp_kses_hair(), apply_filters(), esc_attr(), array_column() |
isset($atts) | 64–70 | _deprecated_function(), wp_allowed_protocols(), wp_kses_hair(), apply_filters(), preg_split(), array_unique(), esc_attr(), array_column() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 74 | 28–70 | 5 | |
| 8.5 | 74 | 28–70 | 5 | |
| 8.4 | 74 | 28–70 | 5 | 15 fewer instructions than PHP 8.3 |
| 8.3 | 89 | 31–85 | 5 | |
| 8.2 | 89 | 31–85 | 5 | |
| 8.1 | 89 | 31–85 | 5 | |
| 7.4 | 89 | 31–85 | 5 |
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_targeted_link_rel_callback() runs, in this order:
- apply_filters( wp_targeted_link_rel )filterline 3380 (+23 into the body)
Filters the rel values that are added to links with `target` attribute.
Uses · 5
- _deprecated_function()Marks a function as deprecated and inform when it has been used.
- wp_kses_hair()Given a string of HTML attributes and values, parse into a structured attribute list.
- wp_allowed_protocols()Retrieves a list of protocols to allow in HTML attributes.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- esc_attr()Escaping for HTML attributes.
Source code
function wp_targeted_link_rel_callback( $matches ) { _deprecated_function( __FUNCTION__, '6.7.0' ); $link_html = $matches[1]; $original_link_html = $link_html; // Consider the HTML escaped if there are no unescaped quotes. $is_escaped = ! preg_match( '/(^|[^\\\\])[\'"]/', $link_html ); if ( $is_escaped ) { // Replace only the quotes so that they are parsable by wp_kses_hair(), leave the rest as is. $link_html = preg_replace( '/\\\\([\'"])/', '$1', $link_html ); } $atts = wp_kses_hair( $link_html, wp_allowed_protocols() ); /** * Filters the rel values that are added to links with `target` attribute. * * @since 5.1.0 * * @param string $rel The rel values. * @param string $link_html The matched content of the link tag including all HTML attributes. */ $rel = apply_filters( 'wp_targeted_link_rel', 'noopener', $link_html ); // Return early if no rel values to be added or if no actual target attribute. if ( ! $rel || ! isset( $atts['target'] ) ) { return "<a $original_link_html>"; } if ( isset( $atts['rel'] ) ) { $all_parts = preg_split( '/\s/', "{$atts['rel']['value']} $rel", -1, PREG_SPLIT_NO_EMPTY ); $rel = implode( ' ', array_unique( $all_parts ) ); } $atts['rel']['whole'] = 'rel="' . esc_attr( $rel ) . '"'; $link_html = implode( ' ', array_column( $atts, 'whole' ) ); if ( $is_escaped ) { $link_html = preg_replace( '/[\'"]/', '\\\\$0', $link_html ); } return "<a $link_html>";}Changelog
Introduced in 5.1.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.0.4 tag, from
src/wp-includes/formatting.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.