Back in the day I wrote a function to check for that (you can put it in functions.php and call it from your page):
public function check_if_user_is_author($user_id, $post_id) {
global $wpdb;
$res = $wpdb->get_results($wpdb->prepare("SELECT * FROM " . $wpdb->posts ." WHERE ID = %d AND post_author = %d LIMIT 1", $post_id, $user_id));
if(isset($res) && count($res) > 0) {
return $res[0];
} else {
return false;
}
}
Also, theoretically you could just get the post object and compare the author’s ID with the current logged in user’s ID. Disclaimer: code below is untested.
$current_user_id = get_current_user_id();
$post_data = get_post($your_att_id, ARRAY_A);
$author_id = $post_data['post_author'];
if( $current_user_id == $author_id ) {
// good, current logged-in user is author of attachment
}
Related Posts:
- show author image in posts
- Get attachment ID of author_meta image – Attachment Metadata
- Limit author image size
- get_attachment_id() only get id of first attached image after post update
- Shortcode for a link and thumbnail
- How to remove “Image Information” and “post date/author” from a media page?
- Function to grab specific image IDs from media library.
- Simple Local Avatar Plugin
- How to change image’s author via a function when using GravityForms uploader? [closed]
- List sub pages with custom field content converting image ID to URL
- How to get attachements URL from author meta and display them?
- Each custom image size in custom upload directory?
- How to automatically add rounded corners to thumbnails?
- Get attachment/image info in JS
- Auto-modifying original [full size] images
- How to limit number of images being printer out in “Set Featured Image” pop up?
- Crop image to horizontal or vertical by code based on image size
- Pasting images removes class attribute
- How can I make all gallery images to open in a new window?
- Open the attachment details modal
- Crop image without scaling or resizing with add_image_size()
- Get the comment author ID by the comment ID
- Can’t access ‘Store uploads in this folder’
- Is there a way to pull the first featured image in a loop and not all other featured images?
- Random popup image per user with no repeat
- Speed of the slider images should be increased in wordpress
- Modifying protexted image sizes: use “add_image_size()” or “update_option()”?
- attach unattached featured images to respective posts
- Confusion about arguments sent to add_image_size
- Is it possible to pull and display a single landscape oriented image
- Remove image classes from post thumbnail output
- change the $content_width
- Different image sizes for home and post pages
- Show full image thumbnail
- Make medium_large images available to insert into post
- Removing height and width from images with a caption
- Images not showing on blog
- Why does Google Image Search still display my images?
- Dynamic tagged image galleries
- Image auto resize
- WP fails to upload files to media library, /wp-admin/async-upload.php 403 forbidden
- Add a background image for Custom Post Type archives page
- Images stopped loadding after adding SSl
- Background-image not showing? [closed]
- GoDaddy Number of Image Files Per Directory Exceeded
- Post and featured image have the same name, why is the attachment (image) is showing and not the post?
- Scaling an image in a WordPress post
- Ways to show multiple, separate galleries per post?
- Stop WordPress from cropping images using url parameters
- How to get the Gallery form/section just like in Gutenberg block?
- Add clickable link on an image
- One of my image sizes isn’t showing up in srcset
- Conflict with single and double quotes
- How do I get a smaller size of an avatar image
- When the new post which has no image published, save the specific image as the featured image ( by category )
- download link for uploaded images for wordpress
- How do I link a featured photo to it’s post?
- Force default OG:Image – Yoast SEO [closed]
- Why do I have blury images in WordPress
- Disable save as image on smartphones using all browsers ( chrome, firefox, ie, cm, opera )
- How to get the title of the random images from media library?
- How to indent pictures on WordPress blog? [closed]
- How To Display Author Photo In WordPress without any plugin?
- What is the plugin to import image from URL?
- Allow users to upload multiple images to their profile
- how to change format jpg to webp?
- User uploads image as “Featured Image” but WordPress resizes it?
- Hide Title tag on image Hover
- How to increase media image scale limit?
- Force WordPress to always generate a thumbnail for original image
- How to get the url of the entry in which an image belongs
- How to get the best resolution of image from srcset
- File upload size limit in wordpress and php.ini limit
- How to add php to theme to show alt attributes
- Display Title/Description/Caption of custom images on homepage
- Blank image thumbnails in media library
- Getting extra image links in code with wp_get_attachment_image
- featured image in custom poste type (backend)
- Image Uploader Doesn’t Open Modal in Widget
- Dinamically modifying attributes of images on posts
- Run command to optimize images after they get uploaded to WordPress
- How decrease the size of images which are present in uploads folder?
- Large size is not honoured when inserting image
- The most of the images don’t appear, although URLs are correct
- Add two images with Sweet Testimonials
- Remove “align” attribute on images
- WordPress Images | How to get the cropped image?
- Import existing image as a single post
- How do I change a Themes Header Image?
- Some images 404
- Media Library is not loading on grid view in admin panel
- How can I put pictures next to each other and how can I add a location? [closed]
- How to show file size of featured image? [duplicate]
- Why are some SVG-images not visible in my footer?
- How To Get Feature Image from Blog in Same WordPress Multisite Blog on the Parent Blog?
- WPALLIMPORT Exporting images from repeater field [closed]
- What does WordPress media uploader do to image files on upload?
- Site header logo and parallax image on homepage do not display on iPhone
- image_get_intermediate_size always returns false
- Change of displayed images for webp versions