0

I want my media-library and all currently uploaded files distributed and available to all users. I am using the User Role Editor Plugin

Is there any functions.php hack that makes all media-uploads visible to all users and roles?

I have a subscriber that is possible to edit a few pages and upload media, but the media uploads that are currently in the library for admins are not visible to the subscriber.

Update: My current approach, that is not working so far.

my functions.php file:

add_action( 'admin_init', 'rk_shared_uploads' );
add_action( 'init', 'rk_shared_uploads');

function rk_shared_uploads() {
    $subscriber = get_role( 'subscriber' );
    $subscriber->add_cap( 'upload_files' );
    $subscriber->add_cap( 'unfiltered_upload' );

    $contributor = get_role( 'contributor' );
    $contributor->add_cap( 'upload_files' );
    $contributor->add_cap( 'unfiltered_upload' );

    $author = get_role( 'author' );
    $author->add_cap( 'upload_files' );
    $author->add_cap( 'unfiltered_upload' );
}

in my wp-config.php

const PP_MEDIA_LIB_UNFILTERED = true;
7
  • Add upload_files capability to user roles you want media library access.
    – Domain
    Commented Jun 25, 2015 at 7:15
  • The users are able to "upload" … I want them to see and use existing material in the library from all other users. Commented Jun 25, 2015 at 8:12
  • upload_files capability gives access to media and media-> add new. codex here
    – Domain
    Commented Jun 25, 2015 at 8:56
  • See my question-update, I added this to my theme functions.php file. The user I tried has role "author" but can't see any media uploads. Commented Jun 25, 2015 at 9:17
  • Maybe with the RoleScoper Plugin this does not work? Commented Jun 25, 2015 at 9:23

3 Answers 3

2
+100

The plugin you mentioned is only reportedly tested up to WordPress version 3.6.1.

I would not (in general) recommend abandoned plugins, because they might impose security risks.

Additionally it uses PHP4 class constructors, that might soon be deprecated and it calls non static methods in a static way.

If you remove the plugin, you should be able to use your code snippet:

add_action( 'admin_init', 'mathiregister_allow_uploads' );

function mathiregister_allow_uploads() {
    $contributor = get_role( 'contributor' );
    $contributor->add_cap('upload_files');
}

to allow contributors to get access to the media library and upload files.

Remember to prefix your filter callbacks, to avoid name collisions.

ps: Skimming through the plugin code, you might be able to bypass the plugin's media restrictions by defining:

define( 'SCOPER_ALL_UPLOADS_EDITABLE ', true );

or do it @toscho style:

const SCOPER_ALL_UPLOADS_EDITABLE = true;

in the global scope, for example in your wp-config.php file.

But you should really consider using up-to-date plugins.

6
  • Thank you; I'll give that a try tomorrow. Is there any recomendation for a plugin that does what role-scoper is doing? I want to be able to restrict certain users to certain pages only? Commented Jun 27, 2015 at 14:04
  • Plugin & theme recommendations are off topic here on WPSE but on the plugin page there's the following notice: Role Scoper is no longer actively developed and the plugin author also mentions the successor plugin. @mathiregister
    – birgire
    Commented Jun 27, 2015 at 15:10
  • Thank you, I upgraded to the new plugin that the author is mentioning (even the paid one) but this feature is still not working. Unfortunately also not with your function. Do you think you can try the "User Role Editor" plugin with a subscriber role and give your function a try. I doesn't work for me. Commented Jun 29, 2015 at 14:56
  • It looks like the constant is called PP_MEDIA_LIB_UNFILTERED in the new version, you could try that in addition to your upload_files capability function. @mathiregister
    – birgire
    Commented Jun 29, 2015 at 15:39
  • Thanks, I updated my question again with my final approach, still no luck. Commented Jun 29, 2015 at 19:47
1

Have you tried adding the unfiltered_upload capability too?

function add_theme_caps() {
    // gets the author role
    $role = get_role( 'subscriber' );

    $role->add_cap( 'upload_files' ); 
    $role->add_cap( 'unfiltered_upload' );
}

add_action( 'admin_init', 'add_theme_caps');
add_action( 'init', 'add_theme_caps');
2
  • I updated my question with my final approach, but with no luck. Commented Jun 29, 2015 at 19:47
  • I tested your updated code. It works fine. May be the plugin you use is conflicting with the code. Try adding priority in the add_action hook add_action( 'admin_init', 'rk_shared_uploads', 15 ); add_action( 'init', 'rk_shared_uploads', 15);
    – Karun
    Commented Jun 30, 2015 at 1:53
-2

I have not tested but the following code will help you please add the following two lines of code to your function.php file

$role= get_role([role_name ]);
$role->add_cap('upload_files');

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.