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?
- add_action hook for completely new post?
- Checking if a file is already in the Media Library
- WordPress Hook for user register
- Which action for triggering cron “wp”or “init”?
- How to implement add_image_size in a plugin
- Changing upload directory for plugin uploads only
- Upload file to remote storage
- Actions or filters fired when data is saved in a custom table
- How to check if certain plugin exists and in expected version
- Add media and attach images to pages
- How to redirect to action on custom page within admin section
- How to display a message about updates in the plugin list
- How to run an add_action hook for specific page
- Why my database table not created on activation?
- wp_transition_post_status does not change the status of the post
- action hook wp_head higher priority as all other plugins/hooks
- Act on user meta updated, but only once
- Resizing Images for a Gallery-Plugin?
- Files automatically added
- Custom delete option button in plugin settings
- Tried in different ways but sidebar not working?
- conditionally load javascript & CSS for do_action() calls from plugin
- Send push when new post is published in a certain category
- use of do_action() without any functions attached
- Odd map_meta_cap $args on post edit — sometimes integer, sometimes string
- How can I create a custom plugin that allows anonymous users to signup without registering?
- Bind a function with its own argument to show something dynamically after every content
- Uploaded attachment not set as featured image
- What’s the hook for filtering every texts of site?
- Associate multiple email addresses with the same user account, so they can log in with either
- Update variable value via add_filter
- Custom filter not working
- hook update_option/updated_option empty $old_value and $value
- Configure WordPress to Generate Scheme-less Relative URLs
- How to list all images used on a specific page?
- Screenshots on plugin page taken old [closed]
- Insert and read media from the WordPress library and call in the plugin
- WordPress5.2.3: Better File Download Plugin validation issue
- how to retrieve post_id under woocommerce_add_to_cart_validation hook?
- Changed media upload path for plugin, but generates error & shows wrong url
- Multi hook deploiement
- action callback, for action dispatched as reported by hook sniffer, not called
- What is the use of wp_schedule_event hook?
- Sending Parameter Failed
- get_term_by() returning null on plugin
- Load images from CDN and custom features to “Add Media” dialogue