quick_edit_show_taxonomy
云策文档标注
概述
quick_edit_show_taxonomy 是一个 WordPress 过滤器,用于控制当前分类法是否在 Quick Edit 面板中显示。开发者可以通过此过滤器基于分类法名称、文章类型等条件动态调整显示逻辑。
关键要点
- 过滤器名称:quick_edit_show_taxonomy
- 参数:$show_in_quick_edit(布尔值,是否显示)、$taxonomy_name(字符串,分类法名称)、$post_type(字符串,当前 Quick Edit 文章的文章类型)
- 用途:在 Quick Edit 面板中隐藏或显示特定分类法,常用于权限控制或条件性显示
- 引入版本:WordPress 4.2.0
代码示例
/**
* Hide tags from quick edit if user does not have admin priviledges
*/
function hide_tags_from_quick_edit( $show_in_quick_edit, $taxonomy_name, $post_type ) {
if ( 'post_tag' === $taxonomy_name && ! current_user_can( 'manage_options' ) ) {
return false;
} else {
return $show_in_quick_edit;
}
}
add_filter( 'quick_edit_show_taxonomy', 'hide_tags_from_quick_edit', 10, 3 );注意事项
- 此过滤器在 wp_ajax_inline_save() 和 WP_Posts_List_Table::inline_edit() 中被调用,用于处理 Quick Edit 的 AJAX 保存和行内编辑输出。
- 确保函数返回布尔值以正确控制显示状态,避免影响其他分类法的显示。
原文内容
Filters whether the current taxonomy should be shown in the Quick Edit panel.
Parameters
$show_in_quick_editbool-
Whether to show the current taxonomy in Quick Edit.
$taxonomy_namestring-
Taxonomy name.
$post_typestring-
Post type of current Quick Edit post.
Source
if ( ! apply_filters( 'quick_edit_show_taxonomy', $show_in_quick_edit, $taxonomy_name, $screen->post_type ) ) {
Changelog
| Version | Description |
|---|---|
| 4.2.0 | Introduced. |
Skip to note 2 content
Steven Slack
/** * Hide tags from quick edit if user does not have admin priviledges */ function hide_tags_from_quick_edit( $show_in_quick_edit, $taxonomy_name, $post_type ) { if ( 'post_tag' === $taxonomy_name && ! current_user_can( 'manage_options' ) ) { return false; } else { return $show_in_quick_edit; } } add_filter( 'quick_edit_show_taxonomy', 'hide_tags_from_quick_edit', 10, 3 );