钩子文档

rest_{$this->post_type}_trashable

💡 云策文档标注

概述

此文档介绍 WordPress REST API 中的过滤器钩子 rest_{$this->post_type}_trashable,用于控制文章类型是否支持移至回收站功能。开发者可通过此钩子动态修改文章类型的回收站支持状态。

关键要点

  • 钩子名称动态部分 $this->post_type 对应文章类型 slug,例如 rest_post_trashable、rest_page_trashable。
  • 传递 false 参数可禁用特定文章类型的回收站支持。
  • 钩子参数包括 $supports_trash(布尔值,表示回收站支持状态)和 $post(WP_Post 对象,被考虑支持回收站的文章)。
  • 此钩子自 WordPress 4.7.0 版本引入,在 WP_REST_Posts_Controller::delete_item() 方法中使用。

📄 原文内容

Filters whether a post is trashable.

Description

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

Possible hook names include:

  • rest_post_trashable
  • rest_page_trashable
  • rest_attachment_trashable

Pass false to disable Trash support for the post.

Parameters

$supports_trashbool
Whether the post type support trashing.
$postWP_Post
The Post object being considered for trashing support.

Source

$supports_trash = apply_filters( "rest_{$this->post_type}_trashable", $supports_trash, $post );

Changelog

Version Description
4.7.0 Introduced.