I want to list images for only user uploaded image. Here is the scenario:
- Using the image uploader on front end using iframe.
- I have added
upload_files
cap to subscriber level users and want them to see only images they uploaded. -
I’ve found this Q Restricting users to view only media library items they have uploaded? but the accepted answer not working for me.
// Code originally by @t31os add_action('pre_get_posts','users_own_attachments'); function users_own_attachments( $wp_query_obj ) { global $current_user, $pagenow; if( !is_a( $current_user, 'WP_User') ) return; if( 'upload.php' != $pagenow ) return; if( !current_user_can('delete_pages') ) $wp_query_obj->set('author', $current_user->id ); return; }
-
The frontend page i am using the image uploader is named “Entry”.
- If i remove this part of the code
if( 'upload.php' != $pagenow ) return;
the code works. I i think i have to improve that part of the conditional code but could not figure it out. The conditional is important because i don’t want the code to apply on other pages where it not required.
So, i need help to improve the conditional part as i mentioned. Thanks!