trackback( string $trackback_url, string $title, string $excerpt, int $ID ): int|false|void

Sends a Trackback.

Description

Updates database when sending trackback to prevent duplicates.

Parameters

$trackback_urlstringrequired
URL to send trackbacks.
$titlestringrequired
Title of post.
$excerptstringrequired
Excerpt of post.
$IDintrequired
Post ID.

Return

int|false|void Database query from update.

Source

function trackback( $trackback_url, $title, $excerpt, $ID ) {
	global $wpdb;

	if ( empty( $trackback_url ) ) {
		return;
	}

	$options            = array();
	$options['timeout'] = 10;
	$options['body']    = array(
		'title'     => $title,
		'url'       => get_permalink( $ID ),
		'blog_name' => get_option( 'blogname' ),
		'excerpt'   => $excerpt,
	);

	$response = wp_safe_remote_post( $trackback_url, $options );

	if ( is_wp_error( $response ) ) {
		return;
	}

	$wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET pinged = CONCAT(pinged, '\n', %s) WHERE ID = %d", $trackback_url, $ID ) );
	return $wpdb->query( $wpdb->prepare( "UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, %s, '')) WHERE ID = %d", $trackback_url, $ID ) );
}

Changelog

VersionDescription
0.71Introduced.

User Contributed Notes

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