_make_url_clickable_cb

函式
_make_url_clickable_cb ( $matches )
Access
Private
引數
  • (array) $matches Single Regex Match.
    Required:
返回值
  • (string) HTML A element with URI address.
定義位置
相關方法
_make_email_clickable_cb_make_web_ftp_clickable_cbmake_clickableget_user_localemake_url_footnote
引入
2.3.2
棄用
-

_make_url_clickable_cb: 此函式用於將文章內容中的URL轉換為可點選的連結。

回撥,將URI匹配轉換為HTML A元素。

該函式已從2.5.0回傳到2.3.2。make_clickable()的Regex回撥。

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
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];
}
if ( 'comment_text' === current_filter() ) {
$rel = 'nofollow ugc';
} else {
$rel = 'nofollow';
}
/**
* 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 = esc_attr( $rel );
return $matches[1] . "<a href="$url" rel="$rel">$url</a>" . $suffix;
}
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]; } if ( 'comment_text' === current_filter() ) { $rel = 'nofollow ugc'; } else { $rel = 'nofollow'; } /** * 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 = esc_attr( $rel ); return $matches[1] . "<a href="$url" rel="$rel">$url</a>" . $suffix; }
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];
	}

	if ( 'comment_text' === current_filter() ) {
		$rel = 'nofollow ugc';
	} else {
		$rel = 'nofollow';
	}

	/**
	 * 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 = esc_attr( $rel );

	return $matches[1] . "<a href="$url" rel="$rel">$url</a>" . $suffix;
}

常見問題

FAQs
檢視更多 >