wppaste
WordPress

do_trackbacks( int|WP_Post $post ): void|false

Since
1.5.0, 4.7.0
Source
wp-includes/comment.php:3025
Performs trackbacks.

Compatibility

WordPress
since 4.7.0
PHP
7.4–8.6-dev
  • 6.7.7
  • 6.8.8
  • 6.9.7
  • 7.0.4
  • 7.1.0

Present in every tracked release (6.7.7 to 7.1.0), and compiles on PHP 7.4 through 8.6-dev.

Parameters

$postint|WP_Post
Post ID or object to do trackbacks on.

Return value

void|false
Returns false on failure.

Performance profile

How much work a call to do_trackbacks() does, and what it touches: the algorithmic scaling, the Zend instruction count per call across PHP versions, the hooks it hands control to, and the core code that calls it. Measured from the compiled opcodes, not a stopwatch, so every number is identical on any machine running the same PHP version, and every function in core is ranked by cost.

Cost class
Expensive

Reaches an outbound HTTP request via wp_safe_remote_post().

Scaling
Scales with input

The body loops, so the work grows with what you pass in.

Instructions
8–59

Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 108.

Plugin surface
3 hooks

Third-party callbacks on 'the_content', 'the_excerpt', 'the_title' run inside this call, and their cost is not bounded by anything here.

Called by
1

1 place in core call this, so the cost is paid more often than your own code shows.

What it touches

  • querycontent queryget_post()called directly
  • hookthird-party callbacksapply_filters()called directly
  • optionoption read or writeget_option()one call below do_trackbacks()
  • httpoutbound HTTP requestwp_safe_remote_post()one call below do_trackbacks()

Further down the call graph this can also reach cache, serialize and transient. Those are the worst case, several calls deep and usually down an error path, not what a normal call pays.

What one call costs · 3 distinct outcomes

One number would be a lie: the work depends on which branch runs. These are every distinct cost do_trackbacks() can have, taken from its control-flow graph on PHP 8.5.

WhenInstructionsCalls it makes
always8get_post()
empty($to_ping)27get_post(), get_to_ping(), get_pung(), ID()
!empty($to_ping)51–59get_post(), get_to_ping(), get_pung(), apply_filters(), wp_html_excerpt(), apply_filters(), strip_tags()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev1088–597
8.51088–597
8.41088–5978 fewer instructions than PHP 8.3
8.31168–627
8.21168–627
8.11168–627
7.41168–627

An instruction is not a fixed amount of time, so a matching count is not necessarily the same speed; what it rules out is a difference in the work itself.

Hooks and filters fired · 3

3 hooks fire while do_trackbacks() runs, in this order:

  1. apply_filters( the_content )filterline 3044 (+19 into the body)

    Filters the post content.

  2. apply_filters( the_excerpt )filterline 3047 (+22 into the body)

    Filters the displayed post excerpt.

  3. apply_filters( the_title )filterline 3054 (+29 into the body)

    Filters the post title.

Uses · 6

Used by · 1

Source code

function do_trackbacks( $post ) {	global $wpdb; 	$post = get_post( $post ); 	if ( ! $post ) {		return false;	} 	$to_ping = get_to_ping( $post );	$pinged  = get_pung( $post ); 	if ( empty( $to_ping ) ) {		$wpdb->update( $wpdb->posts, array( 'to_ping' => '' ), array( 'ID' => $post->ID ) );		return;	} 	if ( empty( $post->post_excerpt ) ) {		/** This filter is documented in wp-includes/post-template.php */		$excerpt = apply_filters( 'the_content', $post->post_content, $post->ID );	} else {		/** This filter is documented in wp-includes/post-template.php */		$excerpt = apply_filters( 'the_excerpt', $post->post_excerpt );	} 	$excerpt = str_replace( ']]>', ']]>', $excerpt );	$excerpt = wp_html_excerpt( $excerpt, 252, '…' ); 	/** This filter is documented in wp-includes/post-template.php */	$post_title = apply_filters( 'the_title', $post->post_title, $post->ID );	$post_title = strip_tags( $post_title ); 	if ( $to_ping ) {		foreach ( (array) $to_ping as $tb_ping ) {			$tb_ping = trim( $tb_ping );			if ( ! in_array( $tb_ping, $pinged, true ) ) {				trackback( $tb_ping, $post_title, $excerpt, $post->ID );				$pinged[] = $tb_ping;			} else {				$wpdb->query(					$wpdb->prepare(						"UPDATE $wpdb->posts SET to_ping = TRIM(REPLACE(to_ping, %s,					'')) WHERE ID = %d",						$tb_ping,						$post->ID					)				);			}		}	}}

Changelog

Introduced in 1.5.0. Unchanged from 6.7.7 through 7.1.0.

  1. 6.7.7
  2. 6.8.8
  3. 6.9.7
  4. 7.0.4
  5. 7.1.0

Signature, return type and hooks compared across 5 parsed releases.

4.7.0
$post can be a WP_Post object.from the docblock
1.5.0
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 6.8.8 tag, from src/wp-includes/comment.php, and regenerated for each WordPress release so it tracks the code rather than a snapshot of it.
Corrections
Something wrong on this page? Report it and it gets fixed in the next regeneration.