钩子文档

{$old_status}_to_{$new_status}

💡 云策文档标注

概述

此 Hook 在文章状态从一个状态转换到另一个状态时触发。Hook 名称是动态的,基于旧状态和新状态。

关键要点

  • Hook 名称格式为 {$old_status}_to_{$new_status},例如 draft_to_publish、publish_to_trash。
  • 参数为 $post,类型为 WP_Post 对象,表示被转换的文章。
  • 此 Hook 由 wp_transition_post_status() 函数触发,用于处理文章状态转换相关操作。
  • 自 WordPress 2.3.0 版本引入。

📄 原文内容

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

Description

The dynamic portions of the hook name, $new_status and $old_status, refer to the old and new post statuses, respectively.

Possible hook names include:

  • draft_to_publish
  • publish_to_trash
  • pending_to_draft

Parameters

$postWP_Post
Post object.

Source

do_action( "{$old_status}_to_{$new_status}", $post );

Changelog

Version Description
2.3.0 Introduced.