discover_pingback_server_uri

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

WordPress Version: 6.3

//
// Ping and trackback functions.
//
/**
 * Finds a pingback server URI based on the given URL.
 *
 * Checks the HTML for the rel="pingback" link and X-Pingback headers. It does
 * a check for the X-Pingback headers first and returns that, if available.
 * The check for the rel="pingback" has more overhead than just the header.
 *
 * @since 1.5.0
 *
 * @param string $url        URL to ping.
 * @param string $deprecated Not Used.
 * @return string|false String containing URI on success, false on failure.
 */
function discover_pingback_server_uri($url, $deprecated = '')
{
    if (!empty($deprecated)) {
        _deprecated_argument(__FUNCTION__, '2.7.0');
    }
    $pingback_str_dquote = 'rel="pingback"';
    $pingback_str_squote = 'rel=\'pingback\'';
    /** @todo Should use Filter Extension or custom preg_match instead. */
    $parsed_url = parse_url($url);
    if (!isset($parsed_url['host'])) {
        // Not a URL. This should never happen.
        return false;
    }
    // Do not search for a pingback server on our own uploads.
    $uploads_dir = wp_get_upload_dir();
    if (str_starts_with($url, $uploads_dir['baseurl'])) {
        return false;
    }
    $response = wp_safe_remote_head($url, array('timeout' => 2, 'httpversion' => '1.0'));
    if (is_wp_error($response)) {
        return false;
    }
    if (wp_remote_retrieve_header($response, 'X-Pingback')) {
        return wp_remote_retrieve_header($response, 'X-Pingback');
    }
    // Not an (x)html, sgml, or xml page, no use going further.
    if (preg_match('#(image|audio|video|model)/#is', wp_remote_retrieve_header($response, 'Content-Type'))) {
        return false;
    }
    // Now do a GET since we're going to look in the HTML headers (and we're sure it's not a binary file).
    $response = wp_safe_remote_get($url, array('timeout' => 2, 'httpversion' => '1.0'));
    if (is_wp_error($response)) {
        return false;
    }
    $contents = wp_remote_retrieve_body($response);
    $pingback_link_offset_dquote = strpos($contents, $pingback_str_dquote);
    $pingback_link_offset_squote = strpos($contents, $pingback_str_squote);
    if ($pingback_link_offset_dquote || $pingback_link_offset_squote) {
        $quote = $pingback_link_offset_dquote ? '"' : '\'';
        $pingback_link_offset = ('"' === $quote) ? $pingback_link_offset_dquote : $pingback_link_offset_squote;
        $pingback_href_pos = strpos($contents, 'href=', $pingback_link_offset);
        $pingback_href_start = $pingback_href_pos + 6;
        $pingback_href_end = strpos($contents, $quote, $pingback_href_start);
        $pingback_server_url_len = $pingback_href_end - $pingback_href_start;
        $pingback_server_url = substr($contents, $pingback_href_start, $pingback_server_url_len);
        // We may find rel="pingback" but an incomplete pingback URL.
        if ($pingback_server_url_len > 0) {
            // We got it!
            return $pingback_server_url;
        }
    }
    return false;
}

WordPress Version: 6.2

//
// Ping and trackback functions.
//
/**
 * Finds a pingback server URI based on the given URL.
 *
 * Checks the HTML for the rel="pingback" link and X-Pingback headers. It does
 * a check for the X-Pingback headers first and returns that, if available.
 * The check for the rel="pingback" has more overhead than just the header.
 *
 * @since 1.5.0
 *
 * @param string $url        URL to ping.
 * @param string $deprecated Not Used.
 * @return string|false String containing URI on success, false on failure.
 */
