_make_url_clickable_cb

The timeline below displays how wordpress function _make_url_clickable_cb has changed across different WordPress versions. If a version is not listed, refer to the next available version below.

WordPress Version: 6.3

/**
 * Callback to convert URI match to HTML A element.
 *
 * This function was backported from 2.5.0 to 2.3.2. Regex callback for make_clickable().
 *
 * @since 2.3.2
 * @access private
 *
 * @param array $matches Single Regex Match.
 * @return string HTML A element with URI address.
 */
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];
    }
    $rel_attr = _make_clickable_rel_attr($url);
    return $matches[1] . "<a href=\"{$url}\"{$rel_attr}>{$url}</a>" . $suffix;
}

WordPress Version: 6.2

/**
 * Callback to convert URI match to HTML A element.
 *
 * This function was backported from 2.5.0 to 2.3.2. Regex callback for make_clickable().
 *
 * @since 2.3.2
 * @access private
 *
 * @param array $matches Single Regex Match.
 * @return string HTML A element with URI address.
 */
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];
    }
    $rel_attr = _make_clickable_rel_attr($url);
    return $matches[1] . "<a href=\"{$url}\"{$rel_attr}>{$url}</a>" . $suffix;
}

WordPress Version: 5.5

/**
 * Callback to convert URI match to HTML A element.
 *
 * This function was backported from 2.5.0 to 2.3.2. Regex callback for make_clickable().
 *
 * @since 2.3.2
 * @access private
 *
 * @param array $matches Single Regex Match.
 * @return string HTML A element with URI address.
 */
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;
}

WordPress Version: 5.4

/**
 * Callback to convert URI match to HTML A element.
 *
 * This function was backported from 2.5.0 to 2.3.2. Regex callback for make_clickable().
 *
 * @since 2.3.2
 * @access private
 *
 * @param array $matches Single Regex Match.
 * @return string HTML A element with URI address.
 */
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;
}

WordPress Version: 5.3

/**
 * Callback to convert URI match to HTML A element.
 *
 * This function was backported from 2.5.0 to 2.3.2. Regex callback for make_clickable().
 *
 * @since 2.3.2
 * @access private
 *
 * @param array $matches Single Regex Match.
 * @return string HTML A element with URI address.
 */
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;
}

WordPress Version: 4.6

/**
 * Callback to convert URI match to HTML A element.
 *
 * This function was backported from 2.5.0 to 2.3.2. Regex callback for make_clickable().
 *
 * @since 2.3.2
 * @access private
 *
 * @param array $matches Single Regex Match.
 * @return string HTML A element with URI address.
 */
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;
}

WordPress Version: 3.7

/**
 * Callback to convert URI match to HTML A element.
 *
 * This function was backported from 2.5.0 to 2.3.2. Regex callback for {@link
 * make_clickable()}.
 *
 * @since 2.3.2
 * @access private
 *
 * @param array $matches Single Regex Match.
 * @return string HTML A element with URI address.
 */
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;
}