wppaste
WordPress

pingback( string $content, int|WP_Post $post ): array<string,

Since
0.71, 4.7.0, 6.8.0
Source
wp-includes/comment.php:3176
Pings back the links found in a post.

Compatibility

WordPress
since 6.8.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

$contentstring
Post content to check for links. If empty will retrieve from post.
$postint|WP_Post
Post ID or object.

Return value

array<string,
bool> An array of pingback statuses indexed by link.

Performance profile

How much work a call to pingback() 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_head().

Scaling
Scales with input

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

Instructions
19–52

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

Plugin surface
2 hooks

Third-party callbacks on 'pre_ping', 'pingback_useragent' 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 callbacksdo_action_ref_array()called directly
  • optionoption read or writeget_option()one call below pingback()
  • httpoutbound HTTP requestwp_safe_remote_head()one call below pingback()

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 · 2 distinct outcomes

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

WhenInstructionsCalls it makes
always19get_post()
always48–52get_post(), get_pung(), wp_extract_urls(), array_unique()

Across PHP versions

PHPCompiledExecutedBranchesNotes
8.6-dev14619–5218
8.514619–5218
8.414619–52183 fewer instructions than PHP 8.3
8.314919–5218
8.214919–5218
8.114919–5218
7.414919–5218

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 · 2

2 hooks fire while pingback() runs, in this order:

  1. do_action( pre_ping )actionline 3240 (+64 into the body)

    Fires just before pinging back links found in a post.

  2. apply_filters( pingback_useragent )filterline 3269 (+93 into the body)

    Filters the user agent sent when pinging-back a URL.

Uses · 12

Used by · 1

Source code

function pingback( $content, $post ) {	require_once ABSPATH . WPINC . '/class-IXR.php';	require_once ABSPATH . WPINC . '/class-wp-http-ixr-client.php'; 	// Original code by Mort (http://mort.mine.nu:8080).	$post_links = array(); 	$post = get_post( $post ); 	if ( ! $post ) {		return array();	} 	$pung = get_pung( $post ); 	if ( empty( $content ) ) {		$content = $post->post_content;	} 	/*	 * Step 1.	 * Parsing the post, external links (if any) are stored in the $post_links array.	 */	$post_links_temp = wp_extract_urls( $content ); 	$ping_status = array();	/*	 * Step 2.	 * Walking through the links array.	 * First we get rid of links pointing to sites, not to specific files.	 * Example:	 * http://dummy-weblog.org	 * http://dummy-weblog.org/	 * http://dummy-weblog.org/post.php	 * We don't wanna ping first and second types, even if they have a valid <link/>.	 */	foreach ( (array) $post_links_temp as $link_test ) {		// If we haven't pung it already and it isn't a link to itself.		if ( ! in_array( $link_test, $pung, true ) && ( url_to_postid( $link_test ) !== $post->ID )			// Also, let's never ping local attachments.			&& ! is_local_attachment( $link_test )		) {			$test = parse_url( $link_test );			if ( $test ) {				if ( isset( $test['query'] ) ) {					$post_links[] = $link_test;				} elseif ( isset( $test['path'] ) && ( '/' !== $test['path'] ) && ( '' !== $test['path'] ) ) {					$post_links[] = $link_test;				}			}		}	} 	$post_links = array_unique( $post_links ); 	/**	 * Fires just before pinging back links found in a post.	 *	 * @since 2.0.0	 *	 * @param string[] $post_links Array of link URLs to be checked (passed by reference).	 * @param string[] $pung       Array of link URLs already pinged (passed by reference).	 * @param int      $post_id    The post ID.	 */	do_action_ref_array( 'pre_ping', array( &$post_links, &$pung, $post->ID ) ); 	foreach ( (array) $post_links as $pagelinkedto ) {		$pingback_server_url = discover_pingback_server_uri( $pagelinkedto ); 		if ( $pingback_server_url ) {			// Allow an additional 60 seconds for each pingback to complete.			if ( function_exists( 'set_time_limit' ) ) {				set_time_limit( 60 );			} 			// Now, the RPC call.			$pagelinkedfrom = get_permalink( $post ); 			// Using a timeout of 3 seconds should be enough to cover slow servers.			$client          = new WP_HTTP_IXR_Client( $pingback_server_url );

Changelog

Introduced in 0.71. One change between 6.7.7 and 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.

6.8.8
Return type changed from none to array<string,.verified against source
6.8.0
Returns an array of pingback statuses indexed by link.from the docblock
4.7.0
$post can be a WP_Post object.from the docblock
0.71
Introduced.from the docblock

About this page

Parsed data
Generated from the wordpress-develop 7.0.4 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.