private_post хук-событиеWP 2.3.0

Fires when a post is transitioned from one status to another.

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

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.

Это один из вариантов динамического хука (new_status)_(post_type)

Использование

add_action( 'private_post', 'wp_kama_private_post_action', 10, 3 );

/**
 * Function for `private_post` action-hook.
 * 
 * @param int     $post_id    Post ID.
 * @param WP_Post $post       Post object.
 * @param string  $old_status Old post status.
 *
 * @return void
 */
function wp_kama_private_post_action( $post_id, $post, $old_status ){

	// action...
}
$post_id(int)
Post ID.
$post(WP_Post)
Post object.
$old_status(строка)
Old post status.

Список изменений

С версии 2.3.0 Введена.
С версии 5.9.0 Added $old_status parameter.

Где вызывается хук

wp_transition_post_status()
private_post
wp-includes/post.php 5361
do_action( "{$new_status}_{$post->post_type}", $post->ID, $post, $old_status );

Где используется хук в WordPress

Использование не найдено.