admin管理员组文章数量:1130349
Some of the employees at my organization need to be able to upload files to a folder and share a link with others. It’s primarily documents like pictures, pdf’s and Word documents. And instead of creating a completely new File Management System, I was thinking about just using the built-in Wordpress Media Library function for this task.
But my problem is, that I want to create a User Role with permissions to only do that and nothing else. If possible, also hide all other option panels, custom post types, etc.
I’ve been reading a bit about User Roles and Capabilities, and founded a Plugin but I think it is a bit much to install a large plugin when it is the only User Role I need to create. And more, I would like to learn some more about it and I think this is a good way to do it.
Any help would appreciate.
Sincere - Mestika
Some of the employees at my organization need to be able to upload files to a folder and share a link with others. It’s primarily documents like pictures, pdf’s and Word documents. And instead of creating a completely new File Management System, I was thinking about just using the built-in Wordpress Media Library function for this task.
But my problem is, that I want to create a User Role with permissions to only do that and nothing else. If possible, also hide all other option panels, custom post types, etc.
I’ve been reading a bit about User Roles and Capabilities, and founded a Plugin but I think it is a bit much to install a large plugin when it is the only User Role I need to create. And more, I would like to learn some more about it and I think this is a good way to do it.
Any help would appreciate.
Sincere - Mestika
Share Improve this question asked Dec 17, 2011 at 10:26 MestikaMestika 7703 gold badges9 silver badges18 bronze badges3 Answers
Reset to default 0Install Justin Tadlock's Members Plugin. It has per-configured roles that allow in-depth control over users. If the standard roles don't allow the amount of access control you want, you can create a custom role and assign your specific access level.
something like this : https://codex.wordpress/Function_Reference/add_role then
if ( current_user_can('new_role') && !current_user_can('upload_files') )
add_action('admin_init', 'allow_new_role_uploads');
function allow_new_role_uploads() {
$new_role = get_role('new_role');
$new_role->add_cap('upload_files');
}
If you have created a custom role to add new capabilities add this code to them function.php
function add_theme_caps(){
global $pagenow;
// gets the author role
$role = get_role( 'teacher' );
$role2 = get_role( 'school' );
if ( 'themes.php' == $pagenow && isset( $_GET['activated'] ) ){ // Test if theme is activated
// Theme is activated
// This only works, because it accesses the class instance.
// would allow the author to edit others' posts for current theme only
$role->add_cap( 'upload_files' );
$role2->add_cap( 'upload_files' );
}
else {
// Theme is deactivated
// Remove the capability when theme is deactivated
$role->remove_cap( 'upload_files' );
$role2->remove_cap( 'upload_files' );
}
}
add_action( 'load-themes.php', 'add_theme_caps' );
Dactivate and active theme to make changes
Some of the employees at my organization need to be able to upload files to a folder and share a link with others. It’s primarily documents like pictures, pdf’s and Word documents. And instead of creating a completely new File Management System, I was thinking about just using the built-in Wordpress Media Library function for this task.
But my problem is, that I want to create a User Role with permissions to only do that and nothing else. If possible, also hide all other option panels, custom post types, etc.
I’ve been reading a bit about User Roles and Capabilities, and founded a Plugin but I think it is a bit much to install a large plugin when it is the only User Role I need to create. And more, I would like to learn some more about it and I think this is a good way to do it.
Any help would appreciate.
Sincere - Mestika
Some of the employees at my organization need to be able to upload files to a folder and share a link with others. It’s primarily documents like pictures, pdf’s and Word documents. And instead of creating a completely new File Management System, I was thinking about just using the built-in Wordpress Media Library function for this task.
But my problem is, that I want to create a User Role with permissions to only do that and nothing else. If possible, also hide all other option panels, custom post types, etc.
I’ve been reading a bit about User Roles and Capabilities, and founded a Plugin but I think it is a bit much to install a large plugin when it is the only User Role I need to create. And more, I would like to learn some more about it and I think this is a good way to do it.
Any help would appreciate.
Sincere - Mestika
Share Improve this question asked Dec 17, 2011 at 10:26 MestikaMestika 7703 gold badges9 silver badges18 bronze badges3 Answers
Reset to default 0Install Justin Tadlock's Members Plugin. It has per-configured roles that allow in-depth control over users. If the standard roles don't allow the amount of access control you want, you can create a custom role and assign your specific access level.
something like this : https://codex.wordpress/Function_Reference/add_role then
if ( current_user_can('new_role') && !current_user_can('upload_files') )
add_action('admin_init', 'allow_new_role_uploads');
function allow_new_role_uploads() {
$new_role = get_role('new_role');
$new_role->add_cap('upload_files');
}
If you have created a custom role to add new capabilities add this code to them function.php
function add_theme_caps(){
global $pagenow;
// gets the author role
$role = get_role( 'teacher' );
$role2 = get_role( 'school' );
if ( 'themes.php' == $pagenow && isset( $_GET['activated'] ) ){ // Test if theme is activated
// Theme is activated
// This only works, because it accesses the class instance.
// would allow the author to edit others' posts for current theme only
$role->add_cap( 'upload_files' );
$role2->add_cap( 'upload_files' );
}
else {
// Theme is deactivated
// Remove the capability when theme is deactivated
$role->remove_cap( 'upload_files' );
$role2->remove_cap( 'upload_files' );
}
}
add_action( 'load-themes.php', 'add_theme_caps' );
Dactivate and active theme to make changes
本文标签: Create a User Role with permissions to only upload files to the media library
版权声明:本文标题:Create a User Role with permissions to only upload files to the media library? 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749251121a2339713.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论