function discover_pingback_server_uri($url, $deprecated = '')
{
    if (!empty($deprecated)) {
        _deprecated_argument(__FUNCTION__, '2.7.0');
    }
    $pingback_str_dquote = 'rel="pingback"';
    $pingback_str_squote = 'rel=\'pingback\'';
    /** @todo Should use Filter Extension or custom preg_match instead. */
    $parsed_url = parse_url($url);
    if (!isset($parsed_url['host'])) {
        // Not a URL. This should never happen.
        return false;
    }
    // Do not search for a pingback server on our own uploads.
    $uploads_dir = wp_get_upload_dir();
    if (0 === strpos($url, $uploads_dir['baseurl'])) {
        return false;
    }
    $response = wp_safe_remote_head($url, array('timeout' => 2, 'httpversion' => '1.0'));
    if (is_wp_error($response)) {
        return false;
    }
    if (wp_remote_retrieve_header($response, 'X-Pingback')) {
        return wp_remote_retrieve_header($response, 'X-Pingback');
    }
    // Not an (x)html, sgml, or xml page, no use going further.
    if (preg_match('#(image|audio|video|model)/#is', wp_remote_retrieve_header($response, 'Content-Type'))) {
        return false;
    }
    // Now do a GET since we're going to look in the HTML headers (and we're sure it's not a binary file).
    $response = wp_safe_remote_get($url, array('timeout' => 2, 'httpversion' => '1.0'));
    if (is_wp_error($response)) {
        return false;
    }
    $contents = wp_remote_retrieve_body($response);
    $pingback_link_offset_dquote = strpos($contents, $pingback_str_dquote);
    $pingback_link_offset_squote = strpos($contents, $pingback_str_squote);
    if ($pingback_link_offset_dquote || $pingback_link_offset_squote) {
        $quote = $pingback_link_offset_dquote ? '"' : '\'';
        $pingback_link_offset = ('"' === $quote) ? $pingback_link_offset_dquote : $pingback_link_offset_squote;
        $pingback_href_pos = strpos($contents, 'href=', $pingback_link_offset);
        $pingback_href_start = $pingback_href_pos + 6;
        $pingback_href_end = strpos($contents, $quote, $pingback_href_start);
        $pingback_server_url_len = $pingback_href_end - $pingback_href_start;
        $pingback_server_url = substr($contents, $pingback_href_start, $pingback_server_url_len);
        // We may find rel="pingback" but an incomplete pingback URL.
        if ($pingback_server_url_len > 0) {
            // We got it!
            return $pingback_server_url;
        }
    }
    return false;
}

WordPress Version: 5.7

//
// Ping and trackback functions.
//
/**
 * Finds a pingback server URI based on the given URL.
 *
 * Checks the HTML for the rel="pingback" link and x-pingback headers. It does
 * a check for the x-pingback headers first and returns that, if available. The
 * check for the rel="pingback" has more overhead than just the header.
 *
 * @since 1.5.0
 *
 * @param string $url        URL to ping.
 * @param string $deprecated Not Used.
 * @return string|false String containing URI on success, false on failure.
 */
function discover_pingback_server_uri($url, $deprecated = '')
{
    if (!empty($deprecated)) {
        _deprecated_argument(__FUNCTION__, '2.7.0');
    }
    $pingback_str_dquote = 'rel="pingback"';
    $pingback_str_squote = 'rel=\'pingback\'';
    /** @todo Should use Filter Extension or custom preg_match instead. */
    $parsed_url = parse_url($url);
    if (!isset($parsed_url['host'])) {
        // Not a URL. This should never happen.
        return false;
    }
    // Do not search for a pingback server on our own uploads.
    $uploads_dir = wp_get_upload_dir();
    if (0 === strpos($url, $uploads_dir['baseurl'])) {
        return false;
    }
    $response = wp_safe_remote_head($url, array('timeout' => 2, 'httpversion' => '1.0'));
    if (is_wp_error($response)) {
        return false;
    }
    if (wp_remote_retrieve_header($response, 'x-pingback')) {
        return wp_remote_retrieve_header($response, 'x-pingback');
    }
    // Not an (x)html, sgml, or xml page, no use going further.
    if (preg_match('#(image|audio|video|model)/#is', wp_remote_retrieve_header($response, 'content-type'))) {
        return false;
    }
    // Now do a GET since we're going to look in the HTML headers (and we're sure it's not a binary file).
    $response = wp_safe_remote_get($url, array('timeout' => 2, 'httpversion' => '1.0'));
    if (is_wp_error($response)) {
        return false;
    }
    $contents = wp_remote_retrieve_body($response);
    $pingback_link_offset_dquote = strpos($contents, $pingback_str_dquote);
    $pingback_link_offset_squote = strpos($contents, $pingback_str_squote);
    if ($pingback_link_offset_dquote || $pingback_link_offset_squote) {
        $quote = $pingback_link_offset_dquote ? '"' : '\'';
        $pingback_link_offset = ('"' === $quote) ? $pingback_link_offset_dquote : $pingback_link_offset_squote;
        $pingback_href_pos = strpos($contents, 'href=', $pingback_link_offset);
        $pingback_href_start = $pingback_href_pos + 6;
        $pingback_href_end = strpos($contents, $quote, $pingback_href_start);
        $pingback_server_url_len = $pingback_href_end - $pingback_href_start;
        $pingback_server_url = substr($contents, $pingback_href_start, $pingback_server_url_len);
        // We may find rel="pingback" but an incomplete pingback URL.
        if ($pingback_server_url_len > 0) {
            // We got it!
            return $pingback_server_url;
        }
    }
    return false;
}

