Changeset 57755
- Timestamp:
- 03/02/2024 08:13:02 PM (5 months ago)
- Location:
- trunk
- Files:
-
- 1 added
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/ajax-actions.php
r57648 r57755 4036 4036 4037 4037 /** This filter is documented in wp-admin/includes/class-custom-image-header.php */ 4038 $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication. 4039 $attachment = $wp_site_icon->create_attachment_object( $cropped, $attachment_id ); 4040 unset( $attachment['ID'] ); 4038 $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication. 4039 4040 // Copy attachment properties. 4041 $attachment = wp_copy_parent_attachment_properties( $cropped, $attachment_id, $context ); 4041 4042 4042 4043 // Update the attachment. �� … 4066 4067 $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication. 4067 4068 4068 $parent_url = wp_get_attachment_url( $attachment_id ); 4069 $parent_basename = wp_basename( $parent_url ); 4070 $url = str_replace( $parent_basename, wp_basename( $cropped ), $parent_url ); 4071 4072 $size = wp_getimagesize( $cropped ); 4073 $image_type = ( $size ) ? $size['mime'] : 'image/jpeg'; 4074 4075 // Get the original image's post to pre-populate the cropped image. 4076 $original_attachment = get_post( $attachment_id ); 4077 $sanitized_post_title = sanitize_file_name( $original_attachment->post_title ); 4078 $use_original_title = ( 4079 ( '' !== trim( $original_attachment->post_title ) ) && 4080 /* 4081 * Check if the original image has a title other than the "filename" default, 4082 * meaning the image had a title when originally uploaded or its title was edited. 4083 */ 4084 ( $parent_basename !== $sanitized_post_title ) && 4085 ( pathinfo( $parent_basename, PATHINFO_FILENAME ) !== $sanitized_post_title ) 4086 ); 4087 $use_original_description = ( '' !== trim( $original_attachment->post_content ) ); 4088 4089 $attachment = array( 4090 'post_title' => $use_original_title ? $original_attachment->post_title : wp_basename( $cropped ), 4091 'post_content' => $use_original_description ? $original_attachment->post_content : $url, 4092 'post_mime_type' => $image_type, 4093 'guid' => $url, 4094 'context' => $context, 4095 ); 4096 4097 // Copy the image caption attribute (post_excerpt field) from the original image. 4098 if ( '' !== trim( $original_attachment->post_excerpt ) ) { 4099 $attachment['post_excerpt'] = $original_attachment->post_excerpt; 4100 } 4101 4102 // Copy the image alt text attribute from the original image. 4103 if ( '' !== trim( $original_attachment->_wp_attachment_image_alt ) ) { 4104 $attachment['meta_input'] = array( 4105 '_wp_attachment_image_alt' => wp_slash( $original_attachment->_wp_attachment_image_alt ), 4106 ); 4107 } 4069 // Copy attachment properties. 4070 $attachment = wp_copy_parent_attachment_properties( $cropped, $attachment_id, $context ); 4108 4071 4109 4072 $attachment_id = wp_insert_attachment( $attachment, $cropped ); -
trunk/src/wp-admin/includes/class-custom-image-header.php
r57364 r57755 1078 1078 $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication. 1079 1079 1080 $attachment = $this->create_attachment_object( $cropped, $attachment_id);1080 $attachment = ); 1081 1081 1082 1082 if ( ! empty( $_POST['create-new-attachment'] ) ) { … … 1315 1315 * 1316 1316 * @since 3.9.0 1317 1317 1318 * 1318 1319 * @param string $cropped Cropped image URL. … … 1321 1322 */ 1322 1323 final public function create_attachment_object( $cropped, $parent_attachment_id ) { 1324 1323 1325 $parent = get_post( $parent_attachment_id ); 1324 1326 $parent_url = wp_get_attachment_url( $parent->ID ); … … 1422 1424 $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication. 1423 1425 1424 $attachment = $this->create_attachment_object( $cropped, $attachment_id);1426 $attachment = ); 1425 1427 1426 1428 $previous = $this->get_previous_crop( $attachment ); -
trunk/src/wp-admin/includes/class-wp-site-icon.php
r55678 r57755 79 79 * 80 80 * @since 4.3.0 81 81 82 * 82 83 * @param string $cropped Cropped image URL. … … 85 86 */ 86 87 public function create_attachment_object( $cropped, $parent_attachment_id ) { 88 89 87 90 $parent = get_post( $parent_attachment_id ); 88 91 $parent_url = wp_get_attachment_url( $parent->ID ); -
trunk/src/wp-admin/includes/image.php
r57524 r57755 481 481 482 482 return $image_meta; 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 483 539 } 484 540 -
trunk/tests/phpunit/tests/image/header.php
r56548 r57755 109 109 } 110 110 111 public function test_create_attachment_object() {112 $id = wp_insert_attachment(113 array(114 'post_status' => 'publish',115 'post_title' => 'foo.png',116 'post_type' => 'post',117 'guid' => 'http://localhost/foo.png',118 )119 );120 121 $cropped = 'foo-cropped.png';122 123 $object = $this->custom_image_header->create_attachment_object( $cropped, $id );124 $this->assertSame( 'foo-cropped.png', $object['post_title'] );125 $this->assertSame( 'http://localhost/' . $cropped, $object['guid'] );126 $this->assertSame( 'custom-header', $object['context'] );127 $this->assertSame( 'image/jpeg', $object['post_mime_type'] );128 }129 130 111 public function test_insert_cropped_attachment() { 131 112 $id = wp_insert_attachment( … … 139 120 140 121 $cropped = 'foo-cropped.png'; 141 $object = $this->custom_image_header->create_attachment_object( $cropped, $id);122 $object = ); 142 123 143 124 $cropped_id = $this->custom_image_header->insert_attachment( $object, $cropped ); … … 162 143 // Create inital crop object. 163 144 $cropped_1 = 'foo-cropped-1.png'; 164 $object = $this->custom_image_header->create_attachment_object( $cropped_1, $id);145 $object = ); 165 146 166 147 // Ensure no previous crop exists. … … 176 157 // Create second crop. 177 158 $cropped_2 = 'foo-cropped-2.png'; 178 $object = $this->custom_image_header->create_attachment_object( $cropped_2, $id );159 $object = ( $cropped_2, $id ); 179 160 180 161 // Test that a previous crop is found. -
trunk/tests/phpunit/tests/image/siteIcon.php
r52010 r57755 99 99 } 100 100 101 public function test_create_attachment_object() {102 $attachment_id = $this->insert_attachment();103 $parent_url = get_post( $attachment_id )->guid;104 $cropped = str_replace( wp_basename( $parent_url ), 'cropped-test-image.jpg', $parent_url );105 106 $object = $this->wp_site_icon->create_attachment_object( $cropped, $attachment_id );107 108 $this->assertSame( $object['post_title'], 'cropped-test-image.jpg' );109 $this->assertSame( $object['context'], 'site-icon' );110 $this->assertSame( $object['post_mime_type'], 'image/jpeg' );111 $this->assertSame( $object['post_content'], $cropped );112 $this->assertSame( $object['guid'], $cropped );113 }114 115 101 public function test_insert_cropped_attachment() { 116 102 $attachment_id = $this->insert_attachment(); … … 118 104 $cropped = str_replace( wp_basename( $parent_url ), 'cropped-test-image.jpg', $parent_url ); 119 105 120 $object = $this->wp_site_icon->create_attachment_object( $cropped, $attachment_id);106 $object = ); 121 107 $cropped_id = $this->wp_site_icon->insert_attachment( $object, $cropped ); 122 108
Note: See TracChangeset
for help on using the changeset viewer.