Media: revert the multi-mime feature.
This feature isn't quite ready to land. Reverts r53786, r53848, r53847, r53845, r53751. Props flixos90, azaozz, dd32. See #55443. Built from https://develop.svn.wordpress.org/trunk@54085 git-svn-id: http://core.svn.wordpress.org/trunk@53644 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
@@ -334,11 +334,6 @@ abstract class WP_Image_Editor {
|
||||
protected function get_output_format( $filename = null, $mime_type = null ) {
|
||||
$new_ext = null;
|
||||
|
||||
// If no mime type is passed but output mime type is set, use that.
|
||||
if ( ! $mime_type && ! empty( $this->output_mime_type ) ) {
|
||||
$mime_type = $this->output_mime_type;
|
||||
}
|
||||
|
||||
// By default, assume specified type takes priority.
|
||||
if ( $mime_type ) {
|
||||
$new_ext = $this->get_extension( $mime_type );
|
||||
@@ -430,25 +425,18 @@ abstract class WP_Image_Editor {
|
||||
}
|
||||
|
||||
/**
|
||||
* Builds an output filename based on current file, and adding proper suffix.
|
||||
* Builds an output filename based on current file, and adding proper suffix
|
||||
*
|
||||
* @since 3.5.0
|
||||
* @since 6.1.0 Skips adding a suffix when set to an empty string. When the
|
||||
* file extension being generated doesn't match the image file extension,
|
||||
* add the extension to the suffix
|
||||
*
|
||||
* @param string $suffix Optional. Suffix to add to the filename. The default null
|
||||
* will result in a 'widthxheight' suffix. Passing
|
||||
* an empty string will result in no suffix.
|
||||
* @param string $dest_path Optional. The path to save the file to. The default null
|
||||
* will use the image file path.
|
||||
* @param string $extension Optional. The file extension to use. The default null
|
||||
* will use the image file extension.
|
||||
* @return string filename The generated file name.
|
||||
* @param string $suffix
|
||||
* @param string $dest_path
|
||||
* @param string $extension
|
||||
* @return string filename
|
||||
*/
|
||||
public function generate_filename( $suffix = null, $dest_path = null, $extension = null ) {
|
||||
// $suffix will be appended to the destination filename, just before the extension.
|
||||
if ( null === $suffix ) {
|
||||
if ( ! $suffix ) {
|
||||
$suffix = $this->get_suffix();
|
||||
}
|
||||
|
||||
@@ -469,21 +457,7 @@ abstract class WP_Image_Editor {
|
||||
}
|
||||
}
|
||||
|
||||
if ( empty( $suffix ) ) {
|
||||
$suffix = '';
|
||||
} else {
|
||||
$suffix = "-{$suffix}";
|
||||
}
|
||||
|
||||
// When the file extension being generated doesn't match the image file extension,
|
||||
// add the extension to the suffix to ensure a unique file name. Prevents
|
||||
// name conflicts when a single image type can have multiple extensions,
|
||||
// eg. .jpg, .jpeg and .jpe are all valid JPEG extensions.
|
||||
if ( ! empty( $extension ) && $extension !== $ext ) {
|
||||
$suffix .= "-{$ext}";
|
||||
}
|
||||
|
||||
return trailingslashit( $dir ) . "{$name}{$suffix}.{$new_ext}";
|
||||
return trailingslashit( $dir ) . "{$name}-{$suffix}.{$new_ext}";
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -663,28 +637,5 @@ abstract class WP_Image_Editor {
|
||||
|
||||
return wp_get_default_extension_for_mime_type( $mime_type );
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the editor output mime type, useful when outputting alternate mime types.
|
||||
*
|
||||
* Track that the mime type is set with the mime type set flag.
|
||||
*
|
||||
* @since 6.1.0
|
||||
*
|
||||
* @param string $output_mime_type The mime type to set.
|
||||
*/
|
||||
public function set_output_mime_type( $output_mime_type ) {
|
||||
$this->output_mime_type = $output_mime_type;
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the mime type to the original file mime type.
|
||||
*
|
||||
* Reset the mime type set flag.
|
||||
*
|
||||
* @since 6.1.0
|
||||
*/
|
||||
public function reset_output_mime_type() {
|
||||
$this->output_mime_type = $this->mime_type;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -486,7 +486,7 @@ jQuery( document ).ready( function( $ ) {
|
||||
|
||||
times = tryAgainCount[ file.id ];
|
||||
|
||||
if ( times && times > 8 ) {
|
||||
if ( times && times > 4 ) {
|
||||
/*
|
||||
* The file may have been uploaded and attachment post created,
|
||||
* but post-processing and resizing failed...
|
||||
|
||||
2
wp-includes/js/plupload/handlers.min.js
vendored
2
wp-includes/js/plupload/handlers.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -138,7 +138,7 @@ window.wp = window.wp || {};
|
||||
|
||||
times = tryAgainCount[ file.id ];
|
||||
|
||||
if ( times && times > 8 ) {
|
||||
if ( times && times > 4 ) {
|
||||
/*
|
||||
* The file may have been uploaded and attachment post created,
|
||||
* but post-processing and resizing failed...
|
||||
|
||||
2
wp-includes/js/plupload/wp-plupload.min.js
vendored
2
wp-includes/js/plupload/wp-plupload.min.js
vendored
File diff suppressed because one or more lines are too long
@@ -1852,11 +1852,6 @@ function wp_filter_content_tags( $content, $context = null ) {
|
||||
$filtered_image = wp_img_tag_add_decoding_attr( $filtered_image, $context );
|
||||
}
|
||||
|
||||
// Use alternate mime types when specified and available.
|
||||
if ( $attachment_id > 0 && _wp_in_front_end_context() ) {
|
||||
$filtered_image = wp_image_use_alternate_mime_types( $filtered_image, $context, $attachment_id );
|
||||
}
|
||||
|
||||
/**
|
||||
* Filters an img tag within the content for a given context.
|
||||
*
|
||||
@@ -1903,117 +1898,6 @@ function wp_filter_content_tags( $content, $context = null ) {
|
||||
return $content;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use alternate mime type images in the front end content output when available.
|
||||
*
|
||||
* @since 6.1.0
|
||||
*
|
||||
* @param string $image The HTML `img` tag where the attribute should be added.
|
||||
* @param string $context Additional context to pass to the filters.
|
||||
* @param int $attachment_id The attachment ID.
|
||||
* @return string Converted `img` tag with `loading` attribute added.
|
||||
*/
|
||||
function wp_image_use_alternate_mime_types( $image, $context, $attachment_id ) {
|
||||
$metadata = wp_get_attachment_metadata( $attachment_id );
|
||||
if ( empty( $metadata['file'] ) ) {
|
||||
return $image;
|
||||
}
|
||||
|
||||
// Only alter images with a `sources` attribute
|
||||
if ( empty( $metadata['sources'] ) ) {
|
||||
return $image;
|
||||
};
|
||||
|
||||
$target_mimes = array( 'image/webp', 'image/jpeg' );
|
||||
|
||||
/**
|
||||
* Filter the content image mime type output selection and order.
|
||||
*
|
||||
* When outputting images in the content, the first mime type available will be used.
|
||||
*
|
||||
* @since 6.1.0
|
||||
*
|
||||
* @param array $target_mimes The image output mime type and order. Default is array( 'image/webp', 'image/jpeg' ).
|
||||
* @param int $attachment_id The attachment ID.
|
||||
* @param string $context Additional context to pass to the filters.
|
||||
* @return array The filtered output mime type and order. Return an empty array to skip mime type substitution.
|
||||
*/
|
||||
$target_mimes = apply_filters( 'wp_content_image_mimes', $target_mimes, $attachment_id, $context );
|
||||
|
||||
if ( false === $target_mimes ) {
|
||||
return $image;
|
||||
}
|
||||
|
||||
// Find the appropriate size for the provided URL in the first available mime type.
|
||||
foreach ( $target_mimes as $target_mime ) {
|
||||
// Handle full size image replacement.
|
||||
if ( ! empty( $metadata['sources'][ $target_mime ]['file'] ) ) {
|
||||
$src_filename = wp_basename( $metadata['file'] );
|
||||
|
||||
// This is the same MIME type as the original, so the entire $target_mime can be skipped.
|
||||
// Since it is already the preferred MIME type, the entire loop can be cancelled.
|
||||
if ( $metadata['sources'][ $target_mime ]['file'] === $src_filename ) {
|
||||
break;
|
||||
}
|
||||
|
||||
$image = str_replace( $src_filename, $metadata['sources'][ $target_mime ]['file'], $image );
|
||||
|
||||
// The full size was replaced, so unset this entirely here so that in the next iteration it is no longer
|
||||
// considered, simply for a small performance optimization.
|
||||
unset( $metadata['sources'] );
|
||||
}
|
||||
|
||||
// Go through each image size and replace with the first available mime type version.
|
||||
foreach ( $metadata['sizes'] as $name => $size_data ) {
|
||||
// Check if size has an original file.
|
||||
if ( empty( $size_data['file'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
// Check if size has a source in the desired mime type.
|
||||
if ( empty( $size_data['sources'][ $target_mime ]['file'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$src_filename = wp_basename( $size_data['file'] );
|
||||
|
||||
// This is the same MIME type as the original, so the entire $target_mime can be skipped.
|
||||
// Since it is already the preferred MIME type, the entire loop can be cancelled.
|
||||
if ( $size_data['sources'][ $target_mime ]['file'] === $src_filename ) {
|
||||
break 2;
|
||||
}
|
||||
|
||||
// Found a match, replace with the new filename.
|
||||
$image = str_replace( $src_filename, $size_data['sources'][ $target_mime ]['file'], $image );
|
||||
|
||||
// This size was replaced, so unset this entirely here so that in the next iteration it is no longer
|
||||
// considered, simply for a small performance optimization.
|
||||
unset( $metadata['sizes'][ $name ] );
|
||||
}
|
||||
}
|
||||
return $image;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if execution is currently in the front end content context, outside of <head>.
|
||||
*
|
||||
* @since 6.1.0
|
||||
* @access private
|
||||
*
|
||||
* @return bool True if in the front end content context, false otherwise.
|
||||
*/
|
||||
function _wp_in_front_end_context() {
|
||||
global $wp_query;
|
||||
|
||||
// Check if this request is generally outside (or before) any frontend context.
|
||||
if ( ! isset( $wp_query ) || defined( 'XMLRPC_REQUEST' ) || defined( 'REST_REQUEST' ) || is_feed() ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
// Check if we're anywhere before the 'wp_head' action has completed.
|
||||
return did_action( 'template_redirect' ) && ! doing_action( 'wp_head' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds `loading` attribute to an `img` HTML tag.
|
||||
*
|
||||
|
||||
@@ -6486,28 +6486,13 @@ function wp_delete_attachment_files( $post_id, $meta, $backup_sizes, $file ) {
|
||||
$intermediate_dir = path_join( $uploadpath['basedir'], dirname( $file ) );
|
||||
|
||||
foreach ( $meta['sizes'] as $size => $sizeinfo ) {
|
||||
$intermediate_file = str_replace( wp_basename( $file ), $sizeinfo['file'], $file );
|
||||
|
||||
// Check for alternate size mime types in the sizeinfo['sources'] array to delete.
|
||||
if ( isset( $sizeinfo['sources'] ) && is_array( $sizeinfo['sources'] ) ) {
|
||||
foreach ( $sizeinfo['sources'] as $mime => $properties ) {
|
||||
$intermediate_file = str_replace( wp_basename( $file ), $properties['file'], $file );
|
||||
if ( ! empty( $intermediate_file ) ) {
|
||||
$intermediate_file = path_join( $uploadpath['basedir'], $intermediate_file );
|
||||
if ( ! wp_delete_file_from_directory( $intermediate_file, $intermediate_dir ) ) {
|
||||
$deleted = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Otherwise, delete files from the sizeinfo data.
|
||||
$intermediate_file = str_replace( wp_basename( $file ), $sizeinfo['file'], $file );
|
||||
if ( ! empty( $intermediate_file ) ) {
|
||||
$intermediate_file = path_join( $uploadpath['basedir'], $intermediate_file );
|
||||
|
||||
if ( ! empty( $intermediate_file ) ) {
|
||||
$intermediate_file = path_join( $uploadpath['basedir'], $intermediate_file );
|
||||
|
||||
if ( ! wp_delete_file_from_directory( $intermediate_file, $intermediate_dir ) ) {
|
||||
$deleted = false;
|
||||
}
|
||||
if ( ! wp_delete_file_from_directory( $intermediate_file, $intermediate_dir ) ) {
|
||||
$deleted = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6529,58 +6514,24 @@ function wp_delete_attachment_files( $post_id, $meta, $backup_sizes, $file ) {
|
||||
}
|
||||
}
|
||||
|
||||
// Delete the full size images from 'sources' if available, or the root file.
|
||||
if ( isset( $meta['sources'] ) && is_array( $meta['sources'] ) ) {
|
||||
$sources = $meta['sources'];
|
||||
$intermediate_dir = path_join( $uploadpath['basedir'], dirname( $file ) );
|
||||
foreach ( $sources as $mime => $properties ) {
|
||||
if ( ! is_array( $properties ) || empty( $properties['file'] ) ) {
|
||||
continue;
|
||||
if ( is_array( $backup_sizes ) ) {
|
||||
$del_dir = path_join( $uploadpath['basedir'], dirname( $meta['file'] ) );
|
||||
|
||||
foreach ( $backup_sizes as $size ) {
|
||||
$del_file = path_join( dirname( $meta['file'] ), $size['file'] );
|
||||
|
||||
if ( ! empty( $del_file ) ) {
|
||||
$del_file = path_join( $uploadpath['basedir'], $del_file );
|
||||
|
||||
if ( ! wp_delete_file_from_directory( $del_file, $del_dir ) ) {
|
||||
$deleted = false;
|
||||
}
|
||||
}
|
||||
$intermediate_file = str_replace( wp_basename( $file ), $properties['file'], $file );
|
||||
if ( ! wp_delete_file_from_directory( $intermediate_file, $intermediate_dir ) ) {
|
||||
$deleted = false;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if ( ! wp_delete_file_from_directory( $file, $uploadpath['basedir'] ) ) {
|
||||
$deleted = false;
|
||||
}
|
||||
}
|
||||
|
||||
if ( is_array( $backup_sizes ) ) {
|
||||
|
||||
$del_dir = path_join( $uploadpath['basedir'], dirname( $meta['file'] ) );
|
||||
// Delete the root (edited) file which was not deleted above.
|
||||
if ( ! wp_delete_file_from_directory( $file, $uploadpath['basedir'] ) ) {
|
||||
$deleted = false;
|
||||
}
|
||||
foreach ( $backup_sizes as $size ) {
|
||||
// Delete files from 'sources' data if available, otherwise from 'sizes' data.
|
||||
if ( isset( $meta['sources'] ) && is_array( $meta['sources'] ) ) {
|
||||
// Delete any backup images stored in the 'sources' array.
|
||||
if ( isset( $size['sources'] ) && is_array( $size['sources'] ) ) {
|
||||
foreach ( $size['sources'] as $mime => $properties ) {
|
||||
$del_file = path_join( dirname( $meta['file'] ), $properties['file'] );
|
||||
if ( ! empty( $del_file ) ) {
|
||||
$del_file = path_join( $uploadpath['basedir'], $del_file );
|
||||
if ( ! wp_delete_file_from_directory( $del_file, $del_dir ) ) {
|
||||
$deleted = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$del_file = path_join( dirname( $meta['file'] ), $size['file'] );
|
||||
|
||||
if ( ! empty( $del_file ) ) {
|
||||
$del_file = path_join( $uploadpath['basedir'], $del_file );
|
||||
if ( ! wp_delete_file_from_directory( $del_file, $del_dir ) ) {
|
||||
$deleted = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if ( ! wp_delete_file_from_directory( $file, $uploadpath['basedir'] ) ) {
|
||||
$deleted = false;
|
||||
}
|
||||
|
||||
return $deleted;
|
||||
|
||||
@@ -783,15 +783,6 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
|
||||
}
|
||||
|
||||
$size_data['source_url'] = $image_src[0];
|
||||
|
||||
if ( empty( $size_data['sources'] ) || ! is_array( $size_data['sources'] ) ) {
|
||||
continue;
|
||||
}
|
||||
|
||||
$image_url_basename = wp_basename( $image_src[0] );
|
||||
foreach ( $size_data['sources'] as $mime => &$mime_details ) {
|
||||
$mime_details['source_url'] = str_replace( $image_url_basename, $mime_details['file'], $image_src[0] );
|
||||
}
|
||||
}
|
||||
|
||||
$full_src = wp_get_attachment_image_src( $post->ID, 'full' );
|
||||
@@ -804,15 +795,6 @@ class WP_REST_Attachments_Controller extends WP_REST_Posts_Controller {
|
||||
'mime_type' => $post->post_mime_type,
|
||||
'source_url' => $full_src[0],
|
||||
);
|
||||
|
||||
if ( ! empty( $data['media_details']['sources'] ) ) {
|
||||
$full_url_basename = wp_basename( $full_src[0] );
|
||||
foreach ( $data['media_details']['sources'] as $mime => &$mime_details ) {
|
||||
$mime_details['source_url'] = str_replace( $full_url_basename, $mime_details['file'], $full_src[0] );
|
||||
}
|
||||
$data['media_details']['sizes']['full']['sources'] = $data['media_details']['sources'];
|
||||
unset( $data['media_details']['sources'] );
|
||||
}
|
||||
}
|
||||
} else {
|
||||
$data['media_details']['sizes'] = new stdClass;
|
||||
|
||||
@@ -16,7 +16,7 @@
|
||||
*
|
||||
* @global string $wp_version
|
||||
*/
|
||||
$wp_version = '6.1-alpha-54084';
|
||||
$wp_version = '6.1-alpha-54085';
|
||||
|
||||
/**
|
||||
* Holds the WordPress DB revision, increments when changes are made to the WordPress DB schema.
|
||||
|
||||
Reference in New Issue
Block a user