I\'m reposting this with an example, I really don\'t get the code formatting of this editor, last time I was so irritated with it that I skipped the code!
该下拉列表使用过滤器“wp\\u dropdown\\u users”(user.php,第976行)填充。此筛选器将下拉列表(html select)作为字符串返回。您可以截取此字符串,并添加自己的选项,即具有自定义角色的用户列表。检查select with Firebug,选项值是用户id,文本是该用户的登录名。
<?php
add_filter(\'wp_dropdown_users\', \'test\');
function test($output)
{
global $post;
//Doing it only for the custom post type
if($post->post_type == \'my_custom_post\')
{
$users = get_users(array(\'role\'=>\'my_custom_role\'));
//We\'re forming a new select with our values, you can add an option
//with value 1, and text as \'admin\' if you want the admin to be listed as well,
//optionally you can use a simple string replace trick to insert your options,
//if you don\'t want to override the defaults
$output .= "<select id=\'post_author_override\' name=\'post_author_override\' class=\'\'>";
foreach($users as $user)
{
$output .= "<option value=\'".$user->id."\'>".$user->user_login."</option>";
}
$output .= "</select>";
}
return $output;
}
?>
就是这样!您将有一个下拉列表列出您的自定义角色。尝试更改帖子作者,它会得到整洁的更新。这是一个黑客,但它对我有用!