admin管理员组文章数量:1122846
I would like to allow contributors to upload media by using the following code added to functions.php
. But the Add Media Button still doesn't show up.
// Allow Contributors to Add Media
if ( current_user_can('contributor') && ! current_user_can('upload_files') ) {
add_action('admin_init', 'allow_contributor_uploads');
function allow_contributor_uploads() {
$contributor = get_role('contributor');
$contributor->add_cap('upload_files');
}
}
I would like to allow contributors to upload media by using the following code added to functions.php
. But the Add Media Button still doesn't show up.
// Allow Contributors to Add Media
if ( current_user_can('contributor') && ! current_user_can('upload_files') ) {
add_action('admin_init', 'allow_contributor_uploads');
function allow_contributor_uploads() {
$contributor = get_role('contributor');
$contributor->add_cap('upload_files');
}
}
Share
Improve this question
edited Dec 22, 2022 at 20:01
bueltge
17.1k7 gold badges61 silver badges97 bronze badges
asked Jan 5, 2018 at 6:08
dekkapo khonjondekkapo khonjon
112 bronze badges
1
- Does this answer your question? Allow contributor role to upload images and not edit already published articles – bueltge Commented Dec 22, 2022 at 20:05
2 Answers
Reset to default 0Try changing current_user_can('contributor')
to current_user_can('edit_posts')
. According to the Codex, 'Passing role names to current_user_can() is discouraged as this is not guaranteed to work correctly.'
I would try surrounding your conditional expression in brackets, just to make sure it's getting parsed properly:
if ( current_user_can('edit_posts') && ! current_user_can('upload_files') ) {
add_action( 'admin_init', 'allow_contributor_uploads' );
}
function allow_contributor_uploads() {
$contributor = get_role('contributor');
$contributor->add_cap('upload_files');
}
本文标签: Using WordPress’s addcap method to Allow Contributors to Upload Media is not Working
版权声明:本文标题:Using WordPress’s add_cap method to Allow Contributors to Upload Media is not Working 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736286904a1927767.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论