Edit File by line
/home/zeestwma/ceyloniy.../wp-admin/includes
File: image.php
$created_sizes = $editor->multi_resize( $new_sizes );
[500] Fix | Delete
[501] Fix | Delete
if ( ! empty( $created_sizes ) ) {
[502] Fix | Delete
$image_meta['sizes'] = array_merge( $image_meta['sizes'], $created_sizes );
[503] Fix | Delete
wp_update_attachment_metadata( $attachment_id, $image_meta );
[504] Fix | Delete
}
[505] Fix | Delete
}
[506] Fix | Delete
[507] Fix | Delete
return $image_meta;
[508] Fix | Delete
}
[509] Fix | Delete
[510] Fix | Delete
/**
[511] Fix | Delete
* Copy parent attachment properties to newly cropped image.
[512] Fix | Delete
*
[513] Fix | Delete
* @since 6.5.0
[514] Fix | Delete
*
[515] Fix | Delete
* @param string $cropped Path to the cropped image file.
[516] Fix | Delete
* @param int $parent_attachment_id Parent file Attachment ID.
[517] Fix | Delete
* @param string $context Control calling the function.
[518] Fix | Delete
* @return array Properties of attachment.
[519] Fix | Delete
*/
[520] Fix | Delete
function wp_copy_parent_attachment_properties( $cropped, $parent_attachment_id, $context = '' ) {
[521] Fix | Delete
$parent = get_post( $parent_attachment_id );
[522] Fix | Delete
$parent_url = wp_get_attachment_url( $parent->ID );
[523] Fix | Delete
$parent_basename = wp_basename( $parent_url );
[524] Fix | Delete
$url = str_replace( wp_basename( $parent_url ), wp_basename( $cropped ), $parent_url );
[525] Fix | Delete
[526] Fix | Delete
$size = wp_getimagesize( $cropped );
[527] Fix | Delete
$image_type = $size ? $size['mime'] : 'image/jpeg';
[528] Fix | Delete
[529] Fix | Delete
$sanitized_post_title = sanitize_file_name( $parent->post_title );
[530] Fix | Delete
$use_original_title = (
[531] Fix | Delete
( '' !== trim( $parent->post_title ) ) &&
[532] Fix | Delete
/*
[533] Fix | Delete
* Check if the original image has a title other than the "filename" default,
[534] Fix | Delete
* meaning the image had a title when originally uploaded or its title was edited.
[535] Fix | Delete
*/
[536] Fix | Delete
( $parent_basename !== $sanitized_post_title ) &&
[537] Fix | Delete
( pathinfo( $parent_basename, PATHINFO_FILENAME ) !== $sanitized_post_title )
[538] Fix | Delete
);
[539] Fix | Delete
$use_original_description = ( '' !== trim( $parent->post_content ) );
[540] Fix | Delete
[541] Fix | Delete
$attachment = array(
[542] Fix | Delete
'post_title' => $use_original_title ? $parent->post_title : wp_basename( $cropped ),
[543] Fix | Delete
'post_content' => $use_original_description ? $parent->post_content : $url,
[544] Fix | Delete
'post_mime_type' => $image_type,
[545] Fix | Delete
'guid' => $url,
[546] Fix | Delete
'context' => $context,
[547] Fix | Delete
);
[548] Fix | Delete
[549] Fix | Delete
// Copy the image caption attribute (post_excerpt field) from the original image.
[550] Fix | Delete
if ( '' !== trim( $parent->post_excerpt ) ) {
[551] Fix | Delete
$attachment['post_excerpt'] = $parent->post_excerpt;
[552] Fix | Delete
}
[553] Fix | Delete
[554] Fix | Delete
// Copy the image alt text attribute from the original image.
[555] Fix | Delete
if ( '' !== trim( $parent->_wp_attachment_image_alt ) ) {
[556] Fix | Delete
$attachment['meta_input'] = array(
[557] Fix | Delete
'_wp_attachment_image_alt' => wp_slash( $parent->_wp_attachment_image_alt ),
[558] Fix | Delete
);
[559] Fix | Delete
}
[560] Fix | Delete
[561] Fix | Delete
$attachment['post_parent'] = $parent_attachment_id;
[562] Fix | Delete
[563] Fix | Delete
return $attachment;
[564] Fix | Delete
}
[565] Fix | Delete
[566] Fix | Delete
/**
[567] Fix | Delete
* Generates attachment meta data and create image sub-sizes for images.
[568] Fix | Delete
*
[569] Fix | Delete
* @since 2.1.0
[570] Fix | Delete
* @since 6.0.0 The `$filesize` value was added to the returned array.
[571] Fix | Delete
* @since 6.7.0 The 'image/heic' mime type is supported.
[572] Fix | Delete
*
[573] Fix | Delete
* @param int $attachment_id Attachment ID to process.
[574] Fix | Delete
* @param string $file Filepath of the attached image.
[575] Fix | Delete
* @return array Metadata for attachment.
[576] Fix | Delete
*/
[577] Fix | Delete
function wp_generate_attachment_metadata( $attachment_id, $file ) {
[578] Fix | Delete
$attachment = get_post( $attachment_id );
[579] Fix | Delete
[580] Fix | Delete
$metadata = array();
[581] Fix | Delete
$support = false;
[582] Fix | Delete
$mime_type = get_post_mime_type( $attachment );
[583] Fix | Delete
[584] Fix | Delete
if ( 'image/heic' === $mime_type || ( preg_match( '!^image/!', $mime_type ) && file_is_displayable_image( $file ) ) ) {
[585] Fix | Delete
// Make thumbnails and other intermediate sizes.
[586] Fix | Delete
$metadata = wp_create_image_subsizes( $file, $attachment_id );
[587] Fix | Delete
} elseif ( wp_attachment_is( 'video', $attachment ) ) {
[588] Fix | Delete
$metadata = wp_read_video_metadata( $file );
[589] Fix | Delete
$support = current_theme_supports( 'post-thumbnails', 'attachment:video' ) || post_type_supports( 'attachment:video', 'thumbnail' );
[590] Fix | Delete
} elseif ( wp_attachment_is( 'audio', $attachment ) ) {
[591] Fix | Delete
$metadata = wp_read_audio_metadata( $file );
[592] Fix | Delete
$support = current_theme_supports( 'post-thumbnails', 'attachment:audio' ) || post_type_supports( 'attachment:audio', 'thumbnail' );
[593] Fix | Delete
}
[594] Fix | Delete
[595] Fix | Delete
/*
[596] Fix | Delete
* wp_read_video_metadata() and wp_read_audio_metadata() return `false`
[597] Fix | Delete
* if the attachment does not exist in the local filesystem,
[598] Fix | Delete
* so make sure to convert the value to an array.
[599] Fix | Delete
*/
[600] Fix | Delete
if ( ! is_array( $metadata ) ) {
[601] Fix | Delete
$metadata = array();
[602] Fix | Delete
}
[603] Fix | Delete
[604] Fix | Delete
if ( $support && ! empty( $metadata['image']['data'] ) ) {
[605] Fix | Delete
// Check for existing cover.
[606] Fix | Delete
$hash = md5( $metadata['image']['data'] );
[607] Fix | Delete
$posts = get_posts(
[608] Fix | Delete
array(
[609] Fix | Delete
'fields' => 'ids',
[610] Fix | Delete
'post_type' => 'attachment',
[611] Fix | Delete
'post_mime_type' => $metadata['image']['mime'],
[612] Fix | Delete
'post_status' => 'inherit',
[613] Fix | Delete
'posts_per_page' => 1,
[614] Fix | Delete
'meta_key' => '_cover_hash',
[615] Fix | Delete
'meta_value' => $hash,
[616] Fix | Delete
)
[617] Fix | Delete
);
[618] Fix | Delete
$exists = reset( $posts );
[619] Fix | Delete
[620] Fix | Delete
if ( ! empty( $exists ) ) {
[621] Fix | Delete
update_post_meta( $attachment_id, '_thumbnail_id', $exists );
[622] Fix | Delete
} else {
[623] Fix | Delete
$ext = '.jpg';
[624] Fix | Delete
switch ( $metadata['image']['mime'] ) {
[625] Fix | Delete
case 'image/gif':
[626] Fix | Delete
$ext = '.gif';
[627] Fix | Delete
break;
[628] Fix | Delete
case 'image/png':
[629] Fix | Delete
$ext = '.png';
[630] Fix | Delete
break;
[631] Fix | Delete
case 'image/webp':
[632] Fix | Delete
$ext = '.webp';
[633] Fix | Delete
break;
[634] Fix | Delete
}
[635] Fix | Delete
$basename = str_replace( '.', '-', wp_basename( $file ) ) . '-image' . $ext;
[636] Fix | Delete
$uploaded = wp_upload_bits( $basename, '', $metadata['image']['data'] );
[637] Fix | Delete
if ( false === $uploaded['error'] ) {
[638] Fix | Delete
$image_attachment = array(
[639] Fix | Delete
'post_mime_type' => $metadata['image']['mime'],
[640] Fix | Delete
'post_type' => 'attachment',
[641] Fix | Delete
'post_content' => '',
[642] Fix | Delete
);
[643] Fix | Delete
/**
[644] Fix | Delete
* Filters the parameters for the attachment thumbnail creation.
[645] Fix | Delete
*
[646] Fix | Delete
* @since 3.9.0
[647] Fix | Delete
*
[648] Fix | Delete
* @param array $image_attachment An array of parameters to create the thumbnail.
[649] Fix | Delete
* @param array $metadata Current attachment metadata.
[650] Fix | Delete
* @param array $uploaded {
[651] Fix | Delete
* Information about the newly-uploaded file.
[652] Fix | Delete
*
[653] Fix | Delete
* @type string $file Filename of the newly-uploaded file.
[654] Fix | Delete
* @type string $url URL of the uploaded file.
[655] Fix | Delete
* @type string $type File type.
[656] Fix | Delete
* }
[657] Fix | Delete
*/
[658] Fix | Delete
$image_attachment = apply_filters( 'attachment_thumbnail_args', $image_attachment, $metadata, $uploaded );
[659] Fix | Delete
[660] Fix | Delete
$sub_attachment_id = wp_insert_attachment( $image_attachment, $uploaded['file'] );
[661] Fix | Delete
add_post_meta( $sub_attachment_id, '_cover_hash', $hash );
[662] Fix | Delete
$attach_data = wp_generate_attachment_metadata( $sub_attachment_id, $uploaded['file'] );
[663] Fix | Delete
wp_update_attachment_metadata( $sub_attachment_id, $attach_data );
[664] Fix | Delete
update_post_meta( $attachment_id, '_thumbnail_id', $sub_attachment_id );
[665] Fix | Delete
}
[666] Fix | Delete
}
[667] Fix | Delete
} elseif ( 'application/pdf' === $mime_type ) {
[668] Fix | Delete
// Try to create image thumbnails for PDFs.
[669] Fix | Delete
[670] Fix | Delete
$fallback_sizes = array(
[671] Fix | Delete
'thumbnail',
[672] Fix | Delete
'medium',
[673] Fix | Delete
'large',
[674] Fix | Delete
);
[675] Fix | Delete
[676] Fix | Delete
/**
[677] Fix | Delete
* Filters the image sizes generated for non-image mime types.
[678] Fix | Delete
*
[679] Fix | Delete
* @since 4.7.0
[680] Fix | Delete
*
[681] Fix | Delete
* @param string[] $fallback_sizes An array of image size names.
[682] Fix | Delete
* @param array $metadata Current attachment metadata.
[683] Fix | Delete
*/
[684] Fix | Delete
$fallback_sizes = apply_filters( 'fallback_intermediate_image_sizes', $fallback_sizes, $metadata );
[685] Fix | Delete
[686] Fix | Delete
$registered_sizes = wp_get_registered_image_subsizes();
[687] Fix | Delete
$merged_sizes = array_intersect_key( $registered_sizes, array_flip( $fallback_sizes ) );
[688] Fix | Delete
[689] Fix | Delete
// Force thumbnails to be soft crops.
[690] Fix | Delete
if ( isset( $merged_sizes['thumbnail'] ) && is_array( $merged_sizes['thumbnail'] ) ) {
[691] Fix | Delete
$merged_sizes['thumbnail']['crop'] = false;
[692] Fix | Delete
}
[693] Fix | Delete
[694] Fix | Delete
// Only load PDFs in an image editor if we're processing sizes.
[695] Fix | Delete
if ( ! empty( $merged_sizes ) ) {
[696] Fix | Delete
$editor = wp_get_image_editor( $file );
[697] Fix | Delete
[698] Fix | Delete
if ( ! is_wp_error( $editor ) ) { // No support for this type of file.
[699] Fix | Delete
/*
[700] Fix | Delete
* PDFs may have the same file filename as JPEGs.
[701] Fix | Delete
* Ensure the PDF preview image does not overwrite any JPEG images that already exist.
[702] Fix | Delete
*/
[703] Fix | Delete
$dirname = dirname( $file ) . '/';
[704] Fix | Delete
$ext = '.' . pathinfo( $file, PATHINFO_EXTENSION );
[705] Fix | Delete
$preview_file = $dirname . wp_unique_filename( $dirname, wp_basename( $file, $ext ) . '-pdf.jpg' );
[706] Fix | Delete
[707] Fix | Delete
$uploaded = $editor->save( $preview_file, 'image/jpeg' );
[708] Fix | Delete
unset( $editor );
[709] Fix | Delete
[710] Fix | Delete
// Resize based on the full size image, rather than the source.
[711] Fix | Delete
if ( ! is_wp_error( $uploaded ) ) {
[712] Fix | Delete
$image_file = $uploaded['path'];
[713] Fix | Delete
unset( $uploaded['path'] );
[714] Fix | Delete
[715] Fix | Delete
$metadata['sizes'] = array(
[716] Fix | Delete
'full' => $uploaded,
[717] Fix | Delete
);
[718] Fix | Delete
[719] Fix | Delete
// Save the meta data before any image post-processing errors could happen.
[720] Fix | Delete
wp_update_attachment_metadata( $attachment_id, $metadata );
[721] Fix | Delete
[722] Fix | Delete
// Create sub-sizes saving the image meta after each.
[723] Fix | Delete
$metadata = _wp_make_subsizes( $merged_sizes, $image_file, $metadata, $attachment_id );
[724] Fix | Delete
}
[725] Fix | Delete
}
[726] Fix | Delete
}
[727] Fix | Delete
}
[728] Fix | Delete
[729] Fix | Delete
// Remove the blob of binary data from the array.
[730] Fix | Delete
unset( $metadata['image']['data'] );
[731] Fix | Delete
[732] Fix | Delete
// Capture file size for cases where it has not been captured yet, such as PDFs.
[733] Fix | Delete
if ( ! isset( $metadata['filesize'] ) && file_exists( $file ) ) {
[734] Fix | Delete
$metadata['filesize'] = wp_filesize( $file );
[735] Fix | Delete
}
[736] Fix | Delete
[737] Fix | Delete
/**
[738] Fix | Delete
* Filters the generated attachment meta data.
[739] Fix | Delete
*
[740] Fix | Delete
* @since 2.1.0
[741] Fix | Delete
* @since 5.3.0 The `$context` parameter was added.
[742] Fix | Delete
*
[743] Fix | Delete
* @param array $metadata An array of attachment meta data.
[744] Fix | Delete
* @param int $attachment_id Current attachment ID.
[745] Fix | Delete
* @param string $context Additional context. Can be 'create' when metadata was initially created for new attachment
[746] Fix | Delete
* or 'update' when the metadata was updated.
[747] Fix | Delete
*/
[748] Fix | Delete
return apply_filters( 'wp_generate_attachment_metadata', $metadata, $attachment_id, 'create' );
[749] Fix | Delete
}
[750] Fix | Delete
[751] Fix | Delete
/**
[752] Fix | Delete
* Converts a fraction string to a decimal.
[753] Fix | Delete
*
[754] Fix | Delete
* @since 2.5.0
[755] Fix | Delete
*
[756] Fix | Delete
* @param string $str Fraction string.
[757] Fix | Delete
* @return int|float Returns calculated fraction or integer 0 on invalid input.
[758] Fix | Delete
*/
[759] Fix | Delete
function wp_exif_frac2dec( $str ) {
[760] Fix | Delete
if ( ! is_scalar( $str ) || is_bool( $str ) ) {
[761] Fix | Delete
return 0;
[762] Fix | Delete
}
[763] Fix | Delete
[764] Fix | Delete
if ( ! is_string( $str ) ) {
[765] Fix | Delete
return $str; // This can only be an integer or float, so this is fine.
[766] Fix | Delete
}
[767] Fix | Delete
[768] Fix | Delete
// Fractions passed as a string must contain a single `/`.
[769] Fix | Delete
if ( substr_count( $str, '/' ) !== 1 ) {
[770] Fix | Delete
if ( is_numeric( $str ) ) {
[771] Fix | Delete
return (float) $str;
[772] Fix | Delete
}
[773] Fix | Delete
[774] Fix | Delete
return 0;
[775] Fix | Delete
}
[776] Fix | Delete
[777] Fix | Delete
list( $numerator, $denominator ) = explode( '/', $str );
[778] Fix | Delete
[779] Fix | Delete
// Both the numerator and the denominator must be numbers.
[780] Fix | Delete
if ( ! is_numeric( $numerator ) || ! is_numeric( $denominator ) ) {
[781] Fix | Delete
return 0;
[782] Fix | Delete
}
[783] Fix | Delete
[784] Fix | Delete
// The denominator must not be zero.
[785] Fix | Delete
if ( 0 == $denominator ) { // phpcs:ignore Universal.Operators.StrictComparisons.LooseEqual -- Deliberate loose comparison.
[786] Fix | Delete
return 0;
[787] Fix | Delete
}
[788] Fix | Delete
[789] Fix | Delete
return $numerator / $denominator;
[790] Fix | Delete
}
[791] Fix | Delete
[792] Fix | Delete
/**
[793] Fix | Delete
* Converts the exif date format to a unix timestamp.
[794] Fix | Delete
*
[795] Fix | Delete
* @since 2.5.0
[796] Fix | Delete
*
[797] Fix | Delete
* @param string $str A date string expected to be in Exif format (Y:m:d H:i:s).
[798] Fix | Delete
* @return int|false The unix timestamp, or false on failure.
[799] Fix | Delete
*/
[800] Fix | Delete
function wp_exif_date2ts( $str ) {
[801] Fix | Delete
list( $date, $time ) = explode( ' ', trim( $str ) );
[802] Fix | Delete
list( $y, $m, $d ) = explode( ':', $date );
[803] Fix | Delete
[804] Fix | Delete
return strtotime( "{$y}-{$m}-{$d} {$time}" );
[805] Fix | Delete
}
[806] Fix | Delete
[807] Fix | Delete
/**
[808] Fix | Delete
* Gets extended image metadata, exif or iptc as available.
[809] Fix | Delete
*
[810] Fix | Delete
* Retrieves the EXIF metadata aperture, credit, camera, caption, copyright, iso
[811] Fix | Delete
* created_timestamp, focal_length, shutter_speed, and title.
[812] Fix | Delete
*
[813] Fix | Delete
* The IPTC metadata that is retrieved is APP13, credit, byline, created date
[814] Fix | Delete
* and time, caption, copyright, and title. Also includes FNumber, Model,
[815] Fix | Delete
* DateTimeDigitized, FocalLength, ISOSpeedRatings, and ExposureTime.
[816] Fix | Delete
*
[817] Fix | Delete
* @todo Try other exif libraries if available.
[818] Fix | Delete
* @since 2.5.0
[819] Fix | Delete
*
[820] Fix | Delete
* @param string $file
[821] Fix | Delete
* @return array|false Image metadata array on success, false on failure.
[822] Fix | Delete
*/
[823] Fix | Delete
function wp_read_image_metadata( $file ) {
[824] Fix | Delete
if ( ! file_exists( $file ) ) {
[825] Fix | Delete
return false;
[826] Fix | Delete
}
[827] Fix | Delete
[828] Fix | Delete
$image_size = wp_getimagesize( $file );
[829] Fix | Delete
[830] Fix | Delete
if ( false === $image_size ) {
[831] Fix | Delete
return false;
[832] Fix | Delete
}
[833] Fix | Delete
[834] Fix | Delete
list( , , $image_type ) = $image_size;
[835] Fix | Delete
[836] Fix | Delete
/*
[837] Fix | Delete
* EXIF contains a bunch of data we'll probably never need formatted in ways
[838] Fix | Delete
* that are difficult to use. We'll normalize it and just extract the fields
[839] Fix | Delete
* that are likely to be useful. Fractions and numbers are converted to
[840] Fix | Delete
* floats, dates to unix timestamps, and everything else to strings.
[841] Fix | Delete
*/
[842] Fix | Delete
$meta = array(
[843] Fix | Delete
'aperture' => 0,
[844] Fix | Delete
'credit' => '',
[845] Fix | Delete
'camera' => '',
[846] Fix | Delete
'caption' => '',
[847] Fix | Delete
'created_timestamp' => 0,
[848] Fix | Delete
'copyright' => '',
[849] Fix | Delete
'focal_length' => 0,
[850] Fix | Delete
'iso' => 0,
[851] Fix | Delete
'shutter_speed' => 0,
[852] Fix | Delete
'title' => '',
[853] Fix | Delete
'orientation' => 0,
[854] Fix | Delete
'keywords' => array(),
[855] Fix | Delete
);
[856] Fix | Delete
[857] Fix | Delete
$iptc = array();
[858] Fix | Delete
$info = array();
[859] Fix | Delete
/*
[860] Fix | Delete
* Read IPTC first, since it might contain data not available in exif such
[861] Fix | Delete
* as caption, description etc.
[862] Fix | Delete
*/
[863] Fix | Delete
if ( is_callable( 'iptcparse' ) ) {
[864] Fix | Delete
wp_getimagesize( $file, $info );
[865] Fix | Delete
[866] Fix | Delete
if ( ! empty( $info['APP13'] ) ) {
[867] Fix | Delete
// Don't silence errors when in debug mode, unless running unit tests.
[868] Fix | Delete
if ( defined( 'WP_DEBUG' ) && WP_DEBUG
[869] Fix | Delete
&& ! defined( 'WP_RUN_CORE_TESTS' )
[870] Fix | Delete
) {
[871] Fix | Delete
$iptc = iptcparse( $info['APP13'] );
[872] Fix | Delete
} else {
[873] Fix | Delete
// Silencing notice and warning is intentional. See https://core.trac.wordpress.org/ticket/42480
[874] Fix | Delete
$iptc = @iptcparse( $info['APP13'] );
[875] Fix | Delete
}
[876] Fix | Delete
[877] Fix | Delete
if ( ! is_array( $iptc ) ) {
[878] Fix | Delete
$iptc = array();
[879] Fix | Delete
}
[880] Fix | Delete
[881] Fix | Delete
// Headline, "A brief synopsis of the caption".
[882] Fix | Delete
if ( ! empty( $iptc['2#105'][0] ) ) {
[883] Fix | Delete
$meta['title'] = trim( $iptc['2#105'][0] );
[884] Fix | Delete
/*
[885] Fix | Delete
* Title, "Many use the Title field to store the filename of the image,
[886] Fix | Delete
* though the field may be used in many ways".
[887] Fix | Delete
*/
[888] Fix | Delete
} elseif ( ! empty( $iptc['2#005'][0] ) ) {
[889] Fix | Delete
$meta['title'] = trim( $iptc['2#005'][0] );
[890] Fix | Delete
}
[891] Fix | Delete
[892] Fix | Delete
if ( ! empty( $iptc['2#120'][0] ) ) { // Description / legacy caption.
[893] Fix | Delete
$caption = trim( $iptc['2#120'][0] );
[894] Fix | Delete
[895] Fix | Delete
mbstring_binary_safe_encoding();
[896] Fix | Delete
$caption_length = strlen( $caption );
[897] Fix | Delete
reset_mbstring_encoding();
[898] Fix | Delete
[899] Fix | Delete
if ( empty( $meta['title'] ) && $caption_length < 80 ) {
[900] Fix | Delete
// Assume the title is stored in 2:120 if it's short.
[901] Fix | Delete
$meta['title'] = $caption;
[902] Fix | Delete
}
[903] Fix | Delete
[904] Fix | Delete
$meta['caption'] = $caption;
[905] Fix | Delete
}
[906] Fix | Delete
[907] Fix | Delete
if ( ! empty( $iptc['2#110'][0] ) ) { // Credit.
[908] Fix | Delete
$meta['credit'] = trim( $iptc['2#110'][0] );
[909] Fix | Delete
} elseif ( ! empty( $iptc['2#080'][0] ) ) { // Creator / legacy byline.
[910] Fix | Delete
$meta['credit'] = trim( $iptc['2#080'][0] );
[911] Fix | Delete
}
[912] Fix | Delete
[913] Fix | Delete
if ( ! empty( $iptc['2#055'][0] ) && ! empty( $iptc['2#060'][0] ) ) { // Created date and time.
[914] Fix | Delete
$meta['created_timestamp'] = strtotime( $iptc['2#055'][0] . ' ' . $iptc['2#060'][0] );
[915] Fix | Delete
}
[916] Fix | Delete
[917] Fix | Delete
if ( ! empty( $iptc['2#116'][0] ) ) { // Copyright.
[918] Fix | Delete
$meta['copyright'] = trim( $iptc['2#116'][0] );
[919] Fix | Delete
}
[920] Fix | Delete
[921] Fix | Delete
if ( ! empty( $iptc['2#025'][0] ) ) { // Keywords array.
[922] Fix | Delete
$meta['keywords'] = array_values( $iptc['2#025'] );
[923] Fix | Delete
}
[924] Fix | Delete
}
[925] Fix | Delete
}
[926] Fix | Delete
[927] Fix | Delete
$exif = array();
[928] Fix | Delete
[929] Fix | Delete
/**
[930] Fix | Delete
* Filters the image types to check for exif data.
[931] Fix | Delete
*
[932] Fix | Delete
* @since 2.5.0
[933] Fix | Delete
*
[934] Fix | Delete
* @param int[] $image_types Array of image types to check for exif data. Each value
[935] Fix | Delete
* is usually one of the `IMAGETYPE_*` constants.
[936] Fix | Delete
*/
[937] Fix | Delete
$exif_image_types = apply_filters( 'wp_read_image_metadata_types', array( IMAGETYPE_JPEG, IMAGETYPE_TIFF_II, IMAGETYPE_TIFF_MM ) );
[938] Fix | Delete
[939] Fix | Delete
if ( is_callable( 'exif_read_data' ) && in_array( $image_type, $exif_image_types, true ) ) {
[940] Fix | Delete
// Don't silence errors when in debug mode, unless running unit tests.
[941] Fix | Delete
if ( defined( 'WP_DEBUG' ) && WP_DEBUG
[942] Fix | Delete
&& ! defined( 'WP_RUN_CORE_TESTS' )
[943] Fix | Delete
) {
[944] Fix | Delete
$exif = exif_read_data( $file );
[945] Fix | Delete
} else {
[946] Fix | Delete
// Silencing notice and warning is intentional. See https://core.trac.wordpress.org/ticket/42480
[947] Fix | Delete
$exif = @exif_read_data( $file );
[948] Fix | Delete
}
[949] Fix | Delete
[950] Fix | Delete
if ( ! is_array( $exif ) ) {
[951] Fix | Delete
$exif = array();
[952] Fix | Delete
}
[953] Fix | Delete
[954] Fix | Delete
$exif_description = '';
[955] Fix | Delete
$exif_usercomment = '';
[956] Fix | Delete
if ( ! empty( $exif['ImageDescription'] ) ) {
[957] Fix | Delete
$exif_description = trim( $exif['ImageDescription'] );
[958] Fix | Delete
}
[959] Fix | Delete
[960] Fix | Delete
if ( ! empty( $exif['COMPUTED']['UserComment'] ) ) {
[961] Fix | Delete
$exif_usercomment = trim( $exif['COMPUTED']['UserComment'] );
[962] Fix | Delete
}
[963] Fix | Delete
[964] Fix | Delete
if ( $exif_description ) {
[965] Fix | Delete
mbstring_binary_safe_encoding();
[966] Fix | Delete
$description_length = strlen( $exif_description );
[967] Fix | Delete
reset_mbstring_encoding();
[968] Fix | Delete
if ( empty( $meta['title'] ) && $description_length < 80 ) {
[969] Fix | Delete
// Assume the title is stored in ImageDescription.
[970] Fix | Delete
$meta['title'] = $exif_description;
[971] Fix | Delete
}
[972] Fix | Delete
[973] Fix | Delete
// If both user comments and description are present.
[974] Fix | Delete
if ( empty( $meta['caption'] ) && $exif_usercomment ) {
[975] Fix | Delete
if ( ! empty( $meta['title'] ) && $exif_description === $meta['title'] ) {
[976] Fix | Delete
$caption = $exif_usercomment;
[977] Fix | Delete
} else {
[978] Fix | Delete
if ( $exif_description === $exif_usercomment ) {
[979] Fix | Delete
$caption = $exif_description;
[980] Fix | Delete
} else {
[981] Fix | Delete
$caption = trim( $exif_description . ' ' . $exif_usercomment );
[982] Fix | Delete
}
[983] Fix | Delete
}
[984] Fix | Delete
$meta['caption'] = $caption;
[985] Fix | Delete
}
[986] Fix | Delete
[987] Fix | Delete
if ( empty( $meta['caption'] ) && $exif_usercomment ) {
[988] Fix | Delete
$meta['caption'] = $exif_usercomment;
[989] Fix | Delete
}
[990] Fix | Delete
[991] Fix | Delete
if ( empty( $meta['caption'] ) ) {
[992] Fix | Delete
$meta['caption'] = $exif_description;
[993] Fix | Delete
}
[994] Fix | Delete
} elseif ( empty( $meta['caption'] ) && $exif_usercomment ) {
[995] Fix | Delete
$meta['caption'] = $exif_usercomment;
[996] Fix | Delete
$description_length = strlen( $exif_usercomment );
[997] Fix | Delete
if ( empty( $meta['title'] ) && $description_length < 80 ) {
[998] Fix | Delete
$meta['title'] = trim( $exif_usercomment );
[999] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function