do_trackbacks

Advertisement

Summery Summery

Perform trackbacks.

Syntax Syntax

do_trackbacks( int|WP_Post $post_id )

Parameters Parameters

$post_id

(int|WP_Post) (Required) Post object or ID to do trackbacks on.

Source Source

File: wp-includes/comment.php

	$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 ) ) {

Advertisement

Changelog Changelog

Changelog
Version Description
4.7.0 $post_id can be a WP_Post object.
1.5.0 Introduced.

Advertisement

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.