Create a User Role with permissions to only upload files to the media library?

admin2025-06-07  51

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 badges
Add a comment  | 

3 Answers 3

Reset to default 0

Install 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

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1749251146a317620.html

最新回复(0)