wp_generate_attachment_metadata
Filters the generated attachment meta data.
Usage
add_filter( 'wp_generate_attachment_metadata', 'wp_kama_generate_attachment_metadata_filter', 10, 3 );
/**
* Function for `wp_generate_attachment_metadata` filter-hook.
*
* @param array $metadata An array of attachment meta data.
* @param int $attachment_id Current attachment ID.
* @param string $context Additional context. Can be 'create' when metadata was initially created for new attachment or 'update' when the metadata was updated.
*
* @return array
*/
function wp_kama_generate_attachment_metadata_filter( $metadata, $attachment_id, $context ){
// filter...
return $metadata;
}
- $metadata(array)
- An array of attachment meta data.
- $attachment_id(int)
- Current attachment ID.
- $context(string)
- Additional context. Can be 'create' when metadata was initially created for new attachment or 'update' when the metadata was updated.
Changelog
| Since 2.1.0 | Introduced. |
| Since 5.3.0 | The $context parameter was added. |
Where the hook is called
wp_generate_attachment_metadata
wp-admin/includes/image.php 750
return apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id, 'create' );
wp-admin/includes/image.php 185
$image_meta = apply_filters( 'wp_generate_attachment_metadata', $image_meta, $attachment_id, 'update' );