WordPress Version: 5.5

//
// Ping and trackback functions.
//
/**
 * Finds a pingback server URI based on the given URL.
 *
 * Checks the HTML for the rel="pingback" link and x-pingback headers. It does
 * a check for the x-pingback headers first and returns that, if available. The
 * check for the rel="pingback" has more overhead than just the header.
 *
 * @since 1.5.0
 *
 * @param string $url        URL to ping.
 * @param int    $deprecated Not Used.
 * @return string|false String containing URI on success, false on failure.
 */
function discover_pingback_server_uri($url, $deprecated = '')
{
    if (!empty($deprecated)) {
        _deprecated_argument(__FUNCTION__, '2.7.0');
    }
    $pingback_str_dquote = 'rel="pingback"';
    $pingback_str_squote = 'rel=\'pingback\'';
    /** @todo Should use Filter Extension or custom preg_match instead. */
    $parsed_url = parse_url($url);
    if (!isset($parsed_url['host'])) {
        // Not a URL. This should never happen.
        return false;
    }
    // Do not search for a pingback server on our own uploads.
    $uploads_dir = wp_get_upload_dir();
    if (0 === strpos($url, $uploads_dir['baseurl'])) {
        return false;
    }
    $response = wp_safe_remote_head($url, array('timeout' => 2, 'httpversion' => '1.0'));
    if (is_wp_error($response)) {
        return false;
    }
    if (wp_remote_retrieve_header($response, 'x-pingback')) {
        return wp_remote_retrieve_header($response, 'x-pingback');
    }
    // Not an (x)html, sgml, or xml page, no use going further.
    if (preg_match('#(image|audio|video|model)/#is', wp_remote_retrieve_header($response, 'content-type'))) {
        return false;
    }
    // Now do a GET since we're going to look in the HTML headers (and we're sure it's not a binary file).
    $response = wp_safe_remote_get($url, array('timeout' => 2, 'httpversion' => '1.0'));
    if (is_wp_error($response)) {
        return false;
    }
    $contents = wp_remote_retrieve_body($response);
    $pingback_link_offset_dquote = strpos($contents, $pingback_str_dquote);
    $pingback_link_offset_squote = strpos($contents, $pingback_str_squote);
    if ($pingback_link_offset_dquote || $pingback_link_offset_squote) {
        $quote = $pingback_link_offset_dquote ? '"' : '\'';
        $pingback_link_offset = ('"' === $quote) ? $pingback_link_offset_dquote : $pingback_link_offset_squote;
        $pingback_href_pos = strpos($contents, 'href=', $pingback_link_offset);
        $pingback_href_start = $pingback_href_pos + 6;
        $pingback_href_end = strpos($contents, $quote, $pingback_href_start);
        $pingback_server_url_len = $pingback_href_end - $pingback_href_start;
        $pingback_server_url = substr($contents, $pingback_href_start, $pingback_server_url_len);
        // We may find rel="pingback" but an incomplete pingback URL.
        if ($pingback_server_url_len > 0) {
            // We got it!
            return $pingback_server_url;
        }
    }
    return false;
}

WordPress Version: 5.4

//
// Ping and trackback functions.
//
/**
 * Finds a pingback server URI based on the given URL.
 *
 * Checks the HTML for the rel="pingback" link and x-pingback headers. It does
 * a check for the x-pingback headers first and returns that, if available. The
 * check for the rel="pingback" has more overhead than just the header.
 *
 * @since 1.5.0
 *
 * @param string $url URL to ping.
 * @param int $deprecated Not Used.
 * @return string|false String containing URI on success, false on failure.
 */
