wp_insert_post_empty_content
云策文档标注
概述
wp_insert_post_empty_content 是一个 WordPress 过滤器,用于判断帖子是否应被视为“空”,从而影响帖子插入操作。当帖子类型支持标题、编辑器和摘要字段,且这些字段均为空时,过滤器可返回真值以阻止帖子插入。
关键要点
- 过滤器用于检查帖子是否为空,基于帖子类型对标题、编辑器和摘要字段的支持情况。
- 返回真值会中断 wp_insert_post() 操作,返回 0 或 WP_Error(取决于 $wp_error 参数)。
- 参数包括 $maybe_empty(布尔值,表示是否为空)和 $postarr(数组,包含帖子数据)。
- 自 WordPress 3.3.0 版本引入,常用于自定义帖子插入逻辑。
代码示例
if ( apply_filters( 'wp_insert_post_empty_content', $maybe_empty, $postarr ) ) {
// 过滤器返回真值时执行的代码
}
原文内容
Filters whether the post should be considered “empty”.
Description
The post is considered “empty” if both:
- The post type supports the title, editor, and excerpt fields
- The title, editor, and excerpt fields are all empty
Returning a truthy value from the filter will effectively short-circuit the new post being inserted and return 0. If $wp_error is true, a WP_Error will be returned instead.
Parameters
$maybe_emptybool-
Whether the post should be considered “empty”.
$postarrarray-
Array of post data.
Source
if ( apply_filters( 'wp_insert_post_empty_content', $maybe_empty, $postarr ) ) {
Changelog
| Version | Description |
|---|---|
| 3.3.0 | Introduced. |