From d3aa6097409f37ea184dea29d247792470a4657e Mon Sep 17 00:00:00 2001 From: Drew Jaynes Date: Thu, 20 Feb 2014 06:26:51 +0000 Subject: [PATCH] Inline documentation for hooks in wp-admin/includes/image.php. Props theorboman, kpdesign. Fixes #25832. git-svn-id: https://develop.svn.wordpress.org/trunk@27202 602fd350-edb4-49c9-b593-d223f7449a82 --- src/wp-admin/includes/image.php | 85 +++++++++++++++++++++++++++++++-- 1 file changed, 81 insertions(+), 4 deletions(-) diff --git a/src/wp-admin/includes/image.php b/src/wp-admin/includes/image.php index 61f527a569..23cce463b8 100644 --- a/src/wp-admin/includes/image.php +++ b/src/wp-admin/includes/image.php @@ -102,6 +102,13 @@ function wp_generate_attachment_metadata( $attachment_id, $file ) { $sizes[$s]['crop'] = get_option( "{$s}_crop" ); // For default sizes set in options } + /** + * Filter the image sizes automatically generated when uploading an image. + * + * @since 2.9.0 + * + * @param array $sizes An associative array of image sizes. + */ $sizes = apply_filters( 'intermediate_image_sizes_advanced', $sizes ); if ( $sizes ) { @@ -155,6 +162,14 @@ function wp_generate_attachment_metadata( $attachment_id, $file ) { if ( isset( $metadata['image']['data'] ) ) unset( $metadata['image']['data'] ); + /** + * Filter the generated attachment meta data. + * + * @since 2.1.0 + * + * @param array $metadata An array of attachment meta data. + * @param int $attachment_id Current attachment ID. + */ return apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id ); } @@ -268,7 +283,13 @@ function wp_read_image_metadata( $file ) { } } - // fetch additional info from exif if available + /** + * Filter the image types to check for exif data. + * + * @since 2.5.0 + * + * @param array $image_types Image types to check for exif data. + */ if ( is_callable( 'exif_read_data' ) && in_array( $sourceImageType, apply_filters( 'wp_read_image_metadata_types', array( IMAGETYPE_JPEG, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM ) ) ) ) { $exif = @exif_read_data( $file ); @@ -316,6 +337,15 @@ function wp_read_image_metadata( $file ) { $meta[ $key ] = utf8_encode( $meta[ $key ] ); } + /** + * Filter the array of meta data read from an image's exif data. + * + * @since 2.5.0 + * + * @param array $meta Image meta data. + * @param string $file Path to image file. + * @param int $sourceImageType Type of image. + */ return apply_filters( 'wp_read_image_metadata', $meta, $file, $sourceImageType ); } @@ -337,7 +367,6 @@ function file_is_valid_image($path) { * Validate that file is suitable for displaying within a web page. * * @since 2.5.0 - * @uses apply_filters() Calls 'file_is_displayable_image' on $result and $path. * * @param string $path File path to test. * @return bool True if suitable, false if not suitable. @@ -351,7 +380,15 @@ function file_is_displayable_image($path) { else $result = true; - return apply_filters('file_is_displayable_image', $result, $path); + /** + * Filter whether the current image is displayable in the browser. + * + * @since 2.5.0 + * + * @param bool $result Whether the image can be displayed. Default true. + * @param string $path Path to the image. + */ + return apply_filters( 'file_is_displayable_image', $result, $path ); } /** @@ -384,7 +421,16 @@ function load_image_to_edit( $attachment_id, $mime_type, $size = 'full' ) { break; } if ( is_resource($image) ) { - $image = apply_filters('load_image_to_edit', $image, $attachment_id, $size); + /** + * Filter the current image being loaded for editing. + * + * @since 2.9.0 + * + * @param resource $image Current image. + * @param string $attachment_id Attachment ID. + * @param string $size Image size. + */ + $image = apply_filters( 'load_image_to_edit', $image, $attachment_id, $size ); if ( function_exists('imagealphablending') && function_exists('imagesavealpha') ) { imagealphablending($image, false); imagesavealpha($image, true); @@ -411,12 +457,43 @@ function _load_image_to_edit_path( $attachment_id, $size = 'full' ) { if ( $filepath && file_exists( $filepath ) ) { if ( 'full' != $size && ( $data = image_get_intermediate_size( $attachment_id, $size ) ) ) { + /** + * Filter the path to the current image. + * + * The filter is evaluated for all image sizes except 'full'. + * + * @since 3.1.0 + * + * @param string $path Path to the current image. + * @param string $attachment_id Attachment ID. + * @param string $size Size of the image. + */ $filepath = apply_filters( 'load_image_to_edit_filesystempath', path_join( dirname( $filepath ), $data['file'] ), $attachment_id, $size ); } } elseif ( function_exists( 'fopen' ) && function_exists( 'ini_get' ) && true == ini_get( 'allow_url_fopen' ) ) { + /** + * Filter the image URL if not in the local filesystem. + * + * The filter is only evaluated if fopen is enabled on the server. + * + * @since 3.1.0 + * + * @param string $image_url Current image URL. + * @param string $attachment_id Attachment ID. + * @param string $size Size of the image. + */ $filepath = apply_filters( 'load_image_to_edit_attachmenturl', wp_get_attachment_url( $attachment_id ), $attachment_id, $size ); } + /** + * Filter the returned path or URL of the current image. + * + * @since 2.9.0 + * + * @param string|bool $filepath File path or URL to current image, or false. + * @param string $attachment_id Attachment ID. + * @param string $size Size of the image. + */ return apply_filters( 'load_image_to_edit_path', $filepath, $attachment_id, $size ); }