Title: _publish_post_hook
Published: April 25, 2014
Last modified: February 24, 2026

---

# _publish_post_hook( int $post_id )

## In this article

 * [Description](https://developer.wordpress.org/reference/functions/_publish_post_hook/?output_format=md#description)
 * [Parameters](https://developer.wordpress.org/reference/functions/_publish_post_hook/?output_format=md#parameters)
 * [Source](https://developer.wordpress.org/reference/functions/_publish_post_hook/?output_format=md#source)
 * [Hooks](https://developer.wordpress.org/reference/functions/_publish_post_hook/?output_format=md#hooks)
 * [Related](https://developer.wordpress.org/reference/functions/_publish_post_hook/?output_format=md#related)
 * [Changelog](https://developer.wordpress.org/reference/functions/_publish_post_hook/?output_format=md#changelog)

[ Back to top](https://developer.wordpress.org/reference/functions/_publish_post_hook/?output_format=md#wp--skip-link--target)

This function’s access is marked private. This means it is not intended for use 
by plugin or theme developers, only by core. It is listed here for completeness.

Hook to schedule pings and enclosures when a post is published.

## 󠀁[Description](https://developer.wordpress.org/reference/functions/_publish_post_hook/?output_format=md#description)󠁿

Uses XMLRPC_REQUEST and WP_IMPORTING constants.

## 󠀁[Parameters](https://developer.wordpress.org/reference/functions/_publish_post_hook/?output_format=md#parameters)󠁿

 `$post_id`intrequired

The ID of the post being published.

## 󠀁[Source](https://developer.wordpress.org/reference/functions/_publish_post_hook/?output_format=md#source)󠁿

    ```php
    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' );
    	}
    }
    ```

[View all references](https://developer.wordpress.org/reference/files/wp-includes/post.php/)
[View on Trac](https://core.trac.wordpress.org/browser/tags/6.9.4/src/wp-includes/post.php#L7998)
[View on GitHub](https://github.com/WordPress/wordpress-develop/blob/6.9.4/src/wp-includes/post.php#L7998-L8027)

## 󠀁[Hooks](https://developer.wordpress.org/reference/functions/_publish_post_hook/?output_format=md#hooks)󠁿

 [do_action( ‘xmlrpc_publish_post’, int $post_id )](https://developer.wordpress.org/reference/hooks/xmlrpc_publish_post/)

Fires when [_publish_post_hook()](https://developer.wordpress.org/reference/functions/_publish_post_hook/)
is called during an XML-RPC request.

## 󠀁[Related](https://developer.wordpress.org/reference/functions/_publish_post_hook/?output_format=md#related)󠁿

| Uses | Description | 
| [wp_next_scheduled()](https://developer.wordpress.org/reference/functions/wp_next_scheduled/)`wp-includes/cron.php` |

Retrieves the timestamp of the next scheduled event for the given hook.

  | 
| [wp_schedule_single_event()](https://developer.wordpress.org/reference/functions/wp_schedule_single_event/)`wp-includes/cron.php` |

Schedules an event to run only once.

  | 
| [get_to_ping()](https://developer.wordpress.org/reference/functions/get_to_ping/)`wp-includes/post.php` |

Retrieves URLs that need to be pinged.

  | 
| [add_post_meta()](https://developer.wordpress.org/reference/functions/add_post_meta/)`wp-includes/post.php` |

Adds a meta field to the given post.

  | 
| [do_action()](https://developer.wordpress.org/reference/functions/do_action/)`wp-includes/plugin.php` |

Calls the callback functions that have been added to an action hook.

  | 
| [get_option()](https://developer.wordpress.org/reference/functions/get_option/)`wp-includes/option.php` |

Retrieves an option value based on an option name.

  |

[Show 2 more](https://developer.wordpress.org/reference/functions/_publish_post_hook/?output_format=md#)
[Show less](https://developer.wordpress.org/reference/functions/_publish_post_hook/?output_format=md#)

## 󠀁[Changelog](https://developer.wordpress.org/reference/functions/_publish_post_hook/?output_format=md#changelog)󠁿

| Version | Description | 
| [2.3.0](https://developer.wordpress.org/reference/since/2.3.0/) | Introduced. |

## User Contributed Notes

You must [log in](https://login.wordpress.org/?redirect_to=https%3A%2F%2Fdeveloper.wordpress.org%2Freference%2Ffunctions%2F_publish_post_hook%2F)
before being able to contribute a note or feedback.