Menu Adam R Brown

WP hooks navigation: Home/browseActions indexFilters index

Source View: image_downsize

To save our bandwidth, we show only a snippet of code around each occurence of the hook. View complete file in SVN (without highlighting).

Understanding Source Code

The best way to understand what a hook does is to look at where it occurs in the source code.

Remember, this hook may occur in more than one file. Moreover, the hook's context may change from version to version.

Source View

This hook occurs 2 times in this file.

Line Code
203       * down-sizing the image, returning that value instead.
204       *
205       * @since 2.5.0
206       *
207       * @param bool|array   $downsize Whether to short-circuit the image downsize.
208       * @param int          $id       Attachment ID for image.
209       * @param string|int[] $size     Requested image size. Can be any registered image size name, or
210       *                               an array of width and height values in pixels (in that order).
211       */
212      $out = apply_filters( 'image_downsize', false, $id, $size );
213
214      if ( $out ) {
215           return $out;
216      }
217
218      $img_url          = wp_get_attachment_url( $id );
219      $meta             = wp_get_attachment_metadata( $id );
220      $width            = 0;
221      $height           = 0;
 
Line Code
4622           /*
4623            * Loop through all potential sizes that may be chosen. Try to do this with some efficiency.
4624            * First: run the image_downsize filter. If it returns something, we can use its data.
4625            * If the filter does not return something, then image_downsize() is just an expensive way
4626            * to check the image metadata, which we do second.
4627            */
4628           foreach ( $possible_sizes as $size => $label ) {
4629
4630                /** This filter is documented in wp-includes/media.php */
4631                $downsize = apply_filters( 'image_downsize', false, $attachment->ID, $size );
4632
4633                if ( $downsize ) {
4634                     if ( empty( $downsize[3] ) ) {
4635                          continue;
4636                     }
4637
4638                     $sizes[ $size ] = array(
4639                          'height'      => $downsize[2],
4640                          'width'       => $downsize[1],