Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93

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