}
/**
- * Filter the maximum image size dimensions for the editor.
+ * Filters the maximum image size dimensions for the editor.
*
* @since 2.5.0
*
* function won't create a new resized copy, it will just return an already
* resized one if it exists.
*
- * A plugin may use the 'image_downsize' filter to hook into and offer image
+ * A plugin may use the {@see 'image_downsize'} filter to hook into and offer image
* resizing services for images. The hook must return an array with the same
* elements that are returned in the function. The first element being the URL
* to the new image that was resized.
return false;
/**
- * Filter whether to preempt the output of image_downsize().
+ * Filters whether to preempt the output of image_downsize().
*
* Passing a truthy value to the filter will effectively short-circuit
* down-sizing the image, returning that value as output instead.
/**
* Gets an img tag for an image attachment, scaling it down if requested.
*
- * The filter 'get_image_tag_class' allows for changing the class name for the
+ * The {@see 'get_image_tag_class'} filter allows for changing the class name for the
* image without having to use regular expressions on the HTML content. The
* parameters are: what WordPress will use for the class, the Attachment ID,
* image align value, and the size the image should be.
*
- * The second filter 'get_image_tag' has the HTML content, which can then be
+ * The second filter, {@see 'get_image_tag'}, has the HTML content, which can then be
* further manipulated by a plugin to change all attribute values and even HTML
* content.
*
$class = 'align' . esc_attr($align) .' size-' . esc_attr($size) . ' wp-image-' . $id;
/**
- * Filter the value of the attachment's image tag class attribute.
+ * Filters the value of the attachment's image tag class attribute.
*
* @since 2.6.0
*
$html = '<img src="' . esc_attr($img_src) . '" alt="' . esc_attr($alt) . '" ' . $title . $hwstring . 'class="' . $class . '" />';
/**
- * Filter the HTML content for the image tag.
+ * Filters the HTML content for the image tag.
*
* @since 2.6.0
*
}
/**
- * Filter dimensions to constrain down-sampled images to.
+ * Filters dimensions to constrain down-sampled images to.
*
* @since 4.1.0
*
return false;
/**
- * Filter whether to preempt calculating the image resize dimensions.
+ * Filters whether to preempt calculating the image resize dimensions.
*
* Passing a non-null value to the filter will effectively short-circuit
* image_resize_dimensions(), returning that value instead.
* Resizes an image to make a thumbnail or intermediate size.
*
* The returned array has the file size, the image width, and image height. The
- * filter 'image_make_intermediate_size' can be used to hook in and change the
+ * {@see 'image_make_intermediate_size'} filter can be used to hook in and change the
* values of the returned array. The only parameter is the resized file path.
*
* @since 2.5.0
return false;
}
+/**
+ * Helper function to test if aspect ratios for two images match.
+ *
+ * @since 4.6.0
+ *
+ * @param int $source_width Width of the first image in pixels.
+ * @param int $source_height Height of the first image in pixels.
+ * @param int $target_width Width of the second image in pixels.
+ * @param int $target_height Height of the second image in pixels.
+ * @return bool True if aspect ratios match within 1px. False if not.
+ */
+function wp_image_matches_ratio( $source_width, $source_height, $target_width, $target_height ) {
+ /*
+ * To test for varying crops, we constrain the dimensions of the larger image
+ * to the dimensions of the smaller image and see if they match.
+ */
+ if ( $source_width > $target_width ) {
+ $constrained_size = wp_constrain_dimensions( $source_width, $source_height, $target_width );
+ $expected_size = array( $target_width, $target_height );
+ } else {
+ $constrained_size = wp_constrain_dimensions( $target_width, $target_height, $source_width );
+ $expected_size = array( $source_width, $source_height );
+ }
+
+ // If the image dimensions are within 1px of the expected size, we consider it a match.
+ $matched = ( abs( $constrained_size[0] - $expected_size[0] ) <= 1 && abs( $constrained_size[1] - $expected_size[1] ) <= 1 );
+
+ return $matched;
+}
+
/**
* Retrieves the image's intermediate size (resized) path, width, and height.
*
* @type string $file Image's path relative to uploads directory
* @type int $width Width of image
* @type int $height Height of image
- * @type string $path Optional. Image's absolute filesystem path. Only returned if registered
- * size is passed to `$size` parameter.
- * @type string $url Optional. Image's URL. Only returned if registered size is passed to `$size`
- * parameter.
+ * @type string $path Image's absolute filesystem path.
+ * @type string $url Image's URL.
* }
*/
function image_get_intermediate_size( $post_id, $size = 'thumbnail' ) {
- if ( !is_array( $imagedata = wp_get_attachment_metadata( $post_id ) ) )
+ if ( ! $size || ! is_array( $imagedata = wp_get_attachment_metadata( $post_id ) ) || empty( $imagedata['sizes'] ) ) {
return false;
+ }
+
+ $data = array();
- // get the best one for a specified set of dimensions
- if ( is_array($size) && !empty($imagedata['sizes']) ) {
+ // Find the best match when '$size' is an array.
+ if ( is_array( $size ) ) {
$candidates = array();
foreach ( $imagedata['sizes'] as $_size => $data ) {
// If there's an exact match to an existing image size, short circuit.
if ( $data['width'] == $size[0] && $data['height'] == $size[1] ) {
- list( $data['width'], $data['height'] ) = image_constrain_size_for_editor( $data['width'], $data['height'], $size );
-
- /** This filter is documented in wp-includes/media.php */
- return apply_filters( 'image_get_intermediate_size', $data, $post_id, $size );
+ $candidates[ $data['width'] * $data['height'] ] = $data;
+ break;
}
- // If it's not an exact match but it's at least the dimensions requested.
+
+ // If it's not an exact match, consider larger sizes with the same aspect ratio.
if ( $data['width'] >= $size[0] && $data['height'] >= $size[1] ) {
- $candidates[ $data['width'] * $data['height'] ] = $_size;
+ // If '0' is passed to either size, we test ratios against the original file.
+ if ( 0 === $size[0] || 0 === $size[1] ) {
+ $same_ratio = wp_image_matches_ratio( $data['width'], $data['height'], $imagedata['width'], $imagedata['height'] );
+ } else {
+ $same_ratio = wp_image_matches_ratio( $data['width'], $data['height'], $size[0], $size[1] );
+ }
+
+ if ( $same_ratio ) {
+ $candidates[ $data['width'] * $data['height'] ] = $data;
+ }
}
}
if ( ! empty( $candidates ) ) {
- // find for the smallest image not smaller than the desired size
- ksort( $candidates );
- foreach ( $candidates as $_size ) {
- $data = $imagedata['sizes'][$_size];
-
- // Skip images with unexpectedly divergent aspect ratios (crops)
- // First, we calculate what size the original image would be if constrained to a box the size of the current image in the loop
- $maybe_cropped = image_resize_dimensions($imagedata['width'], $imagedata['height'], $data['width'], $data['height'], false );
- // If the size doesn't match within one pixel, then it is of a different aspect ratio, so we skip it, unless it's the thumbnail size
- if ( 'thumbnail' != $_size &&
- ( ! $maybe_cropped
- || ( $maybe_cropped[4] != $data['width'] && $maybe_cropped[4] + 1 != $data['width'] )
- || ( $maybe_cropped[5] != $data['height'] && $maybe_cropped[5] + 1 != $data['height'] )
- ) ) {
- continue;
- }
- // If we're still here, then we're going to use this size.
- list( $data['width'], $data['height'] ) = image_constrain_size_for_editor( $data['width'], $data['height'], $size );
-
- /** This filter is documented in wp-includes/media.php */
- return apply_filters( 'image_get_intermediate_size', $data, $post_id, $size );
+ // Sort the array by size if we have more than one candidate.
+ if ( 1 < count( $candidates ) ) {
+ ksort( $candidates );
}
+
+ $data = array_shift( $candidates );
+ /*
+ * When the size requested is smaller than the thumbnail dimensions, we
+ * fall back to the thumbnail size to maintain backwards compatibility with
+ * pre 4.6 versions of WordPress.
+ */
+ } elseif ( ! empty( $imagedata['sizes']['thumbnail'] ) && $imagedata['sizes']['thumbnail']['width'] >= $size[0] && $imagedata['sizes']['thumbnail']['width'] >= $size[1] ) {
+ $data = $imagedata['sizes']['thumbnail'];
+ } else {
+ return false;
}
+
+ // Constrain the width and height attributes to the requested values.
+ list( $data['width'], $data['height'] ) = image_constrain_size_for_editor( $data['width'], $data['height'], $size );
+
+ } elseif ( ! empty( $imagedata['sizes'][ $size ] ) ) {
+ $data = $imagedata['sizes'][ $size ];
}
- if ( is_array($size) || empty($size) || empty($imagedata['sizes'][$size]) )
+ // If we still don't have a match at this point, return false.
+ if ( empty( $data ) ) {
return false;
+ }
- $data = $imagedata['sizes'][$size];
// include the full filesystem path of the intermediate file
if ( empty($data['path']) && !empty($data['file']) ) {
$file_url = wp_get_attachment_url($post_id);
}
/**
- * Filter the output of image_get_intermediate_size()
+ * Filters the output of image_get_intermediate_size()
*
* @since 4.4.0
*
$image_sizes = array_merge( $image_sizes, array_keys( $_wp_additional_image_sizes ) );
/**
- * Filter the list of intermediate image sizes.
+ * Filters the list of intermediate image sizes.
*
* @since 2.5.0
*
}
}
/**
- * Filter the image src result.
+ * Filters the image src result.
*
* @since 4.3.0
*
}
/**
- * Filter the list of attachment image attributes.
+ * Filters the list of attachment image attributes.
*
* @since 2.8.0
*
* If src is an intermediate size GIF, the full size is excluded from srcset to keep a flattened GIF from becoming animated.
*/
if ( ! isset( $image_sizes['thumbnail']['mime-type'] ) || 'image/gif' !== $image_sizes['thumbnail']['mime-type'] ) {
- $image_sizes['full'] = array(
+ $image_sizes[] = array(
'width' => $image_meta['width'],
'height' => $image_meta['height'],
'file' => $image_basename,
$image_edited = preg_match( '/-e[0-9]{13}/', wp_basename( $image_src ), $image_edit_hash );
/**
- * Filter the maximum image width to be included in a 'srcset' attribute.
+ * Filters the maximum image width to be included in a 'srcset' attribute.
*
* @since 4.4.0
*
}
/*
- * Filter out images that are wider than '$max_srcset_image_width' unless
+ * Filters out images that are wider than '$max_srcset_image_width' unless
* that file is in the 'src' attribute.
*/
if ( $max_srcset_image_width && $image['width'] > $max_srcset_image_width && ! $is_src ) {
continue;
}
- /**
- * To check for varying crops, we calculate the expected size of the smaller
- * image if the larger were constrained by the width of the smaller and then
- * see if it matches what we're expecting.
- */
- if ( $image_width > $image['width'] ) {
- $constrained_size = wp_constrain_dimensions( $image_width, $image_height, $image['width'] );
- $expected_size = array( $image['width'], $image['height'] );
- } else {
- $constrained_size = wp_constrain_dimensions( $image['width'], $image['height'], $image_width );
- $expected_size = array( $image_width, $image_height );
- }
-
// If the image dimensions are within 1px of the expected size, use it.
- if ( abs( $constrained_size[0] - $expected_size[0] ) <= 1 && abs( $constrained_size[1] - $expected_size[1] ) <= 1 ) {
+ if ( wp_image_matches_ratio( $image_width, $image_height, $image['width'], $image['height'] ) ) {
// Add the URL, descriptor, and value to the sources array to be returned.
$source = array(
'url' => $image_baseurl . $image['file'],
}
/**
- * Filter an image's 'srcset' sources.
+ * Filters an image's 'srcset' sources.
*
* @since 4.4.0
*
* @param array $size_array Array of width and height values in pixels (in that order).
* @param string $image_src The 'src' of the image.
* @param array $image_meta The image meta data as returned by 'wp_get_attachment_metadata()'.
- * @param int $attachment_id Image attachment ID or 0.
+ * @param int $attachment_id Image attachment ID or 0.
*/
$sources = apply_filters( 'wp_calculate_image_srcset', $sources, $size_array, $image_src, $image_meta, $attachment_id );
$srcset = '';
foreach ( $sources as $source ) {
- $srcset .= $source['url'] . ' ' . $source['value'] . $source['descriptor'] . ', ';
+ $srcset .= str_replace( ' ', '%20', $source['url'] ) . ' ' . $source['value'] . $source['descriptor'] . ', ';
}
return rtrim( $srcset, ', ' );
$sizes = sprintf( '(max-width: %1$dpx) 100vw, %1$dpx', $width );
/**
- * Filter the output of 'wp_calculate_image_sizes()'.
+ * Filters the output of 'wp_calculate_image_sizes()'.
*
* @since 4.4.0
*
/**
* Adds a 'wp-post-image' class to post thumbnails. Internal use only.
*
- * Uses the 'begin_fetch_post_thumbnail_html' and 'end_fetch_post_thumbnail_html' action hooks to
- * dynamically add/remove itself so as to only filter post thumbnails.
+ * Uses the {@see 'begin_fetch_post_thumbnail_html'} and {@see 'end_fetch_post_thumbnail_html'}
+ * action hooks to dynamically add/remove itself so as to only filter post thumbnails.
*
* @ignore
* @since 2.9.0
* Builds the Caption shortcode output.
*
* Allows a plugin to replace the content that would otherwise be returned. The
- * filter is 'img_caption_shortcode' and passes an empty string, the attr
+ * filter is {@see 'img_caption_shortcode'} and passes an empty string, the attr
* parameter and the content parameter values.
*
* The supported attributes for the shortcode are 'id', 'align', 'width', and
}
/**
- * Filter the default caption shortcode output.
+ * Filters the default caption shortcode output.
*
* If the filtered output isn't empty, it will be used instead of generating
* the default caption template.
$width = $html5 ? $atts['width'] : ( 10 + $atts['width'] );
/**
- * Filter the width of an image's caption.
+ * Filters the width of an image's caption.
*
* By default, the caption is 10 pixels greater than the width of the image,
* to prevent post content from running up against a floated image.
}
/**
- * Filter the default gallery shortcode output.
+ * Filters the default gallery shortcode output.
*
* If the filtered output isn't empty, it will be used instead of generating
* the default gallery template.
$gallery_style = '';
/**
- * Filter whether to print default gallery styles.
+ * Filters whether to print default gallery styles.
*
* @since 3.1.0
*
$gallery_div = "<div id='$selector' class='gallery galleryid-{$id} gallery-columns-{$columns} gallery-size-{$size_class}'>";
/**
- * Filter the default gallery shortcode CSS styles.
+ * Filters the default gallery shortcode CSS styles.
*
* @since 2.5.0
*
}
/**
- * Filter the playlist output.
+ * Filters the playlist output.
*
* Passing a non-empty value to the filter will short-circuit generation
* of the default playlist output, returning the passed value instead.
if ( 1 === $instance ) {
/**
- * Print and enqueue playlist scripts, styles, and JavaScript templates.
+ * Prints and enqueues playlist scripts, styles, and JavaScript templates.
*
* @since 3.9.0
*
echo (int) $theme_width;
?>"<?php if ( 'video' === $safe_type ):
echo ' height="', (int) $theme_height, '"';
- else:
- echo ' style="visibility: hidden"';
endif; ?>></<?php echo $safe_type ?>>
<div class="wp-playlist-next"></div>
<div class="wp-playlist-prev"></div>
*/
function wp_mediaelement_fallback( $url ) {
/**
- * Filter the Mediaelement fallback output for no-JS.
+ * Filters the Mediaelement fallback output for no-JS.
*
* @since 3.6.0
*
*/
function wp_get_audio_extensions() {
/**
- * Filter the list of supported audio formats.
+ * Filters the list of supported audio formats.
*
* @since 3.6.0
*
}
/**
- * Filter the editable list of keys to look up data from an attachment's metadata.
+ * Filters the editable list of keys to look up data from an attachment's metadata.
*
* @since 3.9.0
*
* @type string $autoplay The 'autoplay' attribute for the `<audio>` element. Default empty.
* @type string $preload The 'preload' attribute for the `<audio>` element. Default 'none'.
* @type string $class The 'class' attribute for the `<audio>` element. Default 'wp-audio-shortcode'.
- * @type string $style The 'style' attribute for the `<audio>` element. Default 'width: 100%; visibility: hidden;'.
+ * @type string $style The 'style' attribute for the `<audio>` element. Default 'width: 100%;'.
* }
* @param string $content Shortcode content.
* @return string|void HTML content to display audio.
$instance++;
/**
- * Filter the default audio shortcode output.
+ * Filters the default audio shortcode output.
*
* If the filtered output isn't empty, it will be used instead of generating the default audio template.
*
'autoplay' => '',
'preload' => 'none',
'class' => 'wp-audio-shortcode',
- 'style' => 'width: 100%; visibility: hidden;'
+ 'style' => 'width: 100%;'
);
foreach ( $default_types as $type ) {
$defaults_atts[$type] = '';
}
/**
- * Filter the media library used for the audio shortcode.
+ * Filters the media library used for the audio shortcode.
*
* @since 3.6.0
*
}
/**
- * Filter the class attribute for the audio shortcode output container.
+ * Filters the class attribute for the audio shortcode output container.
*
* @since 3.6.0
*
$html .= '</audio>';
/**
- * Filter the audio shortcode output.
+ * Filters the audio shortcode output.
*
* @since 3.6.0
*
*/
function wp_get_video_extensions() {
/**
- * Filter the list of supported video formats.
+ * Filters the list of supported video formats.
*
* @since 3.6.0
*
$instance++;
/**
- * Filter the default video shortcode output.
+ * Filters the default video shortcode output.
*
* If the filtered output isn't empty, it will be used instead of generating
* the default video template.
}
/**
- * Filter the media library used for the video shortcode.
+ * Filters the media library used for the video shortcode.
*
* @since 3.6.0
*
}
/**
- * Filter the class attribute for the video shortcode output container.
+ * Filters the class attribute for the video shortcode output container.
*
* @since 3.6.0
*
$output = sprintf( '<div style="%s" class="wp-video">%s</div>', $width_rule, $html );
/**
- * Filter the output of the video shortcode.
+ * Filters the output of the video shortcode.
*
* @since 3.6.0
*
$adjacent = $prev ? 'previous' : 'next';
/**
- * Filter the adjacent image link.
+ * Filters the adjacent image link.
*
* The dynamic portion of the hook name, `$adjacent`, refers to the type of adjacency,
* either 'next', or 'previous'.
return wp_constrain_dimensions( $example_width * 1000000, $example_height * 1000000, $max_width, $max_height );
}
-/**
- * Converts a shorthand byte value to an integer byte value.
- *
- * @since 2.3.0
- *
- * @param string $size A shorthand byte value.
- * @return int An integer byte value.
- */
-function wp_convert_hr_to_bytes( $size ) {
- $size = strtolower( $size );
- $bytes = (int) $size;
- if ( strpos( $size, 'k' ) !== false )
- $bytes = intval( $size ) * KB_IN_BYTES;
- elseif ( strpos( $size, 'm' ) !== false )
- $bytes = intval($size) * MB_IN_BYTES;
- elseif ( strpos( $size, 'g' ) !== false )
- $bytes = intval( $size ) * GB_IN_BYTES;
- return $bytes;
-}
-
/**
* Determines the maximum upload size allowed in php.ini.
*
$p_bytes = wp_convert_hr_to_bytes( ini_get( 'post_max_size' ) );
/**
- * Filter the maximum upload size allowed in php.ini.
+ * Filters the maximum upload size allowed in php.ini.
*
* @since 2.5.0
*
require_once ABSPATH . WPINC . '/class-wp-image-editor-imagick.php';
/**
- * Filter the list of image editing library classes.
+ * Filters the list of image editing library classes.
*
* @since 3.5.0
*
}
/**
- * Prints default plupload arguments.
+ * Prints default Plupload arguments.
*
* @since 3.4.0
*/
return;
$max_upload_size = wp_max_upload_size();
+ $allowed_extensions = array_keys( get_allowed_mime_types() );
+ $extensions = array();
+ foreach ( $allowed_extensions as $extension ) {
+ $extensions = array_merge( $extensions, explode( '|', $extension ) );
+ }
$defaults = array(
'runtimes' => 'html5,flash,silverlight,html4',
'silverlight_xap_url' => includes_url( 'js/plupload/plupload.silverlight.xap' ),
'filters' => array(
'max_file_size' => $max_upload_size . 'b',
+ 'mime_types' => array( array( 'extensions' => implode( ',', $extensions ) ) ),
),
);
}
/**
- * Filter the Plupload default settings.
+ * Filters the Plupload default settings.
*
* @since 3.4.0
*
);
/**
- * Filter the Plupload default parameters.
+ * Filters the Plupload default parameters.
*
* @since 3.4.0
*
if ( $post_parent ) {
$parent_type = get_post_type_object( $post_parent->post_type );
+
if ( $parent_type && $parent_type->show_ui && current_user_can( 'edit_post', $attachment->post_parent ) ) {
$response['uploadedToLink'] = get_edit_post_link( $attachment->post_parent, 'raw' );
}
- $response['uploadedToTitle'] = $post_parent->post_title ? $post_parent->post_title : __( '(no title)' );
+
+ if ( $parent_type && current_user_can( 'read_post', $attachment->post_parent ) ) {
+ $response['uploadedToTitle'] = $post_parent->post_title ? $post_parent->post_title : __( '(no title)' );
+ }
}
$attached_file = get_attached_file( $attachment->ID );
$response['compat'] = get_compat_media_markup( $attachment->ID, array( 'in_modal' => true ) );
/**
- * Filter the attachment data prepared for JavaScript.
+ * Filters the attachment data prepared for JavaScript.
*
* @since 3.5.0
*
);
/**
- * Filter the media view settings.
+ * Filters the media view settings.
*
* @since 3.5.0
*
$settings = apply_filters( 'media_view_settings', $settings, $post );
/**
- * Filter the media view strings.
+ * Filters the media view strings.
*
* @since 3.5.0
*
);
/**
- * Filter arguments used to retrieve media attached to the given post.
+ * Filters arguments used to retrieve media attached to the given post.
*
* @since 3.6.0
*
$children = get_children( $args );
/**
- * Filter the list of media attached to the given post.
+ * Filters the list of media attached to the given post.
*
* @since 3.6.0
*
$html = array();
/**
- * Filter the embedded media types that are allowed to be returned from the content blob.
+ * Filters the embedded media types that are allowed to be returned from the content blob.
*
* @since 4.2.0
*
}
/**
- * Filter the list of all found galleries in the given post.
+ * Filters the list of all found galleries in the given post.
*
* @since 3.6.0
*
$gallery = reset( $galleries );
/**
- * Filter the first-found post gallery.
+ * Filters the first-found post gallery.
*
* @since 3.6.0
*
$post_id = $wpdb->get_var( $sql );
/**
- * Filter an attachment id found by URL.
+ * Filters an attachment id found by URL.
*
* @since 4.2.0
*