wp_generate_attachment_metadata filter-hookWP 2.1.0

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_generate_attachment_metadata
WP_REST_Attachments_Controller::finalize_item()
wp_generate_attachment_metadata
wp_update_image_subsizes()
wp_generate_attachment_metadata
wp-admin/includes/image.php 750
return apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id, 'create' );
wp-includes/rest-api/endpoints/class-wp-rest-attachments-controller.php 3400
$metadata = apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id, 'update' );
wp-admin/includes/image.php 185
$image_meta = apply_filters( 'wp_generate_attachment_metadata', $image_meta, $attachment_id, 'update' );

Where the hook is used in WordPress

Usage not found.