save_post_attachment not working

In short, save_post_attachment doesn’t work and, instead, you need to use edit_attachment.

We ran into an issue when we built an input that would allow users to allow certain media files to be downloaded while prohibiting others. However, when we tried to hook into the save_post_custom_post_type action, by adding the WordPress function below, to update a post meta value, we kept running into issues. The save_post_attachment hook does not work.

// THIS DOES NOT WORK
add_action( 'save_post_attachment', array( $this, 'save_attachment_meta_box_data') );

It turns out, save_post_attachment does not work! Instead, you need to use the edit_attachment hook (visible below):

// THIS WORKS
add_action( 'edit_attachment', array( $this, 'save_attachment_meta_box_data') );

Leave a Reply

Your email address will not be published. Required fields are marked *