pingback( string $content, int|WP_Post $post ): array<string,
- Since
- 0.71, 4.7.0, 6.8.0
- Source
wp-includes/comment.php:3173
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
- Scaling
- Scales with input
- Instructions
- 19–52
- Plugin surface
- 2 hooks
- Called by
- 1
Reaches an outbound HTTP request via wp_safe_remote_head().
The body loops, so the work grows with what you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 146.
Third-party callbacks on 'pre_ping', 'pingback_useragent' run inside this call, and their cost is not bounded by anything here.
1 place in core call this, so the cost is paid more often than your own code shows.
What it touches
- querycontent query
get_post()called directly - hookthird-party callbacks
do_action_ref_array()called directly - optionoption read or write
get_option()one call below pingback() - httpoutbound HTTP request
wp_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.
| When | Instructions | Calls it makes |
|---|---|---|
| always | 19 | get_post() |
| always | 48–52 | get_post(), get_pung(), wp_extract_urls(), array_unique() |
Across PHP versions
| PHP | Compiled | Executed | Branches | Notes |
|---|---|---|---|---|
| 8.6-dev | 146 | 19–52 | 18 | |
| 8.5 | 146 | 19–52 | 18 | |
| 8.4 | 146 | 19–52 | 18 | 3 fewer instructions than PHP 8.3 |
| 8.3 | 149 | 19–52 | 18 | |
| 8.2 | 149 | 19–52 | 18 | |
| 8.1 | 149 | 19–52 | 18 | |
| 7.4 | 149 | 19–52 | 18 |
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:
- do_action( pre_ping )actionline 3237 (+64 into the body)
Fires just before pinging back links found in a post.
- apply_filters( pingback_useragent )filterline 3266 (+93 into the body)
Filters the user agent sent when pinging-back a URL.
Uses · 12
- get_post()Retrieves post data given a post ID or post object.
- get_pung()Retrieves URLs already pinged for a post.
- wp_extract_urls()Uses RegEx to extract URLs from arbitrary content.
- url_to_postid()Examines a URL and try to determine the post ID it represents.
- is_local_attachment()Determines whether an attachment URI is local and really an attachment.
- do_action_ref_array()Calls the callback functions that have been added to an action hook, specifying arguments in an array.
- discover_pingback_server_uri()Finds a pingback server URI based on the given URL.
- get_permalink()Retrieves the full permalink for the current post or post ID.
- apply_filters()Calls the callback functions that have been added to a filter hook.
- get_bloginfo()Retrieves information about the current site.
- add_ping()Adds a URL to those already pinged.
- WP_HTTP_IXR_Client::__construct()
Used by · 1
- do_all_pingbacks()Performs all pingbacks.
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.
Signature, return type and hooks compared across 5 parsed releases.
none to array<string,.verified against source$post can be a WP_Post object.from the docblockAbout this page
- Parsed data
- Generated from the wordpress-develop 6.9.7 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.