_publish_post_hook( int $post_id )
- Since
- 2.3.0
- Source
wp-includes/post.php:8220
Description
Uses XMLRPC_REQUEST and WP_IMPORTING constants.
Compatibility
- WordPress
- since 2.3.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
$post_idint- The ID of the post being published.
Performance profile
How much work a call to _publish_post_hook() 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
- Heavy
- Scaling
- Constant
- Instructions
- 6–47
- Plugin surface
- 1 hook
- Called by
- 0
Reaches the database via get_post().
No loop in the body: the same number of instructions runs whatever you pass in.
Executed per call on PHP 8.5, depending on the branch taken. The body compiles to 48.
Third-party callbacks on 'xmlrpc_publish_post' run inside this call, and their cost is not bounded by anything here.
Nothing in core calls this; the cost is only what you spend yourself.
What it touches
- hookthird-party callbacks
do_action()called directly - optionoption read or write
get_option()called directly - cacheobject cache
wp_cache_get()one call below _publish_post_hook() - serializeserialisation
maybe_unserialize()one call below _publish_post_hook() - querycontent query
get_post()one call below _publish_post_hook()
Further down the call graph this can also reach transient. That is the worst case, several calls deep and usually down an error path, not what a normal call pays.
What one call costs · 18 distinct outcomes
One number would be a lie: the work depends on which branch runs. These are every distinct cost _publish_post_hook() can have, taken from its control-flow graph on PHP 8.5.
| When | Instructions | Calls it makes |
|---|---|---|
!defined('XMLRPC_REQUEST') && defined('WP_IMPORTING') | 6 | none |
defined('XMLRPC_REQUEST') && defined('WP_IMPORTING') | 10 | do_action() |
!defined('XMLRPC_REQUEST') && !defined('WP_IMPORTING') && !get_option() && empty($to_ping) && wp_next_scheduled() | 26 | get_option(), add_post_meta(), get_to_ping(), wp_next_scheduled() |
defined('XMLRPC_REQUEST') && !defined('WP_IMPORTING') && !get_option() && empty($to_ping) && wp_next_scheduled() | 30 | do_action(), get_option(), add_post_meta(), get_to_ping(), wp_next_scheduled() |
!defined('XMLRPC_REQUEST') && !defined('WP_IMPORTING') && !get_option() && !empty($to_ping) && wp_next_scheduled() | 31 | get_option(), add_post_meta(), get_to_ping(), add_post_meta(), wp_next_scheduled() |
!defined('XMLRPC_REQUEST') && !defined('WP_IMPORTING') && get_option() && empty($to_ping) && wp_next_scheduled() | 32 | get_option(), add_post_meta(), add_post_meta(), get_to_ping(), wp_next_scheduled() |
!defined('XMLRPC_REQUEST') && !defined('WP_IMPORTING') && !get_option() && empty($to_ping) && !wp_next_scheduled() | 32 | get_option(), add_post_meta(), get_to_ping(), wp_next_scheduled(), time(), wp_schedule_single_event() |
defined('XMLRPC_REQUEST') && !defined('WP_IMPORTING') && !get_option() && !empty($to_ping) && wp_next_scheduled() | 35 | do_action(), get_option(), add_post_meta(), get_to_ping(), add_post_meta(), wp_next_scheduled() |
defined('XMLRPC_REQUEST') && !defined('WP_IMPORTING') && get_option() && empty($to_ping) && wp_next_scheduled() | 36 | do_action(), get_option(), add_post_meta(), add_post_meta(), get_to_ping(), wp_next_scheduled() |
defined('XMLRPC_REQUEST') && !defined('WP_IMPORTING') && !get_option() && empty($to_ping) && !wp_next_scheduled() | 36 | do_action(), get_option(), add_post_meta(), get_to_ping(), wp_next_scheduled(), time(), wp_schedule_single_event() |
!defined('XMLRPC_REQUEST') && !defined('WP_IMPORTING') && get_option() && !empty($to_ping) && wp_next_scheduled() | 37 | get_option(), add_post_meta(), add_post_meta(), get_to_ping(), add_post_meta(), wp_next_scheduled() |
!defined('XMLRPC_REQUEST') && !defined('WP_IMPORTING') && !get_option() && !empty($to_ping) && !wp_next_scheduled() | 37 | get_option(), add_post_meta(), get_to_ping(), add_post_meta(), wp_next_scheduled(), time(), wp_schedule_single_event() |
6 further outcomes, up to 47 instructions
!defined('XMLRPC_REQUEST') && !defined('WP_IMPORTING') && get_option() && empty($to_ping) && !wp_next_scheduled() | 38 | get_option(), add_post_meta(), add_post_meta(), get_to_ping(), wp_next_scheduled(), time(), wp_schedule_single_event() |
defined('XMLRPC_REQUEST') && !defined('WP_IMPORTING') && get_option() && !empty($to_ping) && wp_next_scheduled() | 41 | do_action(), get_option(), add_post_meta(), add_post_meta(), get_to_ping(), add_post_meta(), wp_next_scheduled() |
defined('XMLRPC_REQUEST') && !defined('WP_IMPORTING') && !get_option() && !empty($to_ping) && !wp_next_scheduled() | 41 | do_action(), get_option(), add_post_meta(), get_to_ping(), add_post_meta(), wp_next_scheduled(), time(), wp_schedule_single_event() |
defined('XMLRPC_REQUEST') && !defined('WP_IMPORTING') && get_option() && empty($to_ping) && !wp_next_scheduled() | 42 | do_action(), get_option(), add_post_meta(), add_post_meta(), get_to_ping(), wp_next_scheduled(), time(), wp_schedule_single_event() |
!defined('XMLRPC_REQUEST') && !defined('WP_IMPORTING') && get_option() && !empty($to_ping) && !wp_next_scheduled() | 43 | get_option(), add_post_meta(), add_post_meta(), get_to_ping(), add_post_meta(), wp_next_scheduled(), time(), wp_schedule_single_event() |
defined('XMLRPC_REQUEST') && !defined('WP_IMPORTING') && get_option() && !empty($to_ping) && !wp_next_scheduled() | 47 | do_action(), get_option(), add_post_meta(), add_post_meta(), get_to_ping(), add_post_meta(), wp_next_scheduled(), time(), wp_schedule_single_event() |
Across PHP versions
Compiles the same on PHP 7.4, 8.1, 8.2, 8.3, 8.4, 8.5 and 8.6-dev: 48 instructions, 6–47 executed per call, 5 branches. The work does not change between versions.
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 · 1
One hook fires while _publish_post_hook() runs, in this order:
- do_action( xmlrpc_publish_post )actionline 8229 (+9 into the body)
Fires when _publish_post_hook() is called during an XML-RPC request.
Uses · 6
- do_action()Calls the callback functions that have been added to an action hook.
- get_option()Retrieves an option value based on an option name.
- add_post_meta()Adds a meta field to the given post.
- get_to_ping()Retrieves URLs that need to be pinged.
- wp_next_scheduled()Retrieves the timestamp of the next scheduled event for the given hook.
- wp_schedule_single_event()Schedules an event to run only once.
Source code
function _publish_post_hook( $post_id ) { if ( defined( 'XMLRPC_REQUEST' ) ) { /** * Fires when _publish_post_hook() is called during an XML-RPC request. * * @since 2.1.0 * * @param int $post_id Post ID. */ do_action( 'xmlrpc_publish_post', $post_id ); } if ( defined( 'WP_IMPORTING' ) ) { return; } if ( get_option( 'default_pingback_flag' ) ) { add_post_meta( $post_id, '_pingme', '1', true ); } add_post_meta( $post_id, '_encloseme', '1', true ); $to_ping = get_to_ping( $post_id ); if ( ! empty( $to_ping ) ) { add_post_meta( $post_id, '_trackbackme', '1' ); } if ( ! wp_next_scheduled( 'do_pings' ) ) { wp_schedule_single_event( time(), 'do_pings' ); }}Changelog
Introduced in 2.3.0. Unchanged from 6.7.7 through 7.1.0.
Signature, return type and hooks compared across 5 parsed releases.
About this page
- Parsed data
- Generated from the wordpress-develop 7.1.0 tag, from
src/wp-includes/post.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.