Changeset 57755 for trunk/src/wp-admin/includes/image.php
- Timestamp:
- 03/02/2024 08:13:02 PM (11 months ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/image.php
r57524 r57755 481 481 482 482 return $image_meta; 483 } 484 485 /** 486 * Copy parent attachment properties to newly cropped image. 487 * 488 * @since 6.5.0 489 * 490 * @param string $cropped Path to the cropped image file. 491 * @param int $parent_attachment_id Parent file Attachment ID. 492 * @param string $context Control calling the function. 493 * @return array Properties of attachment. 494 */ 495 function wp_copy_parent_attachment_properties( $cropped, $parent_attachment_id, $context = '' ) { 496 $parent = get_post( $parent_attachment_id ); 497 $parent_url = wp_get_attachment_url( $parent->ID ); 498 $parent_basename = wp_basename( $parent_url ); 499 $url = str_replace( wp_basename( $parent_url ), wp_basename( $cropped ), $parent_url ); 500 501 $size = wp_getimagesize( $cropped ); 502 $image_type = $size ? $size['mime'] : 'image/jpeg'; 503 504 $sanitized_post_title = sanitize_file_name( $parent->post_title ); 505 $use_original_title = ( 506 ( '' !== trim( $parent->post_title ) ) && 507 /* 508 * Check if the original image has a title other than the "filename" default, 509 * meaning the image had a title when originally uploaded or its title was edited. 510 */ 511 ( $parent_basename !== $sanitized_post_title ) && 512 ( pathinfo( $parent_basename, PATHINFO_FILENAME ) !== $sanitized_post_title ) 513 ); 514 $use_original_description = ( '' !== trim( $parent->post_content ) ); 515 516 $attachment = array( 517 'post_title' => $use_original_title ? $parent->post_title : wp_basename( $cropped ), 518 'post_content' => $use_original_description ? $parent->post_content : $url, 519 'post_mime_type' => $image_type, 520 'guid' => $url, 521 'context' => $context, 522 ); 523 524 // Copy the image caption attribute (post_excerpt field) from the original image. 525 if ( '' !== trim( $parent->post_excerpt ) ) { 526 $attachment['post_excerpt'] = $parent->post_excerpt; 527 } 528 529 // Copy the image alt text attribute from the original image. 530 if ( '' !== trim( $parent->_wp_attachment_image_alt ) ) { 531 $attachment['meta_input'] = array( 532 '_wp_attachment_image_alt' => wp_slash( $parent->_wp_attachment_image_alt ), 533 ); 534 } 535 536 $attachment['post_parent'] = $parent_attachment_id; 537 538 return $attachment; 483 539 } 484 540
Note: See TracChangeset
for help on using the changeset viewer.