Try this way, should work well
function cpt_from_attachment($attachment_ID)
{
global $current_user;
get_currentuserinfo();
$attachment_post = get_post( $attachment_ID );
$type = get_post_mime_type($attachment_ID);
// DO WHAT YOU NEED
}
add_action("add_attachment", 'cpt_from_attachment');
Related Posts:
- Send an e-mail notification to custom user role when a file is uploaded to uploads folder
- Intercept request to /wp-content/uploads/random.file
- wp.media add context
- Hook to get image filename when it is uploaded
- File names are being overridden when uploading new media
- Change the look of the media uploader
- Featured image to grayscale with PHP imagefilter – which hook to use?
- Making Site A Use Site B’s wp-content Folder
- Modify upload directory to use post category slug in file path on multisite installation
- Passing a parameter to filter and action functions
- Difference Between Filter and Action Hooks?
- How to know what functions are hooked to an action/filter?
- Get a list of all registered actions
- Plupload Intergration in a meta-box?
- what is correct way to hook when update post
- Is there a hook that runs after a user logs in?
- how to limit search to post titles?
- How to enqueue scripts on custom post add/edit pages?
- How can I edit post data before it is saved?
- Difference between do_action and add_action
- Trigger refresh for new media manager in 3.5
- Physical organization of wordpress media library (Real Media Library plugin)
- Can I upload media to a specific folder?
- wp_upload_dir how to get just the directory name .
- How to generate thumbnails when needed only?
- Trouble understanding apply_filters()
- Limit image upload to one and disable audio, video and other document file types to upload
- How to add new tab to media upload manager with custom set of images?
- How can I see all the actions attached to an “add_action” hook?
- No Thumbnails Generated
- Which hook should be used to add an action containing a redirect?
- Media files exist in upload folder but not showing up
- How to Require a Minimum Image Dimension for Uploading?
- How to upload files straight to S3 without using local storage? [closed]
- Extend Media Library
- How does WP media uploader create the 3 different sized images, and how can I duplicate it
- How to make “Upload files”selected by default in Insert Media?
- get_template_part vs action hooks in themes
- Why do some hooks not work inside class context?
- WordPress 3.5: Setting custom “full URL path to files” in the Media Library?
- Get $image_id after uploading with media_sideload_image()
- Difference between after_setup_theme and init action hooks?
- simple solution for restricting access to (some) uploads/downloads
- what happens to existing media files when I switch to year/month directory structure format?
- Reject upload of wrong-sized images using the Media Uploader
- Is there any action filter/hook for validating a custom field before publishing the post?
- WordPress Media Uploader events
- Trigger custom action when setting button pressed
- How to show all available images in WP’s media library when using the Polylang plugin?
- how to upload and allow downloads of .mobi and .epub formats
- Upload post thumbnail from the front end
- Allowing WebP uploads?
- Please explain how these hooks work
- How many filter/action hooks are healthy?
- Give users a maximum upload capacity; limit the number of files a user can upload OR limit the number of files per upload
- How to add a custom field to the media screen (image/gallery)?
- Can’t upload media, permissions are correct
- Earliest hook to reliably get $post/$posts
- How to assign multiple file-mime-types to extension?
- Saving Media – Which Hook is Fired?
- Set limit to media upload?
- Is it possible to reorganize the WordPress uploads directory?
- WordPress 3.5: Switch back to Old Media Uploader?
- Save camera info as metadata on image upload?
- Media upload finished hook
- Users can’t upload images on frontend if they haven’t got access to the wp backend
- How to upload SVG in WordPress 4.9.8?
- Hook after image is uploaded and image sizes generated
- How Can I Organize the Uploads Folder by Slug (or ID, or FileType, or Author)?
- How can I batch delete all unattached images with WP-CLI or other automated process?
- What does (10, 2) mean when used with add_filter
- Create image formats with different qualities when uploading
- Rename files during upload using variables
- Is there a hook which fires after all thumbnails are generated?
- upload_async.php returns 500 error
- Which filters or actions to use after a media upload and delete?
- add_action(‘wp_ajax_[action name]’, myfunction) problem
- Organize uploads by year, month and day
- WordPress Multisite: Adding actions to only one site
- wp_delete_attachment doesn’t delete images in wp-content/uploads/
- Display attachments by ID in a wp.media frame
- Force WordPress 3.3 to use Flash uploader
- Use a separate custom table (not posts) to handle file upload data
- How to only hook on Single.php after content?
- Upload folder is not writable, even when permissions are correct
- Different upload directory based on post type in a theme
- Media not actually deleted on disk when click “Permanent Delete”
- Image upload callback in new 3.5 media
- How to remove action hook done in a plugin from functions.php in my theme?
- retrieve custom image sizes from media uploader javascript object
- Valid characters for actions, hooks and filters
- Add inline uploader to plugin option page
- Protecting direct access to PDF and ZIP unless user logged in (without plugin)
- How to wp_upload_bits() to a sub-folder?
- How to check if a hook is hooked or not?
- Using same directory for storing all uploaded images on a WordPress network
- Insert images to post not working
- Extract image from content and set it as the featured image
- trigger save_post event programmatically
- Is it possible to allow zip files to be uploaded in WordPress?