function discover_pingback_server_uri($url, $deprecated = '')
{
    if (!empty($deprecated)) {
        _deprecated_argument(__FUNCTION__, '2.7.0');
    }
    $pingback_str_dquote = 'rel="pingback"';
    $pingback_str_squote = 'rel=\'pingback\'';
    /** @todo Should use Filter Extension or custom preg_match instead. */
    $parsed_url = parse_url($url);
    if (!isset($parsed_url['host'])) {
        // Not a URL. This should never happen.
        return false;
    }
    // Do not search for a pingback server on our own uploads.
    $uploads_dir = wp_get_upload_dir();
    if (0 === strpos($url, $uploads_dir['baseurl'])) {
        return false;
    }
    $response = wp_safe_remote_head($url, array('timeout' => 2, 'httpversion' => '1.0'));
    if (is_wp_error($response)) {
        return false;
    }
    if (wp_remote_retrieve_header($response, 'x-pingback')) {
        return wp_remote_retrieve_header($response, 'x-pingback');
    }
    // Not an (x)html, sgml, or xml page, no use going further.
    if (preg_match('#(image|audio|video|model)/#is', wp_remote_retrieve_header($response, 'content-type'))) {
        return false;
    }
    // Now do a GET since we're going to look in the html headers (and we're sure it's not a binary file).
    $response = wp_safe_remote_get($url, array('timeout' => 2, 'httpversion' => '1.0'));
    if (is_wp_error($response)) {
        return false;
    }
    $contents = wp_remote_retrieve_body($response);
    $pingback_link_offset_dquote = strpos($contents, $pingback_str_dquote);
    $pingback_link_offset_squote = strpos($contents, $pingback_str_squote);
    if ($pingback_link_offset_dquote || $pingback_link_offset_squote) {
        $quote = $pingback_link_offset_dquote ? '"' : '\'';
        $pingback_link_offset = ('"' === $quote) ? $pingback_link_offset_dquote : $pingback_link_offset_squote;
        $pingback_href_pos = strpos($contents, 'href=', $pingback_link_offset);
        $pingback_href_start = $pingback_href_pos + 6;
        $pingback_href_end = strpos($contents, $quote, $pingback_href_start);
        $pingback_server_url_len = $pingback_href_end - $pingback_href_start;
        $pingback_server_url = substr($contents, $pingback_href_start, $pingback_server_url_len);
        // We may find rel="pingback" but an incomplete pingback URL.
        if ($pingback_server_url_len > 0) {
            // We got it!
            return $pingback_server_url;
        }
    }
    return false;
}

WordPress Version: 5.3

//
// Ping and trackback functions.
//
/**
 * Finds a pingback server URI based on the given URL.
 *
 * Checks the HTML for the rel="pingback" link and x-pingback headers. It does
 * a check for the x-pingback headers first and returns that, if available. The
 * check for the rel="pingback" has more overhead than just the header.
 *
 * @since 1.5.0
 *
 * @param string $url URL to ping.
 * @param int $deprecated Not Used.
 * @return false|string False on failure, string containing URI on success.
 */
function discover_pingback_server_uri($url, $deprecated = '')
{
    if (!empty($deprecated)) {
        _deprecated_argument(__FUNCTION__, '2.7.0');
    }
    $pingback_str_dquote = 'rel="pingback"';
    $pingback_str_squote = 'rel=\'pingback\'';
    /** @todo Should use Filter Extension or custom preg_match instead. */
    $parsed_url = parse_url($url);
    if (!isset($parsed_url['host'])) {
        // Not a URL. This should never happen.
        return false;
    }
    //Do not search for a pingback server on our own uploads
    $uploads_dir = wp_get_upload_dir();
    if (0 === strpos($url, $uploads_dir['baseurl'])) {
        return false;
    }
    $response = wp_safe_remote_head($url, array('timeout' => 2, 'httpversion' => '1.0'));
    if (is_wp_error($response)) {
        return false;
    }
    if (wp_remote_retrieve_header($response, 'x-pingback')) {
        return wp_remote_retrieve_header($response, 'x-pingback');
    }
    // Not an (x)html, sgml, or xml page, no use going further.
    if (preg_match('#(image|audio|video|model)/#is', wp_remote_retrieve_header($response, 'content-type'))) {
        return false;
    }
    // Now do a GET since we're going to look in the html headers (and we're sure it's not a binary file)
    $response = wp_safe_remote_get($url, array('timeout' => 2, 'httpversion' => '1.0'));
    if (is_wp_error($response)) {
        return false;
    }
    $contents = wp_remote_retrieve_body($response);
    $pingback_link_offset_dquote = strpos($contents, $pingback_str_dquote);
    $pingback_link_offset_squote = strpos($contents, $pingback_str_squote);
    if ($pingback_link_offset_dquote || $pingback_link_offset_squote) {
        $quote = $pingback_link_offset_dquote ? '"' : '\'';
        $pingback_link_offset = ($quote == '"') ? $pingback_link_offset_dquote : $pingback_link_offset_squote;
        $pingback_href_pos = strpos($contents, 'href=', $pingback_link_offset);
        $pingback_href_start = $pingback_href_pos + 6;
        $pingback_href_end = strpos($contents, $quote, $pingback_href_start);
        $pingback_server_url_len = $pingback_href_end - $pingback_href_start;
        $pingback_server_url = substr($contents, $pingback_href_start, $pingback_server_url_len);
        // We may find rel="pingback" but an incomplete pingback URL
        if ($pingback_server_url_len > 0) {
            // We got it!
            return $pingback_server_url;
        }
    }
    return false;
}

