discover_pingback_server_uri( string $url, string $deprecated = '' ): string|false

In this article

Finds a pingback server URI based on the given URL.

Description

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.

Parameters

$urlstringrequired
URL to ping.
$deprecatedstringoptional
Not Used.

Default:''

Return

string|false String containing URI on success, false on failure.

Source

	 * @param int $post_id Post ID.
	 * @param int $new     The new comment count.
	 * @param int $old     The old comment count.
	 */
	do_action( 'wp_update_comment_count', $post_id, $new, $old );

	/** This action is documented in wp-includes/post.php */
	do_action( "edit_post_{$post->post_type}", $post_id, $post );

	/** This action is documented in wp-includes/post.php */
	do_action( 'edit_post', $post_id, $post );

	return true;
}

//
// 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(

Changelog

VersionDescription
1.5.0Introduced.

User Contributed Notes

You must log in before being able to contribute a note or feedback.