The handle_upload
hook is called after wp_handle_upload is run, and it sends in a named array consisting of ‘file’, ‘url’ & ‘type’. You could possibly use code like this to utilise it, depending on what you need to achieve:
function process_images($results) {
if( $results['type'] === 'image/jpeg' ) { // or /png or /tif / /whatever
$filename = $results[ 'file' ];
$url = $results[ 'url' ];
// manipulate the image
}
}
add_action('wp_handle_upload', 'process_images');
Edit: If you need the attachment ID as well, it might be better hooking in at a higher level, such as add / edit attachment:
add_action('add_attachment', 'process_images');
add_action('edit_attachment', 'process_images');
in which case the variable sent in is the attachment_id, from which you can derive the rest using something like:
$metadata = wp_get_attachment_metadata( $results );
Related Posts:
- Hook for validating and rejecting frontend image upload
- How can I add an image upload field directly to a custom write panel?
- Difference Between Filter and Action Hooks?
- Which hook should be used to add an action containing a redirect?
- How do you use the plugin boilerplate loader class to hook actions and filters?
- How Do I Load My Action Earlier Enough?
- Does WP fire delete_post when trashed posts are automatically deleted?
- What’s the earliest point I can get the queried object ID?
- How do I Make a Theme “plugin-ready”?
- What’s the difference between hooks, filters and actions? [duplicate]
- How to use filter hook ‘post_updated_messages’ in coherence with action hook ‘save_post’
- Is it possible to create an action hook using do_action() within add_action()?
- How can I hook into existing WordPress Bulk actions?
- Hook event for upload image in the menu
- Define a function outside a class and call the function using action or filter hook
- Create a plugin to change the action to which a function is hooked
- Is there a better way to implement responsive images than what WordPress uses by default?
- Modifying values with add_action to be sent to db
- Woocommerce – Hide a Column in Cart Table
- Which are the hooks run before/after when a category’s deletion?
- Should action callbacks start with a verb?
- Execute Hook on the footer or header after activating a plugin
- Namespaced action and filter tags
- What filter should I use to insert a button inside on Media>Add New
- Prefixing plugin hooks (actions/filters) with a wrapper class or functions
- I have 2 plugins using the same wp_login action hook and one is not working
- Upload multiple images and insert them into custom html code
- How dynamic action login_form_{action} is working
- 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()?
- How to get all queries’s results after they have executed?
- Bug: Post needs to be updated twice when adding action for save_post hook
- When does save_post hook fire on post save/update
- Hook add_attachment error
- Call to undefined function is_home() or any conditional tags
- How to find list of all functions bind to a particular hook from my plugin?
- Can I Hook Into the TinyMCE Insert/Edit Link Button to Use Shortlink For Post?
- Cleaning a filename after image sideloading a url that contains `%20`
- Using init hook for register_taxonomy is causing invalid_taxonomy in wp_insert_term()
- How to move an image in a plugin to the upload directory and make it as a media of wordpress?
- Action / Hook when a new plugin is added
- apply_filters() and call_user_func() to define and call a function outside a class
- WordPress discards PNG file when uploading plugin file
- WordPress Plugin Boilerplate – add actions and/or filters based on user’s role
- remove different admin menu for specific users
- add_option_{$option} action hook not being called
- Does WordPress have something like timer hook?
- How can I set a dynamic value for post_updated_messages based on return value of post_updated?
- Is it possible to convert various image types from remote URLs to WebP and then serve them immediately?
- Insert plugin html content to a specific spot in the frontpage
- Apply function on all action hooks?
- Using “add_image_size” to register custom image sizes inside plugins not working
- Leveraging Core Functionality in Icon Upload Plugin [closed]
- Upload to a specific media folder created by FileBird Lite
- Ninja Forms: Front-End Forms, Post ID?
- Images stored from external API not loading
- How do I remove an action hook inside a class that is called by another class?
- Passing function into add_action always returns the first argument
- Problem in plugin debuging in wordpress
- WordPress Iframe for blog image
- Uploading images to custom table
- Replace the WordPress Media Library Uploader
- do_action from within a class does not seem to work
- OOP development and hooks
- Plugin Development – Call to undefined function comment_exists()
- wp_ajax add_action fuction won’t fire on custom jQuery action
- WordPress Reset password Strength set to medium
- Add_action not calling callback function
- replacing jquery google cdn with a new version dynamically
- Prevent plugin activation and add admin notice
- how to retrieve post_id under woocommerce_add_to_cart_validation hook?
- Changed media upload path for plugin, but generates error & shows wrong url
- How and when would I implement some code which would take data from one part of the Db and put it in another?
- How to destroy or dispose wordpress uploder/manager?
- Unable to show a message after plugin activation
- plugin modal/popup integration best practice
- Function not working on any file other than the main plugin file
- Caption Shortcode: what filter to change the image size?
- Multi hook deploiement
- Can I use a hook other than ‘init’ to handle form submissions?
- action callback, for action dispatched as reported by hook sniffer, not called
- Filter the_content() to add custom figure tags
- Template file structure , wordpress hook for altering the template
- woocommerce single product page hook not working
- Issue on Getting WP Gallery Items In cpt-single.php As Attachments
- Plugin Hook: Get posts
- What is the use of wp_schedule_event hook?
- Displaying $_FILES data (simlar to $_POST)
- Changing upload directory for plugin uploads only
- How do I replace title with my plugin?
- Looking for Hook that is fired after a plugin or wp upgrade is installed/updated
- Get user logged in status from within a plugin. $current_user not defined
- How do you filter get_media_items by mime type in a custom media upload tab?
- Custom filename when pasting an image from clipboard
- Images not displaying on live server
- Sending Parameter Failed
- How wordpress plugin hooks works? [duplicate]
- How to remove a class [closed]
- Woocommerce: block user removing cart item
- how to insert content into wp_head after loop_end
- upload script in plugin development [duplicate]