Archived
Updates bonanza
This commit is contained in:
1 parent
d26191c9f8
commit
9d480fc3c5
1366 files changed
+220321
-90180
No files matched your search
+152
-6
@@ -20,7 +20,7 @@
|
||||
* @param int $dst_h The destination height.
|
||||
* @param int $src_abs Optional. If the source crop points are absolute.
|
||||
* @param string $dst_file Optional. The destination file to write to.
|
||||
* @return string|WP_Error|false New filepath on success, WP_Error or false on failure.
|
||||
* @return string|WP_Error New filepath on success, WP_Error on failure.
|
||||
*/
|
||||
function wp_crop_image( $src, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $src_abs = false, $dst_file = false ) {
|
||||
$src_file = $src;
|
||||
@@ -54,6 +54,9 @@ function wp_crop_image( $src, $src_x, $src_y, $src_w, $src_h, $dst_w, $dst_h, $s
|
||||
$dst_file = dirname( $dst_file ) . '/' . wp_unique_filename( dirname( $dst_file ), basename( $dst_file ) );
|
||||
|
||||
$result = $editor->save( $dst_file );
|
||||
if ( is_wp_error( $result ) )
|
||||
return $result;
|
||||
|
||||
return $dst_file;
|
||||
}
|
||||
|
||||
@@ -70,6 +73,7 @@ function wp_generate_attachment_metadata( $attachment_id, $file ) {
|
||||
$attachment = get_post( $attachment_id );
|
||||
|
||||
$metadata = array();
|
||||
$support = false;
|
||||
if ( preg_match('!^image/!', get_post_mime_type( $attachment )) && file_is_displayable_image($file) ) {
|
||||
$imagesize = getimagesize( $file );
|
||||
$metadata['width'] = $imagesize[0];
|
||||
@@ -81,6 +85,7 @@ function wp_generate_attachment_metadata( $attachment_id, $file ) {
|
||||
// make thumbnails and other intermediate sizes
|
||||
global $_wp_additional_image_sizes;
|
||||
|
||||
$sizes = array();
|
||||
foreach ( get_intermediate_image_sizes() as $s ) {
|
||||
$sizes[$s] = array( 'width' => '', 'height' => '', 'crop' => false );
|
||||
if ( isset( $_wp_additional_image_sizes[$s]['width'] ) )
|
||||
@@ -92,11 +97,18 @@ function wp_generate_attachment_metadata( $attachment_id, $file ) {
|
||||
else
|
||||
$sizes[$s]['height'] = get_option( "{$s}_size_h" ); // For default sizes set in options
|
||||
if ( isset( $_wp_additional_image_sizes[$s]['crop'] ) )
|
||||
$sizes[$s]['crop'] = intval( $_wp_additional_image_sizes[$s]['crop'] ); // For theme-added sizes
|
||||
$sizes[$s]['crop'] = $_wp_additional_image_sizes[$s]['crop']; // For theme-added sizes
|
||||
else
|
||||
$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 ) {
|
||||
@@ -113,8 +125,80 @@ function wp_generate_attachment_metadata( $attachment_id, $file ) {
|
||||
if ( $image_meta )
|
||||
$metadata['image_meta'] = $image_meta;
|
||||
|
||||
} elseif ( preg_match( '#^video/#', get_post_mime_type( $attachment ) ) ) {
|
||||
$metadata = wp_read_video_metadata( $file );
|
||||
$support = current_theme_supports( 'post-thumbnails', 'attachment:video' ) || post_type_supports( 'attachment:video', 'thumbnail' );
|
||||
} elseif ( preg_match( '#^audio/#', get_post_mime_type( $attachment ) ) ) {
|
||||
$metadata = wp_read_audio_metadata( $file );
|
||||
$support = current_theme_supports( 'post-thumbnails', 'attachment:audio' ) || post_type_supports( 'attachment:audio', 'thumbnail' );
|
||||
}
|
||||
|
||||
if ( $support && ! empty( $metadata['image']['data'] ) ) {
|
||||
// check for existing cover
|
||||
$hash = md5( $metadata['image']['data'] );
|
||||
$posts = get_posts( array(
|
||||
'fields' => 'ids',
|
||||
'post_type' => 'attachment',
|
||||
'post_mime_type' => $metadata['image']['mime'],
|
||||
'post_status' => 'inherit',
|
||||
'posts_per_page' => 1,
|
||||
'meta_key' => '_cover_hash',
|
||||
'meta_value' => $hash
|
||||
) );
|
||||
$exists = reset( $posts );
|
||||
|
||||
if ( ! empty( $exists ) ) {
|
||||
update_post_meta( $attachment_id, '_thumbnail_id', $exists );
|
||||
} else {
|
||||
$ext = '.jpg';
|
||||
switch ( $metadata['image']['mime'] ) {
|
||||
case 'image/gif':
|
||||
$ext = '.gif';
|
||||
break;
|
||||
case 'image/png':
|
||||
$ext = '.png';
|
||||
break;
|
||||
}
|
||||
$basename = str_replace( '.', '-', basename( $file ) ) . '-image' . $ext;
|
||||
$uploaded = wp_upload_bits( $basename, '', $metadata['image']['data'] );
|
||||
if ( false === $uploaded['error'] ) {
|
||||
$image_attachment = array(
|
||||
'post_mime_type' => $metadata['image']['mime'],
|
||||
'post_type' => 'attachment',
|
||||
'post_content' => '',
|
||||
);
|
||||
/**
|
||||
* Filter the parameters for the attachment thumbnail creation.
|
||||
*
|
||||
* @since 3.9.0
|
||||
*
|
||||
* @param array $image_attachment An array of parameters to create the thumbnail.
|
||||
* @param array $metadata Current attachment metadata.
|
||||
* @param array $uploaded An array containing the thumbnail path and url.
|
||||
*/
|
||||
$image_attachment = apply_filters( 'attachment_thumbnail_args', $image_attachment, $metadata, $uploaded );
|
||||
|
||||
$sub_attachment_id = wp_insert_attachment( $image_attachment, $uploaded['file'] );
|
||||
add_post_meta( $sub_attachment_id, '_cover_hash', $hash );
|
||||
$attach_data = wp_generate_attachment_metadata( $sub_attachment_id, $uploaded['file'] );
|
||||
wp_update_attachment_metadata( $sub_attachment_id, $attach_data );
|
||||
update_post_meta( $attachment_id, '_thumbnail_id', $sub_attachment_id );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// remove the blob of binary data from the array
|
||||
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 );
|
||||
}
|
||||
|
||||
@@ -228,7 +312,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 );
|
||||
|
||||
@@ -276,6 +366,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 );
|
||||
|
||||
}
|
||||
@@ -297,7 +396,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.
|
||||
@@ -311,7 +409,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 );
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -344,7 +450,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);
|
||||
@@ -371,12 +486,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 );
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user