I'm trying to upload photos from the Media Uploader from the wp_editor
. This works fine but I'm trying to only allow users to view images that they are the author for. Here is the code I'm using to do this:
//restrict authors to only being able to view media that they've uploaded
function ik_eyes_only( $wp_query ) {
//are we looking at the Media Library or the Posts list?
if ( strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/upload.php' ) !== false
|| strpos( $_SERVER[ 'REQUEST_URI' ], '/wp-admin/edit.php' ) !== false ) {
global $current_user;
$wp_query->set( 'author', $current_user->id );
}
}
//filter media library & posts list for authors
add_filter('parse_query', 'ik_eyes_only' );
add_action('pre_get_posts','ml_restrict_media_library');
function ml_restrict_media_library( $wp_query_obj ) {
global $current_user, $pagenow;
if( !is_a( $current_user, 'WP_User') )
return;
if( 'admin-ajax.php' != $pagenow || $_REQUEST['action'] != 'query-attachments' )
return;
if( !current_user_can('manage_media_library') )
$wp_query_obj->set('author', $current_user->ID );
return;
}
This works great and the images are filtered both from within the upload.php in the dashboard and on the front end from a page. However, if I try and upload a file from upload.php page within the dashboard, the file uploads successfully. When I do it from the wp_editor though I get an error saying An error occurred in the upload. Please try again later.
.
Why would this upload from the admin dashboard but not from my front end page?