post_author_meta_box()
云策文档标注
概述
post_author_meta_box() 函数用于在 WordPress 后台编辑文章时显示作者选择表单字段。它生成一个下拉列表,允许用户选择文章的作者。
关键要点
- 函数接受一个必需参数 $post,类型为 WP_Post,表示当前文章对象。
- 内部使用 wp_dropdown_users() 函数来创建用户下拉列表,并设置相关参数如权限检查、默认选中作者等。
- 此函数自 WordPress 2.6.0 版本引入,主要用于文章编辑界面的作者元框。
原文内容
Displays form field with list of authors.
Parameters
$postWP_Postrequired-
Current post object.
Source
function post_author_meta_box( $post ) {
global $user_ID;
$post_type_object = get_post_type_object( $post->post_type );
?>
<label class="screen-reader-text" for="post_author_override">
</label>
array( $post_type_object->cap->edit_posts ),
'name' => 'post_author_override',
'selected' => empty( $post->ID ) ? $user_ID : $post->post_author,
'include_selected' => true,
'show' => 'display_name_with_login',
)
);
}
Changelog
| Version | Description |
|---|---|
| 2.6.0 | Introduced. |