钩子文档

pre_untrash_post

💡 云策文档标注

概述

pre_untrash_post 是一个 WordPress 过滤器钩子,用于在恢复文章从回收站之前控制是否允许此操作。它允许开发者基于文章对象和之前状态进行自定义逻辑判断。

关键要点

  • pre_untrash_post 是一个过滤器钩子,用于干预文章从回收站恢复的过程。
  • 它接受三个参数:$untrash(布尔值或 null,表示是否继续恢复)、$post(WP_Post 对象)和 $previous_status(文章被移至回收站前的状态字符串)。
  • 开发者可以通过此钩子添加自定义条件来阻止或允许文章的恢复操作。
  • 该钩子自 WordPress 4.9.0 引入,并在 5.6.0 版本中增加了 $previous_status 参数。

代码示例

$check = apply_filters( 'pre_untrash_post', null, $post, $previous_status );

注意事项

  • 此钩子通常与 wp_untrash_post() 函数结合使用,用于在恢复文章前执行额外检查。
  • 返回 null 或 true 允许恢复,返回 false 则阻止恢复操作。
  • 确保正确处理 $previous_status 参数,以基于文章之前的状态做出决策。

📄 原文内容

Filters whether a post untrashing should take place.

Parameters

$untrashbool|null
Whether to go forward with untrashing.
$postWP_Post
Post object.
$previous_statusstring
The status of the post at the point where it was trashed.

Source

$check = apply_filters( 'pre_untrash_post', null, $post, $previous_status );

Changelog

Version Description
5.6.0 Added the $previous_status parameter.
4.9.0 Introduced.