WordPress Version: 4.6

//
// Ping and trackback functions.
//
/**
 * Finds a pingback server URI based on the given URL.
 *
 * Checks the HTML for the rel="pingback" link and x-pingback headers. It does
 * a check for the x-pingback headers first and returns that, if available. The
 * check for the rel="pingback" has more overhead than just the header.
 *
 * @since 1.5.0
 *
 * @param string $url URL to ping.
 * @param int $deprecated Not Used.
 * @return false|string False on failure, string containing URI on success.
 */
function discover_pingback_server_uri($url, $deprecated = '')
{
    if (!empty($deprecated)) {
        _deprecated_argument(__FUNCTION__, '2.7.0');
    }
    $pingback_str_dquote = 'rel="pingback"';
    $pingback_str_squote = 'rel=\'pingback\'';
    /** @todo Should use Filter Extension or custom preg_match instead. */
    $parsed_url = parse_url($url);
    if (!isset($parsed_url['host'])) {
        // Not a URL. This should never happen.
        return false;
    }
    //Do not search for a pingback server on our own uploads
    $uploads_dir = wp_get_upload_dir();
    if (0 === strpos($url, $uploads_dir['baseurl'])) {
        return false;
    }
    $response = wp_safe_remote_head($url, array('timeout' => 2, 'httpversion' => '1.0'));
    if (is_wp_error($response)) {
        return false;
    }
    if (wp_remote_retrieve_header($response, 'x-pingback')) {
        return wp_remote_retrieve_header($response, 'x-pingback');
    }
    // Not an (x)html, sgml, or xml page, no use going further.
    if (preg_match('#(image|audio|video|model)/#is', wp_remote_retrieve_header($response, 'content-type'))) {
        return false;
    }
    // Now do a GET since we're going to look in the html headers (and we're sure it's not a binary file)
    $response = wp_safe_remote_get($url, array('timeout' => 2, 'httpversion' => '1.0'));
    if (is_wp_error($response)) {
        return false;
    }
    $contents = wp_remote_retrieve_body($response);
    $pingback_link_offset_dquote = strpos($contents, $pingback_str_dquote);
    $pingback_link_offset_squote = strpos($contents, $pingback_str_squote);
    if ($pingback_link_offset_dquote || $pingback_link_offset_squote) {
        $quote = $pingback_link_offset_dquote ? '"' : '\'';
        $pingback_link_offset = ($quote == '"') ? $pingback_link_offset_dquote : $pingback_link_offset_squote;
        $pingback_href_pos = @strpos($contents, 'href=', $pingback_link_offset);
        $pingback_href_start = $pingback_href_pos + 6;
        $pingback_href_end = @strpos($contents, $quote, $pingback_href_start);
        $pingback_server_url_len = $pingback_href_end - $pingback_href_start;
        $pingback_server_url = substr($contents, $pingback_href_start, $pingback_server_url_len);
        // We may find rel="pingback" but an incomplete pingback URL
        if ($pingback_server_url_len > 0) {
            // We got it!
            return $pingback_server_url;
        }
    }
    return false;
}

WordPress Version: 4.5

//
// Ping and trackback functions.
//
/**
 * Finds a pingback server URI based on the given URL.
 *
 * Checks the HTML for the rel="pingback" link and x-pingback headers. It does
 * a check for the x-pingback headers first and returns that, if available. The
 * check for the rel="pingback" has more overhead than just the header.
 *
 * @since 1.5.0
 *
 * @param string $url URL to ping.
 * @param int $deprecated Not Used.
 * @return false|string False on failure, string containing URI on success.
 */
