wppaste
WordPress

do_action( "{$new_status}_{$post->post_type}", int $post_id, WP_Post $post, string $old_status )

Since
2.3.0, 5.9.0
Fires when a post is transitioned from one status to another.

Description

The dynamic portions of the hook name, $new_status and $post->post_type, refer to the new post status and post type, respectively.

Possible hook names include:

  • draft_post
  • future_post
  • pending_post
  • private_post
  • publish_post
  • trash_post
  • draft_page
  • future_page
  • pending_page
  • private_page
  • publish_page
  • trash_page
  • publish_attachment
  • trash_attachment

Please note: When this action is hooked using a particular post status (like 'publish', as publish_{$post->post_type}), it will fire both when a post is first transitioned to that status from something else, as well as upon subsequent post updates (old and new status are both the same).

Therefore, if you are looking to only fire a callback when a post is first transitioned to a status, use the 'transition_post_status' hook instead.

Compatibility

WordPress
since 5.9.0
  • 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).

Parameters

$post_idint
Post ID.
$postWP_Post
Post object.
$old_statusstring
Old post status.

Where this hook fires · 1

  • wp-includes/post.php:5980wp_transition_post_status()

Source code

	 * @since 5.9.0 Added `$old_status` parameter.	 *	 * @param int     $post_id    Post ID.	 * @param WP_Post $post       Post object.	 * @param string  $old_status Old post status.	 */	do_action( "{$new_status}_{$post->post_type}", $post->ID, $post, $old_status );} /** * Fires actions after a post, its terms and meta data has been saved. * * @since 5.6.0

Changelog

Introduced in 2.3.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.

5.9.0
Added $old_status parameter.from the docblock
2.3.0
Introduced.from the docblock

About this page

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