钩子文档

pre_delete_post

💡 云策文档标注

概述

pre_delete_post 是一个 WordPress 过滤器,用于在删除文章前决定是否继续执行删除操作。开发者可以通过此 Hook 干预删除流程,例如基于条件阻止或允许删除。

关键要点

  • pre_delete_post 是一个过滤器,在 wp_delete_post() 函数中调用,用于控制文章删除是否进行。
  • 参数包括 $check(初始为 null,返回非 null 值将短路删除)、$post(WP_Post 对象)和 $force_delete(布尔值,指示是否绕过回收站)。
  • 此 Hook 从 WordPress 4.4.0 版本引入,常用于自定义删除逻辑或权限检查。

代码示例

$check = apply_filters( 'pre_delete_post', null, $post, $force_delete );

📄 原文内容

Filters whether a post deletion should take place.

Parameters

$checkWP_Post|false|null
Whether to go forward with deletion. Anything other than null will short-circuit deletion.
$postWP_Post
Post object.
$force_deletebool
Whether to bypass the Trash.

Source

$check = apply_filters( 'pre_delete_post', null, $post, $force_delete );

Changelog

Version Description
4.4.0 Introduced.