wppaste
WordPress

_make_clickable_rel_attr( string $url ): string

Since
6.2.0
Source
wp-includes/formatting.php:3104
Helper function used to build the "rel" attribute for a URL when creating an anchor using make_clickable().

Compatibility

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

$urlstring
The URL.

Return value

string
The rel attribute for the anchor or an empty string if no rel attribute should be added.

Performance profile

How much work a call to _make_clickable_rel_attr() 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
36–47

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

Plugin surface
1 hook

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

Called by
2

2 places 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 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 · 2 distinct outcomes

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

WhenInstructionsCalls it makes
!$rel_parts36–42wp_parse_url(), strtolower(), wp_allowed_protocols(), array_intersect(), wp_is_internal_link(), current_filter(), apply_filters()
$rel_parts41–47wp_parse_url(), strtolower(), wp_allowed_protocols(), array_intersect(), wp_is_internal_link(), current_filter(), apply_filters(), esc_attr()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev4836–474
8.54836–474
8.44836–4747 fewer instructions than PHP 8.3
8.35540–544
8.25540–544
8.15540–5441 fewer instruction than PHP 7.4
7.45640–554

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 _make_clickable_rel_attr() runs, in this order:

  1. apply_filters( make_clickable_rel )filterline 3129 (+25 into the body)

    Filters the rel value that is added to URL matches converted to links.

Uses · 6

  • wp_parse_url()A wrapper for PHP's parse_url() function that handles consistency in the return values across PHP versions.
  • wp_allowed_protocols()Retrieves a list of protocols to allow in HTML attributes.
  • wp_is_internal_link()Determines whether or not the specified URL is of a host included in the internal hosts list.
  • current_filter()Retrieves the name of the current filter hook.
  • apply_filters()Calls the callback functions that have been added to a filter hook.
  • esc_attr()Escaping for HTML attributes.

Used by · 2

Source code

function _make_clickable_rel_attr( $url ) {	$rel_parts        = array();	$scheme           = strtolower( wp_parse_url( $url, PHP_URL_SCHEME ) );	$nofollow_schemes = array_intersect( wp_allowed_protocols(), array( 'https', 'http' ) ); 	// Apply "nofollow" to external links with qualifying URL schemes (mailto:, tel:, etc... shouldn't be followed).	if ( ! wp_is_internal_link( $url ) && in_array( $scheme, $nofollow_schemes, true ) ) {		$rel_parts[] = 'nofollow';	} 	// Apply "ugc" when in comment context.	if ( 'comment_text' === current_filter() ) {		$rel_parts[] = 'ugc';	} 	$rel = implode( ' ', $rel_parts ); 	/**	 * Filters the rel value that is added to URL matches converted to links.	 *	 * @since 5.3.0	 *	 * @param string $rel The rel value.	 * @param string $url The matched URL being converted to a link tag.	 */	$rel = apply_filters( 'make_clickable_rel', $rel, $url ); 	$rel_attr = $rel ? ' rel="' . esc_attr( $rel ) . '"' : ''; 	return $rel_attr;}

Changelog

Introduced in 6.2.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 7.1.0 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.