bulk_post_updated_messages
云策文档标注
概述
bulk_post_updated_messages 是一个 WordPress 过滤器,用于自定义批量操作(如更新、锁定、删除等)后显示的消息。默认情况下,自定义文章类型使用 'post' 类型的消息,开发者可通过此过滤器为特定文章类型添加或修改消息。
关键要点
- 过滤器名称:bulk_post_updated_messages,用于过滤批量操作更新消息。
- 参数:$bulk_messages(数组,按文章类型键控的消息数组,键包括 'updated'、'locked'、'deleted'、'trashed'、'untrashed')和 $bulk_counts(数组,每个消息的项目计数数组,用于构建国际化字符串)。
- 引入版本:WordPress 3.7.0,无需检查 WP 版本即可使用,使用不存在的过滤器不会导致错误。
- 应用场景:主要为自定义文章类型(CPT)定制批量操作反馈消息,提升用户体验。
代码示例
add_filter( 'bulk_post_updated_messages', 'my_bulk_post_updated_messages_filter', 10, 2 );
function my_bulk_post_updated_messages_filter( $bulk_messages, $bulk_counts ) {
$bulk_messages['my_cpt'] = array(
'updated' => _n( '%s my_cpt updated.', '%s my_cpts updated.', $bulk_counts['updated'] ),
'locked' => _n( '%s my_cpt not updated, somebody is editing it.', '%s my_cpts not updated, somebody is editing them.', $bulk_counts['locked'] ),
'deleted' => _n( '%s my_cpt permanently deleted.', '%s my_cpts permanently deleted.', $bulk_counts['deleted'] ),
'trashed' => _n( '%s my_cpt moved to the Trash.', '%s my_cpts moved to the Trash.', $bulk_counts['trashed'] ),
'untrashed' => _n( '%s my_cpt restored from the Trash.', '%s my_cpts restored from the Trash.', $bulk_counts['untrashed'] ),
);
return $bulk_messages;
}
原文内容
Filters the bulk action updated messages.
Description
By default, custom post types use the messages for the ‘post’ post type.
Parameters
$bulk_messagesarray[]-
Arrays of messages, each keyed by the corresponding post type. Messages are keyed with
'updated','locked','deleted','trashed', and'untrashed'. $bulk_countsint[]-
Array of item counts for each message, used to build internationalized strings.
Source
$bulk_messages = apply_filters( 'bulk_post_updated_messages', $bulk_messages, $bulk_counts );
Changelog
| Version | Description |
|---|---|
| 3.7.0 | Introduced. |
Skip to note 2 content
Steven Lin
Example migrated from Codex:
The following example adds custom bulk action updated messages for ‘my_cpt’ post type (cpt being an abbreviation for “custom post type”):
add_filter( 'bulk_post_updated_messages', 'my_bulk_post_updated_messages_filter', 10, 2 ); function my_bulk_post_updated_messages_filter( $bulk_messages, $bulk_counts ) { $bulk_messages['my_cpt'] = array( 'updated' => _n( '%s my_cpt updated.', '%s my_cpts updated.', $bulk_counts['updated'] ), 'locked' => _n( '%s my_cpt not updated, somebody is editing it.', '%s my_cpts not updated, somebody is editing them.', $bulk_counts['locked'] ), 'deleted' => _n( '%s my_cpt permanently deleted.', '%s my_cpts permanently deleted.', $bulk_counts['deleted'] ), 'trashed' => _n( '%s my_cpt moved to the Trash.', '%s my_cpts moved to the Trash.', $bulk_counts['trashed'] ), 'untrashed' => _n( '%s my_cpt restored from the Trash.', '%s my_cpts restored from the Trash.', $bulk_counts['untrashed'] ), ); return $bulk_messages; }