admin管理员组文章数量:1391768
I am using a function to create new user roles and delete some defaults. However, they are not showing up in the post author box! Only the admin shows up because they are selected as an admin. Any user with a custom role does not show up. Any idea why this would be happening?
Here is my function:
// 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');
I am using a function to create new user roles and delete some defaults. However, they are not showing up in the post author box! Only the admin shows up because they are selected as an admin. Any user with a custom role does not show up. Any idea why this would be happening?
Here is my function:
// 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');
Share
Improve this question
edited Mar 21, 2013 at 23:42
souporserious
asked Mar 21, 2013 at 23:24
souporserioussouporserious
6791 gold badge11 silver badges27 bronze badges
4
- Why would roles show up in the post author box? Only users show up there. – vancoder Commented Mar 21, 2013 at 23:32
- 1 Sorry, worded my question wrong. Users with custom roles are not showing up. – souporserious Commented Mar 21, 2013 at 23:42
- Looks like if you log in as one of your new users, they can create posts. Then, when you login as admin again, their names will appear in the author list of the post 'they' created. I'm not sure why these restrictions apply. – vancoder Commented Mar 21, 2013 at 23:56
- @vancoder I tried this but nothing happend. It still does not show up. I was able to create a post, but it did not save with me as the editor. Weird! – souporserious Commented Mar 22, 2013 at 0:06
2 Answers
Reset to default 10Found a workaround below. I guess it has to do with a bug in the Wordpress core. This will list ALL users in posts, so be cautious.
// 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');
credit goes to here
Yes, indeed, it is a bug, as reported in the ticket #16841.
Testing with 3.6-beta3, it's still there... The workaround is, in scribu's words:
[...] to add a
level_1
cap to your role.It's PITA, considering how user levels have been deprecated so long ago, but there you go.
And... it works as advertised ;)
For reference, these are the places where wp_dropdown_users
happen in the core:
本文标签: customizationUsers with custom roles not showing in post author select box
版权声明:本文标题:customization - Users with custom roles not showing in post author select box 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744771989a2624394.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论