Turns out I solved my own question with help from a colleague. The two filters that get called after media is uploaded or when media is being edited are; ‘add_attachment’ and ‘edit_attachment’. Here is the code I am using, I then check to see if the attachment is an image (code omitted from example).
function analyse_attachment($attachment_ID)
{
$attachment = get_attached_file($attachment_ID); // Gets path to attachment
update_post_meta($attachment_ID, "image_rgb", $the_colour);
}
add_action("add_attachment", 'analyse_attachment');
add_action("edit_attachment", 'analyse_attachment');
Obviously I’ve omitted some stuff that isn’t relevant to the question. But that code gets called right after you’ve uploaded or edited an attachment.
Related Posts:
- How can I get full attachment url from wp_get_attachment_metadata?
- submit two file input fields in the same form
- How to Insert images in WordPress using code
- How to show post attachment image
- What’s the preferred method of writing AJAX-enabled plugins?
- Redesigning Custom Post Type “Add New” page
- How to stop showing admin notice after close button has been clicked
- How to save the values of checkbox to the register setting?
- Handling jQuery Component Collision
- How to get Login Error messages on a custom template
- Finding WordPress sites using my plugins
- Enqueue style inside shortcode but its loaded at the bottom of page (before footer scripts)
- How do I check if my $wpdb->insert() was successful?
- Claim Listing functionality – how to send email to users when their claim has been approved or denied
- Creating a theme option page?
- WordPress 4.0 Cookie Authentication to avoid nonce error when publishing a post and page
- Add post thumbnail from external image with plugin
- Where is the source code that makes the “all” array grabs filters in the $wp_filter?
- How to Build a Movie Library in WordPress 3.x
- Options page not displayed under Settings menu
- Is it possible to add an action to the currently running action?
- How to include and use custom class files in plugin?
- Action on post publish
- How to prevent action in ajax request, when in admin side?
- Only execute jQuery function(on document ready) on the page has shortcode from plugin [duplicate]
- unzip a folder on specific location and delete the zip file
- Plugin not appearing after uploading it via FTP
- Any Short code Availble for Get Post List With Thumbnail Plugin?
- Changing labels of status filters for post grid
- Where to call add_shortcode function in WordPress Plugin Boilerplate?
- Plugin version is not showing up in wordpress.org plugin directory
- Own plugin corrups plugin-activation
- wordpress plugin is not activating from widget
- CSV file generation failing
- finding whether request is for post, and post id
- How to get specific setting by settings_fields()?
- Save / Show multi line text in metabox
- Prevent duplicate records in plugin table
- How to fetch products with the price in a page on woocommerce using a form or live search with php
- Owl Carousel2 image not displaying full width when using Stretch row and content, Stretch row and content(no padding) in wordpress
- Get Time Taken By Each Action Hook in WordPress
- Best way to initiate a class in a WP plugin?
- Buidling a translate plugin for wordpress
- Force language in translate function
- wp_footer hook only working on homepage not in other pages
- How to create a child/addon plugin
- How to secure the release of WordPress plugins / avoid copying plugins?
- How do I combine a theme with a plugin
- Use wp-config.php constants in all files of plugin
- how to force tag page layout to use same as search layout?
- Delay JavaScript files from loading
- Prevent direct access to WordPress plugin assets?
- Using ACF default value to autoincrement a number field
- a href adds default URL with the given echo URL
- Gutenberg Block Style CSS Class Is Not Applying on Backend
- plugins_url() works everywhere but wp_reqister_script()
- Integrating boxtal PHP library into a custom WordPress Plugin
- Images under 1MB are not being compressed
- Sanitize $_GET variable when comparing
- Where can I save plugin data?
- show my own admin_notices after a post has been published
- How to add a WordPress Nonce for this form to avoid CSRF
- Overriding current theme files via plugin
- How to create a plugin that includes all the other plugins?
- How to add update function to plugin without adding it to https://wordpress.org/plugins/ [closed]
- WordPress custom plugin that uses woocommerce enabled payment gateway for payment [closed]
- How to call external functions from a PHP script in a WordPress plugin?
- How to edit link for comment count
- Integrating Custom Database with WordPress
- How to get Recent Post From Each Category with Thumbnail?
- Need to know if my approach to designing a geneaology plug-in for wordpress makes sense
- How use wp_insert_post and add og:custom tags?
- How to change “Read More” text?
- Creating one user access account for all the multiple sites
- Using id to show item
- How to use wp_editor and save its data in wp_posts table
- My WordPress activation hook isn’t working
- wpdb update method is updating but not refreshing the current page data
- Shortcode and WP query using category attributes
- Securing a plugin pop-up window
- Is admin section completely customizable in terms of styling?
- WordPress ajax error 400 bad request for sending data to remote site [duplicate]
- Better way to run heavy scripts using WordPress database
- how to check plugin name unique or not?
- Attachments plugin cannot click media library button [closed]
- Creating a user ‘add custom field’ section
- WordPress ajax not working in registration
- Can a developer adopt a plugin marked as “not updated in over 2 years”?
- How wordpress plugin hooks works? [duplicate]
- Post curl function save twice using plugin hook function wordpress
- get_option returning a different value from what’s saved
- Plugin: Custom menu item problem
- Getting warning of Missing argument 2 for wpdb::prepare()
- Jquery post responses 500 error after some time and lastly an 503 error
- How can I delete the options from DB when the plugin is deleted?
- How can I make my plugin detect if a certain theme is active?
- Is it possible to create post in wordpress using postman?
- wp_enqueue_script doesn’t load JS in plugin
- AI Code For OpenAI
- Pulsing circle before the post title (Breaking news flash)