X-Git-Url: https://scripts.mit.edu/gitweb/autoinstalls/wordpress.git/blobdiff_plain/f5fcdc7994bb67cce809bc4777944ae8b7fad4a4..dc1231b7312fbdca99e9e887cc2bb35a28f85cdc:/wp-includes/media.php diff --git a/wp-includes/media.php b/wp-includes/media.php index 35ecdd95..49d1717c 100644 --- a/wp-includes/media.php +++ b/wp-includes/media.php @@ -26,6 +26,9 @@ * * @since 2.5.0 * + * @global int $content_width + * @global array $_wp_additional_image_sizes + * * @param int $width Width of the image in pixels. * @param int $height Height of the image in pixels. * @param string|array $size Optional. Size or array of sizes of what the result image @@ -145,7 +148,7 @@ function image_hwstring( $width, $height ) { * @param int $id Attachment ID for image. * @param array|string $size Optional. Image size to scale to. Accepts a registered image size * or flat array of height and width values. Default 'medium'. - * @return bool|array False on failure, array on success. + * @return false|array False on failure, array on success. */ function image_downsize( $id, $size = 'medium' ) { @@ -242,6 +245,8 @@ function add_image_size( $name, $width = 0, $height = 0, $crop = false ) { * * @since 3.9.0 * + * @global array $_wp_additional_image_sizes + * * @param string $name The image size to check. * @return bool True if the image size exists, false if not. */ @@ -256,6 +261,8 @@ function has_image_size( $name ) { * * @since 3.9.0 * + * @global array $_wp_additional_image_sizes + * * @param string $name The image size to remove. * @return bool True if the image size was successfully removed, false on failure. */ @@ -343,9 +350,7 @@ function get_image_tag( $id, $alt, $title, $align, $size = 'medium' ) { * @param string $align Part of the class name for aligning the image. * @param string $size Optional. Default is 'medium'. */ - $html = apply_filters( 'get_image_tag', $html, $id, $alt, $title, $align, $size ); - - return $html; + return apply_filters( 'get_image_tag', $html, $id, $alt, $title, $align, $size ); } /** @@ -445,7 +450,7 @@ function wp_constrain_dimensions( $current_width, $current_height, $max_width = * @param int $dest_h New height in pixels. * @param bool|array $crop Optional. Whether to crop image to specified height and width or resize. * An array can specify positioning of the crop area. Default false. - * @return bool|array False on failure. Returned array matches parameters for `imagecopyresampled()`. + * @return false|array False on failure. Returned array matches parameters for `imagecopyresampled()`. */ function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = false) { @@ -551,7 +556,7 @@ function image_resize_dimensions($orig_w, $orig_h, $dest_w, $dest_h, $crop = fal * @param int $height Image height. * @param bool $crop Optional. Whether to crop image to specified height and width or resize. * Default false. - * @return bool|array False, if no image was created. Metadata array on success. + * @return false|array False, if no image was created. Metadata array on success. */ function image_make_intermediate_size( $file, $width, $height, $crop = false ) { if ( $width || $height ) { @@ -594,7 +599,7 @@ function image_make_intermediate_size( $file, $width, $height, $crop = false ) { * @param int $post_id Attachment ID. * @param array|string $size Optional. Registered image size to retrieve or flat array of height * and width dimensions. Default 'thumbnail'. - * @return bool|array False on failure or array of file path, width, and height on success. + * @return false|array False on failure or array of file path, width, and height on success. */ function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) { if ( !is_array( $imagedata = wp_get_attachment_metadata( $post_id ) ) ) @@ -685,26 +690,38 @@ function get_intermediate_image_sizes() { * @param string|array $size Optional. Registered image size to retrieve the source for or a flat * array of height and width dimensions. Default 'thumbnail'. * @param bool $icon Optional. Whether the image should be treated as an icon. Default false. - * @return bool|array Returns an array (url, width, height), or false, if no image is available. + * @return false|array Returns an array (url, width, height), or false, if no image is available. */ function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon = false ) { - // get a thumbnail or intermediate image if there is one - if ( $image = image_downsize($attachment_id, $size) ) - return $image; + $image = image_downsize( $attachment_id, $size ); + if ( ! $image ) { + $src = false; - $src = false; + if ( $icon && $src = wp_mime_type_icon( $attachment_id ) ) { + /** This filter is documented in wp-includes/post.php */ + $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' ); - if ( $icon && $src = wp_mime_type_icon($attachment_id) ) { - /** This filter is documented in wp-includes/post.php */ - $icon_dir = apply_filters( 'icon_dir', ABSPATH . WPINC . '/images/media' ); + $src_file = $icon_dir . '/' . wp_basename( $src ); + @list( $width, $height ) = getimagesize( $src_file ); + } - $src_file = $icon_dir . '/' . wp_basename($src); - @list($width, $height) = getimagesize($src_file); + if ( $src && $width && $height ) { + $image = array( $src, $width, $height ); + } } - if ( $src && $width && $height ) - return array( $src, $width, $height ); - return false; + /** + * Filter the image src result. + * + * @since 4.3.0 + * + * @param array|false $image Either array with src, width & height, icon src, or false. + * @param int $attachment_id Image attachment ID. + * @param string|array $size Registered image size to retrieve the source for or a flat + * array of height and width dimensions. Default 'thumbnail'. + * @param bool $icon Whether the image should be treated as an icon. Default false. + */ + return apply_filters( 'wp_get_attachment_image_src', $image, $attachment_id, $size, $icon ); } /** @@ -725,7 +742,6 @@ function wp_get_attachment_image_src( $attachment_id, $size = 'thumbnail', $icon * @return string HTML img element or empty string on failure. */ function wp_get_attachment_image($attachment_id, $size = 'thumbnail', $icon = false, $attr = '') { - $html = ''; $image = wp_get_attachment_image_src($attachment_id, $size, $icon); if ( $image ) { @@ -882,7 +898,7 @@ function img_caption_shortcode( $attr, $content = null ) { return $content; if ( ! empty( $atts['id'] ) ) - $atts['id'] = 'id="' . esc_attr( $atts['id'] ) . '" '; + $atts['id'] = 'id="' . esc_attr( sanitize_html_class( $atts['id'] ) ) . '" '; $class = trim( 'wp-caption ' . $atts['align'] . ' ' . $atts['class'] ); @@ -928,6 +944,8 @@ add_shortcode('gallery', 'gallery_shortcode'); * * @since 2.5.0 * + * @staticvar int $instance + * * @param array $attr { * Attributes of the gallery shortcode. * @@ -1201,6 +1219,9 @@ function wp_playlist_scripts( $type ) { * * @since 3.9.0 * + * @global int $content_width + * @staticvar int $instance + * * @param array $attr { * Array of default playlist attributes. * @@ -1521,6 +1542,8 @@ function wp_get_attachment_id3_keys( $attachment, $context = 'display' ) { * * @since 3.6.0 * + * @staticvar int $instance + * * @param array $attr { * Attributes of the audio shortcode. * @@ -1529,11 +1552,10 @@ function wp_get_attachment_id3_keys( $attachment, $context = 'display' ) { * @type string $autoplay The 'autoplay' attribute for the `