I want users to be able to upload photos using 'upload_files' but in their profile page, the Media Library shows every image that's been uploaded by every user. How can I filter that so that they can only view the images THEY uploaded themselves?
I want users to be able to upload photos using 'upload_files' but in their profile page, the Media Library shows every image that's been uploaded by every user. How can I filter that so that they can only view the images THEY uploaded themselves?
<?php
/*
Plugin Name: Manage Your Media Only
Version: 0.1
*/
//Manage Your Media Only
function mymo_parse_query_useronly( $wp_query ) {
if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/upload.php' ) !== false ) {
if ( !current_user_can( 'level_5' ) ) {
global $current_user;
$wp_query->set( 'author', $current_user->id );
}
}
}
add_filter('parse_query', 'mymo_parse_query_useronly' );
?>
Save code above as manage_your_media_only.php, zip it, upload as plugin to your WP and activate it, that's all.
Hi Bruha,
Thank you very much for your reply.
I've tried your plugin, but I get 2 problems:
1) the plugin-code is visible on the top of my website
2) my admin is gone. If I go to http://www.mydomain.com/wp-admin/ looks like this on my screen:
_______________
<?php
/*
Plugin Name: Manage Your Media Only
Version: 0.1
*/
//Manage Your Media Only
function mymo_parse_query_useronly( $wp_query ) {
if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/upload.php' ) !== false ) {
if ( !current_user_can( 'level_5' ) ) {
global $current_user;
$wp_query->set( 'author', $current_user->id );
}
}
}
add_filter('parse_query', 'mymo_parse_query_useronly' );
?>
Warning: Cannot modify header information - headers already sent by (output started at .../wp-content/plugins/manage_your_media_only.php:9) in .../public_html/wp-includes/pluggable.php on line 890
_______________
I deactivated all other plugins.
Am I doing something wrong.
I really appreciate your help.
Thank you very much in advance!
Arthur
i made it for your and check it, try this manage_your_media_only.zip
Hi bruha! Thank you, I was looking for this!
But when I use WordPress featured images, the Media Gallery tab still shows all Media Uploaded from all users, thus I can edit them too (like changing caption of an image)..
any ideas?
Hello everyone,
I managed to install this as well, since i'm here with the same problem, but the link 'unattached images' in the media library still shows all images by everyone. Thats a bit odd! Any idea on how to fix that? can't find anything i'm looking for an hour already.
Thanks
bruha - I used your code and it seems to work perfectly, thanks.
This topic has been closed to new replies.