function discover_pingback_server_uri($url, $deprecated = '')
{
    if (!empty($deprecated)) {
        _deprecated_argument(__FUNCTION__, '2.7');
    }
    $pingback_str_dquote = 'rel="pingback"';
    $pingback_str_squote = 'rel=\'pingback\'';
    /** @todo Should use Filter Extension or custom preg_match instead. */
    $parsed_url = parse_url($url);
    if (!isset($parsed_url['host'])) {
        // Not a URL. This should never happen.
        return false;
    }
    //Do not search for a pingback server on our own uploads
    $uploads_dir = wp_get_upload_dir();
    if (0 === strpos($url, $uploads_dir['baseurl'])) {
        return false;
    }
    $response = wp_safe_remote_head($url, array('timeout' => 2, 'httpversion' => '1.0'));
    if (is_wp_error($response)) {
        return false;
    }
    if (wp_remote_retrieve_header($response, 'x-pingback')) {
        return wp_remote_retrieve_header($response, 'x-pingback');
    }
    // Not an (x)html, sgml, or xml page, no use going further.
    if (preg_match('#(image|audio|video|model)/#is', wp_remote_retrieve_header($response, 'content-type'))) {
        return false;
    }
    // Now do a GET since we're going to look in the html headers (and we're sure it's not a binary file)
    $response = wp_safe_remote_get($url, array('timeout' => 2, 'httpversion' => '1.0'));
    if (is_wp_error($response)) {
        return false;
    }
    $contents = wp_remote_retrieve_body($response);
    $pingback_link_offset_dquote = strpos($contents, $pingback_str_dquote);
    $pingback_link_offset_squote = strpos($contents, $pingback_str_squote);
    if ($pingback_link_offset_dquote || $pingback_link_offset_squote) {
        $quote = $pingback_link_offset_dquote ? '"' : '\'';
        $pingback_link_offset = ($quote == '"') ? $pingback_link_offset_dquote : $pingback_link_offset_squote;
        $pingback_href_pos = @strpos($contents, 'href=', $pingback_link_offset);
        $pingback_href_start = $pingback_href_pos + 6;
        $pingback_href_end = @strpos($contents, $quote, $pingback_href_start);
        $pingback_server_url_len = $pingback_href_end - $pingback_href_start;
        $pingback_server_url = substr($contents, $pingback_href_start, $pingback_server_url_len);
        // We may find rel="pingback" but an incomplete pingback URL
        if ($pingback_server_url_len > 0) {
            // We got it!
            return $pingback_server_url;
        }
    }
    return false;
}

WordPress Version: 4.1

//
// Ping and trackback functions.
//
/**
 * Finds a pingback server URI based on the given URL.
 *
 * Checks the HTML for the rel="pingback" link and x-pingback headers. It does
 * a check for the x-pingback headers first and returns that, if available. The
 * check for the rel="pingback" has more overhead than just the header.
 *
 * @since 1.5.0
 *
 * @param string $url URL to ping.
 * @param int $deprecated Not Used.
 * @return false|string False on failure, string containing URI on success.
 */
