I am trying to hook into WordPress after the file is uploaded and metadata is created. Currently I am using the following code.
add_action( 'add_attachment', array($this,'ProcessFile') );
public function ProcessFile( $attachment_id )
{
$Images = wp_get_attachment_metadata( $attachment_id );
}
However, $Images returns false which means the metadata has not been created. What hook should I be using to get the metadata of the image?
CodePudding user response:
I have analysis your requirement, you can try to below code and follow instruction:
add_attachment
runs right after an attachment is added to your website database and before the metadata have been generated. If you don't need the value to be in the database yet, you can use the wp_generate_attachment_metadata
filter to hook in. However, if you need the data to be in the database already, you'll have to use updated_post_meta
and check that the meta_key
passed in equals _wp_attachment_metadata
.
CodePudding user response:
add_attachment runs right after an attachment is added to the DB, but but before the metadata is generated. If you don't need the value to be in the database yet, you can use the wp_generate_attachment_metadata filter to hook in. However, if you need the data to be in the database already, you'll have to use updated_post_meta and check that the meta_key passed in equals _wp_attachment_metadata.