wp_calculate_image_srcset_meta

Let plugins pre-filter the image meta to be able to fix inconsistencies in the stored data.

Description

apply_filters( 'wp_calculate_image_srcset_meta', (array) $image_meta, (array) $size_array, (string) $image_src, (int) $attachment_id ); 

Parameters (4)

0. $image_meta (array)
The image meta data as returned by wp_get_attachment_metadata()..
1. $size_array (array)
Array of width and height values in pixels (in that order).
2. $image_src (string)
The src of the image.
3. $attachment_id (int)
The image attachment ID or 0 if not supplied.

Usage

To run the hook, copy the example below.
  1. $image_meta = apply_filters( 'wp_calculate_image_srcset_meta', $image_meta, $size_array, $image_src, $attachment_id ); 
  2.  
  3. if ( !empty( $image_meta ) ) { 
  4.  
  5. // everything has led up to this point... 
  6.  
  7.  
The following example is for adding a hook callback.
  1. // define the wp_calculate_image_srcset_meta callback 
  2. function filter_wp_calculate_image_srcset_meta( $image_meta, $size_array, $image_src, $attachment_id ) { 
  3. // make filter magic happen here... 
  4. return $image_meta
  5. }; 
  6.  
  7. // add the filter 
  8. add_filter( 'wp_calculate_image_srcset_meta', 'filter_wp_calculate_image_srcset_meta', 10, 4 ); 
To remove a hook callback, use the example below.
  1. // remove the filter 
  2. remove_filter( 'wp_calculate_image_srcset_meta', 'filter_wp_calculate_image_srcset_meta', 10, 4 ); 

Defined (1)

The filter is defined in the following location(s).

/wp-includes/media.php  
  1. $image_meta = apply_filters( 'wp_calculate_image_srcset_meta', $image_meta, $size_array, $image_src, $attachment_id );