handle_bulk_actions-{$screen}
云策文档标注
概述
handle_bulk_actions-{$screen} 是一个 WordPress Hook,用于在自定义批量操作需要处理时触发,允许开发者修改重定向链接以向用户提供操作反馈。
关键要点
- Hook 名称包含动态部分 $screen,代表当前屏幕 ID,用于针对特定屏幕(如文章、评论、用户等)处理批量操作。
- 参数包括 $sendback(重定向 URL)、$doaction(执行的操作名称)和 $items(操作项数组,如文章、评论、用户等的 ID)。
- 主要用于在批量操作后修改 $sendback,添加成功或失败反馈,以改善用户体验。
- 自 WordPress 4.7.0 版本引入,是处理自定义批量操作的核心 Hook。
代码示例
$sendback = apply_filters( "handle_bulk_actions-{$screen}", $sendback, $doaction, $post_ids );注意事项
- Hook 名称使用连字符而非下划线,需注意命名规范,但代码示例中已忽略此警告。
- 参数 $items 可接受多种类型的 ID 数组,如文章、评论、术语、链接、插件、附件或用户,需根据上下文正确处理。
原文内容
Fires when a custom bulk action should be handled.
Description
The redirect link should be modified with success or failure feedback from the action to be used to display feedback to the user.
The dynamic portion of the hook name, $screen, refers to the current screen ID.
Parameters
$sendbackstring-
The redirect URL.
$doactionstring-
The action being taken.
$itemsarray-
The items to take the action on. Accepts an array of IDs of posts, comments, terms, links, plugins, attachments, or users.
Source
$sendback = apply_filters( "handle_bulk_actions-{$screen}", $sendback, $doaction, $post_ids ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores
Changelog
| Version | Description |
|---|---|
| 4.7.0 | Introduced. |