回调将URI匹配转换为HTML A元素。

原型

_make_url_clickable_cb( array $matches )

描述

此功能从2.5.0反向移植到2.3.2。 make_clickable()的正则表达式回调。

参数

$matches (array) (Required) 单一正则表达式匹配。

返回值

(string)  HTML具有URI地址的元素。

源文件

路径:wp-includes/formatting.php

<?php
...
function _make_url_clickable_cb( $matches ) {
	$url = $matches[2];
	if ( ')' == $matches[3] && strpos( $url, '(' ) ) {
		// If the trailing character is a closing parethesis, and the URL has an opening parenthesis in it, add the closing parenthesis to the URL.
		// Then we can let the parenthesis balancer do its thing below.
		$url .= $matches[3];
		$suffix = '';
	} else {
		$suffix = $matches[3];
	}
	// Include parentheses in the URL only if paired
	while ( substr_count( $url, '(' ) < substr_count( $url, ')' ) ) {
		$suffix = strrchr( $url, ')' ) . $suffix;
		$url = substr( $url, 0, strrpos( $url, ')' ) );
	}
	$url = esc_url($url);
	if ( empty($url) )
		return $matches[0];
	return $matches[1] . "<a href="$url" rel="nofollow">$url</a>" . $suffix;
}
...
?>

其他

英文文档:https://developer.wordpress.org/reference/functions/_make_url_clickable_cb/