To let the current users only view his/her uploaded attachments, add the following code to your themes actions:
add_filter( 'posts_where', 'devplus_wpquery_where' );
function devplus_wpquery_where( $where ){
global $current_user;
if( is_user_logged_in() ){
// logged in user, but are we viewing the library?
if( isset( $_POST['action'] ) && ( $_POST['action'] == 'query-attachments' ) ){
// here you can add some extra logic if you'd want to.
$where .= ' AND post_author=".$current_user->data->ID;
}
}
return $where;
}
Hope this helps!
Related Posts:
- Programmatically adding images to media library
- Uploaded images don’t show in Media Library if there are special characters in IPTC Keywords
- Regenerate missing _wp_attachment_metadata
- Get images attached to a specific page
- WordPress Attachments with old images
- How can I use an image from an external source without uploading it to the media library
- how to get original image using wp_get_attachment_image_src
- Can I attach image to post without adding it to post?
- How to delete resized (cropped) image uploads and prevent future resizing?
- How to find attachment by it’s name?
- How do I delete all generated images from my server except those currently used in posts
- Theme Customiser Image Control
- Get attachment ID of author_meta image – Attachment Metadata
- Remove duplicate images from media library.
- Separate attachment images from post loop
- copy attachment title to description and alt text
- Get an image from url in front end submission form
- Open the attachment details modal
- How do I delete thousands of unattached images?
- Why would image paths in wordpress suddenly change?
- Get post embedded image caption
- Rename attachments during upload
- Regex to turn embedded images in to attachments
- Re-process Images
- Show prev and next post links for parent post of current image in attachment page?
- Why can’t I edit certain images from the WordPress Media library?
- Uploading images: ‘ø’ get replaced with ‘ø’
- Make alt text required when setting a featured image
- How to make programmatic image upload generate thumbnail and sizes?
- Best way to strip character entities (%20 etc)
- Display one random image, but only if landscape
- Display latest 12 images from media library
- Get full image array
- How to change image url?
- Bulk image rotation
- Link to full size image or attachment page in photo theme
- get the image of the post
- add the post as canonical for attachment page wordpress
- media_sideload_image with rewritten urls?
- How to order images in a post in WordPress 3.3?
- Check if the image exists in WordPress media library
- How to output images as figure/figcaption
- Out of memory error reporting
- Multiple images in one attachment page
- WordPress adds extra width to post images container boxes
- Handling image uploads without thickbox
- Customizing the attachement page to show rest of all images in a gallery from post
- Is it possible to split Default WP Media directory to multiple Folder/Subdomain?
- Images attached to posts from library link to 404 error page
- Help to upload post attachments from Ajax
- Images uploaded to the media library has strange colors. However, in the edit screen the color is ok
- Alter image meta fields in the Media Library
- Add custom text in the media library image meta area
- How to add images to a post without inserting them into the content area of the post editor?
- Uploaded images not displaying in network site
- Unable to upload images to the Media Library. Getting this erron on the console wp-admin/async-upload.php 403 (Forbidden)
- How to limit the number of images displayed in the media window?
- Call to undefined function wp_generate_attachment_metadata()
- How do you import images from a URL in your post?
- Create a post from every image in my media gallery
- Retrieve Image Attachments Getting Post Thumbnail Image First
- Auto delete pictures in media library by age
- Images not showing in media grid view (but showing in list view)
- How to get the title of the random images from media library?
- How to get image URL from media_sideload_image?
- How to test if there are no more previous or next image on attachment page?
- Show last 12 uploaded images on home page, but only from posts
- How to change the value “uploaded to” in the media library (WordPress 4.0)
- Excluding post thumbnail from the attachment.php when using wordpress gallery
- Output posts attached images as thumbnails linked to full-size with lightbox class
- Get an image from the media library. Struggling with the code?
- Allow wp media library to check already selected images displayed in div
- Custom image size not displaying with wp_get_attachment_image()
- unsharp thumbnails after uploading image
- Post-processing of the image failed
- After moving a site to new hosting, not all images are showing in media library
- Blank image thumbnails in media library
- How to handle a lot of media files in the uploads folder? (+10.000)
- Broken images in media library
- Get “Image CSS Class” value from the Advanced Options section
- Uploaded images not showing properly using wordpress
- After I upload a file to library its name converted to dashes
- add titles to images in ad media in pages and posts
- attachment.php & flexslider—linking thumbnail to specific image
- Surround uploaded image link with div
- Setting name of attachment URL
- Show title when inserting single images
- Broken Media Library
- Upload unnattached image from frontend
- Image attachement management – a philosophical question
- greater flexibility in targeting images attached to page
- Stop Attachment image names from taking top level permalink
- How do I change a Themes Header Image?
- Media Library is not loading on grid view in admin panel
- Blurry Images WordPress 5.8.1
- Remote Image (from URL) as Media Library element
- What does WordPress media uploader do to image files on upload?
- How to get WordPress to resize images for srcset?
- Is there a way to upscale a media library original image to the nearest whole pixel in WordPress?
- How to make Media Library files private?