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
- add_action(‘wp_ajax_[action name]’, myfunction) problem
- Use a separate custom table (not posts) to handle file upload data
- WP 3.3 > Still no option to enable automatic image overwrites?
- Custom upload directory per CPT; when removed, file not deleted
- Modify featured image path to Amazon S3
- How to set an upload directory for each media type?
- How to protect uploads in multisite if user is not logged in?
- uploading files to the uploads folder via ftp
- admin_post hook not called
- Remove upload_files capability from a role but allow role to manage an avatar image
- 3.5 media manager add CSS / JS to new ‘tab’ iframe content
- Please explain me what the do_action does
- post_id missing from the wp-admin file upload request
- How can I upload a csv file into WordPress?
- How to link to the image editor’s Edit Image function?
- Use latest jQuery in WordPress (admin interface)
- What hook should be used to programmatically create a post only when master post is updated?
- Image uploading stuck on “crunching”
- “upload_mimes” filter not working. Need to allow WOFF and WOFF2
- Whole bunch of errors on WP website – media upload, edit slugs, edit screen not working [closed]
- Retroactively place uploaded media into -month, -year based folders?
- Can’t seem to upload a file to a custom directory
- What are the benefit in adding hook in the init() hook?
- Conditional add_filter for upload directory?
- Need to download uploaded binary file
- Insert Image automatically when upload finishes wordpress media uploader
- How do I modify the url of uploaded media content?
- WordPress “HTTP error.” when uploading Media – IIS
- Where to hook my plugin’s action
- What’s hook to use immediately after a user is authentcated [duplicate]
- Uploading images on front end doesn’t generate thumbnail sizes
- Adding Media Upload to Custom Options Panel breaks “Insert into Post”
- WordPress bug with capabilities?
- How to get all of the activate_plugin action parameters?
- Prefixing plugin hooks (actions/filters) with a wrapper class or functions
- Trigger a custom function when option are saved in admin area
- Adding buttons to Add New Post and Add New Page
- Manipulate CSV data during upload, is it possible?
- Execute JavaScript in WordPress Hook
- How to submit data between wp_iframe and backbone.js in media upload
- What are best practices to storing uploads in WordPress?
- How to display message (with switch_theme hook) after deactivating My theme?
- Original image not saving?
- Restrict role to view own media
- What action hook can I use to add a JavaScript to a page post using a theme template that is not including get_header() nor get_footer()?
- Is it possible to add the_content filter upon login?
- Create featured image from a remote url when creating a post
- What hook is the currently active theme’s functions.php file loaded on? [duplicate]
- Image resizing – TimThumb vs convert on upload?
- Why do plugins often ask to add in to templates?
- Issue with images which have no sizes available
- Is it safe to upload JSON files to upload folder?
- How to catch wordpress post ID when it’s published
- How can I collect and output all attributes of all executed ShortCodes?
- Unable to upload file more than 1MB in size
- password_reset doesnt work
- Thumbnail images missing in WP media library
- Advanced WordPress plugin activation detection
- Using Windows Server 2012 How to Move Uploads Folder to another hard drive
- Can I Hook Into the TinyMCE Insert/Edit Link Button to Use Shortlink For Post?
- get_attached_file returns wrong path after changing media upload dir
- How to adapt upload_dir to save files outside of WP uploads folder
- Reattach media after moving to another server
- All my files are on my blog! I need sync solution
- How to call do_action() to pass arguments to hooked functions that take different number of args?
- media file uploading
- What is wrong with my wp_insert_attachment code?
- Editor User Role can’t see other users media
- How to allow .ged file uploads
- taxonomy_edit_form_fields output after term fields
- Media files not loading
- Check if front page within function passed to action
- Set attachment category from file name on upload
- HTTP Error WordPress on IIS uploading image
- What folder to place Large Video files?
- add_option_{$option} action hook not being called
- $new_pass always returns null – password_reset hook
- Why can’t I shove an instance of a class into a variable from a do_action hook?
- Move jQuery on *top* of footer
- Passing a parameter to filter and action functions
- Failed to load resource at admin screen
- Make custom thumbnail size image in media_sideload_image function
- Upload more than one media files with a post
- Removing action from template class
- uploading photos
- Single file upload
- OOP Plugin: Where should I place the action hooks in the class?
- Add frontend editor with media buttons for Visitors and display only their media
- WordPress Custom Fonts Problem! [closed]
- I want to customize wp.media (the wordpress admin uploader) in order to change the file name but only in video custom post type
- Updating Media Library PDF’s in bulk
- Assign multiple categories to Media Library upload