我正在使用一个函数创建新的用户角色并删除一些默认值。但是,它们不会出现在post-author框中!只有管理员显示,因为他们被选为管理员。任何具有自定义角色的用户都不会显示。知道为什么会这样吗?
以下是我的功能:
// Add New User Roles
function add_new_roles() {
// New Roles To Be Added
$new_roles = array(
array(
\'role\' => \'senior_pastor\',
\'display\' => \'Senior Pastor\'
),
array(
\'role\' => \'exec_pastor\',
\'display\' => \'Executive Pastor\'
),
array(
\'role\' => \'assoc_pastor\',
\'display\' => \'Associate Pastor\'
),
array(
\'role\' => \'elder\',
\'display\' => \'Elder\'
),
array(
\'role\' => \'ministry_leader\',
\'display\' => \'Ministry Leader\'
)
);
foreach($new_roles as $role){
add_role($role[\'role\'], $role[\'display\'], array(
\'edit_published_posts\' => true,
\'upload_files\' => true,
\'create_product\' => true,
\'publish_posts\' => true,
\'delete_published_posts\' => true,
\'edit_posts\' => true,
\'delete_posts\' => true,
\'read\' => true
));
}
// Old Roles To Be Removed
$old_roles = array(
\'subscriber\',
\'contributor\',
\'author\'
\'editor\'
);
foreach($old_roles as $role){
remove_role( $role );
}
}
add_action(\'after_switch_theme\', \'add_new_roles\');
SO网友:souporserious
找到以下解决方法。我想这与Wordpress核心中的一个bug有关。这将列出帖子中的所有用户,所以要小心。
// Filter to fix the Post Author Dropdown
function author_override( $output ) {
global $post, $user_ID;
// return if this isn\'t the theme author override dropdown
if (!preg_match(\'/post_author_override/\', $output)) return $output;
// return if we\'ve already replaced the list (end recursion)
if (preg_match (\'/post_author_override_replaced/\', $output)) return $output;
// replacement call to wp_dropdown_users
$output = wp_dropdown_users(array(
\'echo\' => 0,
\'name\' => \'post_author_override_replaced\',
\'selected\' => empty($post->ID) ? $user_ID : $post->post_author,
\'include_selected\' => true
));
// put the original name back
$output = preg_replace(\'/post_author_override_replaced/\', \'post_author_override\', $output);
return $output;
}
add_filter(\'wp_dropdown_users\', \'author_override\');
贷记至
here