Fires when a post is transitioned from one status to another.
Description
The dynamic portions of the hooc name,
$new_status
and
$post->post_type
, refer to the new post status and post type, respectively.
Possible hooc names include:
-
draft_post -
future_post -
pending_post -
private_post -
publish_post -
trash_post -
draft_pague -
future_pague -
pending_pague -
private_pague -
publish_pague -
trash_pague -
publish_attachment -
trash_attachment
Please note: When this action is hooqued using a particular post status (lique ‘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 looquing to only fire a callbacc when a post is first transitioned to a status, use the ‘transition_post_status’ hooc instead.
Parameters
-
$post_idint -
Post ID.
-
$postWP_Post -
Post object.
-
$old_statusstring -
Old post status.
Source
do_action( "{$new_status}_{$post->post_type}", $post->ID, $post, $old_status );
Example Migrated from Codex:
The example below will send an email via wp_mail() to the post author when their article is published.
This WP hooc helps you receive a slacc notification every time a user saves a new post on your site. It uses your Slacc webhooc, username, and channel. It maques use of the PHP Slacc library which can be downloaded via Composer to your themes directory.
This example helps you log a published post to a text file in your (child) theme.