function discover_pingback_server_uri($url, $deprecated = '')
{
    if (!empty($deprecated)) {
        _deprecated_argument(__FUNCTION__, '2.7');
    }
    $pingback_str_dquote = 'rel="pingback"';
    $pingback_str_squote = 'rel=\'pingback\'';
    /** @todo Should use Filter Extension or custom preg_match instead. */
    $parsed_url = parse_url($url);
    if (!isset($parsed_url['host'])) {
        // Not an URL. This should never happen.
        return false;
    }
    //Do not search for a pingback server on our own uploads
    $uploads_dir = wp_upload_dir();
    if (0 === strpos($url, $uploads_dir['baseurl'])) {
        return false;
    }
    $response = wp_safe_remote_head($url, array('timeout' => 2, 'httpversion' => '1.0'));
    if (is_wp_error($response)) {
        return false;
    }
    if (wp_remote_retrieve_header($response, 'x-pingback')) {
        return wp_remote_retrieve_header($response, 'x-pingback');
    }
    // Not an (x)html, sgml, or xml page, no use going further.
    if (preg_match('#(image|audio|video|model)/#is', wp_remote_retrieve_header($response, 'content-type'))) {
        return false;
    }
    // Now do a GET since we're going to look in the html headers (and we're sure it's not a binary file)
    $response = wp_safe_remote_get($url, array('timeout' => 2, 'httpversion' => '1.0'));
    if (is_wp_error($response)) {
        return false;
    }
    $contents = wp_remote_retrieve_body($response);
    $pingback_link_offset_dquote = strpos($contents, $pingback_str_dquote);
    $pingback_link_offset_squote = strpos($contents, $pingback_str_squote);
    if ($pingback_link_offset_dquote || $pingback_link_offset_squote) {
        $quote = $pingback_link_offset_dquote ? '"' : '\'';
        $pingback_link_offset = ($quote == '"') ? $pingback_link_offset_dquote : $pingback_link_offset_squote;
        $pingback_href_pos = @strpos($contents, 'href=', $pingback_link_offset);
        $pingback_href_start = $pingback_href_pos + 6;
        $pingback_href_end = @strpos($contents, $quote, $pingback_href_start);
        $pingback_server_url_len = $pingback_href_end - $pingback_href_start;
        $pingback_server_url = substr($contents, $pingback_href_start, $pingback_server_url_len);
        // We may find rel="pingback" but an incomplete pingback URL
        if ($pingback_server_url_len > 0) {
            // We got it!
            return $pingback_server_url;
        }
    }
    return false;
}

WordPress Version: 3.7

//
// Ping and trackback functions.
//
/**
 * Finds a pingback server URI based on the given URL.
 *
 * Checks the HTML for the rel="pingback" link and x-pingback headers. It does
 * a check for the x-pingback headers first and returns that, if available. The
 * check for the rel="pingback" has more overhead than just the header.
 *
 * @since 1.5.0
 *
 * @param string $url URL to ping.
 * @param int $deprecated Not Used.
 * @return bool|string False on failure, string containing URI on success.
 */
function discover_pingback_server_uri($url, $deprecated = '')
{
    if (!empty($deprecated)) {
        _deprecated_argument(__FUNCTION__, '2.7');
    }
    $pingback_str_dquote = 'rel="pingback"';
    $pingback_str_squote = 'rel=\'pingback\'';
    /** @todo Should use Filter Extension or custom preg_match instead. */
    $parsed_url = parse_url($url);
    if (!isset($parsed_url['host'])) {
        // Not an URL. This should never happen.
        return false;
    }
    //Do not search for a pingback server on our own uploads
    $uploads_dir = wp_upload_dir();
    if (0 === strpos($url, $uploads_dir['baseurl'])) {
        return false;
    }
    $response = wp_safe_remote_head($url, array('timeout' => 2, 'httpversion' => '1.0'));
    if (is_wp_error($response)) {
        return false;
    }
    if (wp_remote_retrieve_header($response, 'x-pingback')) {
        return wp_remote_retrieve_header($response, 'x-pingback');
    }
    // Not an (x)html, sgml, or xml page, no use going further.
    if (preg_match('#(image|audio|video|model)/#is', wp_remote_retrieve_header($response, 'content-type'))) {
        return false;
    }
    // Now do a GET since we're going to look in the html headers (and we're sure it's not a binary file)
    $response = wp_safe_remote_get($url, array('timeout' => 2, 'httpversion' => '1.0'));
    if (is_wp_error($response)) {
        return false;
    }
    $contents = wp_remote_retrieve_body($response);
    $pingback_link_offset_dquote = strpos($contents, $pingback_str_dquote);
    $pingback_link_offset_squote = strpos($contents, $pingback_str_squote);
    if ($pingback_link_offset_dquote || $pingback_link_offset_squote) {
        $quote = $pingback_link_offset_dquote ? '"' : '\'';
        $pingback_link_offset = ($quote == '"') ? $pingback_link_offset_dquote : $pingback_link_offset_squote;
        $pingback_href_pos = @strpos($contents, 'href=', $pingback_link_offset);
        $pingback_href_start = $pingback_href_pos + 6;
        $pingback_href_end = @strpos($contents, $quote, $pingback_href_start);
        $pingback_server_url_len = $pingback_href_end - $pingback_href_start;
        $pingback_server_url = substr($contents, $pingback_href_start, $pingback_server_url_len);
        // We may find rel="pingback" but an incomplete pingback URL
        if ($pingback_server_url_len > 0) {
            // We got it!
            return $pingback_server_url;
        }
    }
    return false;
}