钩子文档

delete_post_{$post->post_type}

💡 云策文档标注

概述

delete_post_{$post->post_type} 是一个 WordPress 动作钩子,在从数据库中删除文章前立即触发。钩子名称的动态部分基于文章类型,允许针对特定文章类型执行自定义操作。

关键要点

  • 触发时机:在文章从数据库删除前立即执行。
  • 钩子名称:动态钩子,{$post->post_type} 替换为文章类型的 slug。
  • 参数:$post_id(整数,文章 ID)和 $post(WP_Post 对象,文章对象)。
  • 相关函数:与 wp_delete_post() 函数关联,用于删除或移至回收站。
  • 版本历史:从 WordPress 6.6.0 版本引入。

📄 原文内容

Fires immediately before a post is deleted from the database.

Description

The dynamic portion of the hook name, $post->post_type, refers to the post type slug.

Parameters

$post_idint
Post ID.
$postWP_Post
Post object.

Source

do_action( "delete_post_{$post->post_type}", $post_id, $post );

Changelog

Version Description
6.6.0 Introduced.