Changeset 52946
- Timestamp:
- 03/17/2022 08:17:48 PM (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/class-custom-image-header.php
r52610 r52946 976 976 $filename = wp_basename( $file ); 977 977 978 // Construct the object array.979 $ object = array(978 // Construct the array with attachment object data. 979 $attachment = array( 980 980 'post_title' => $filename, 981 981 'post_content' => $url, … … 986 986 987 987 // Save the data. 988 $attachment_id = wp_insert_attachment( $ object, $file );988 $attachment_id = wp_insert_attachment( $attachment, $file ); 989 989 990 990 return compact( 'attachment_id', 'file', 'filename', 'url', 'type' ); … … 1062 1062 $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication. 1063 1063 1064 $ object = $this->create_attachment_object( $cropped, $attachment_id );1064 $attachment = $this->create_attachment_object( $cropped, $attachment_id ); 1065 1065 1066 1066 if ( ! empty( $_POST['create-new-attachment'] ) ) { 1067 unset( $ object['ID'] );1067 unset( $attachment['ID'] ); 1068 1068 } 1069 1069 1070 1070 // Update the attachment. 1071 $attachment_id = $this->insert_attachment( $ object, $cropped );1071 $attachment_id = $this->insert_attachment( $attachment, $cropped ); 1072 1072 1073 1073 $url = wp_get_attachment_url( $attachment_id ); … … 1301 1301 * @param string $cropped Cropped image URL. 1302 1302 * @param int $parent_attachment_id Attachment ID of parent image. 1303 * @return array A ttachment object.1303 * @return array An array with attachment object data. 1304 1304 */ 1305 1305 final public function create_attachment_object( $cropped, $parent_attachment_id ) { … … 1311 1311 $image_type = ( $size ) ? $size['mime'] : 'image/jpeg'; 1312 1312 1313 $ object = array(1313 $attachment = array( 1314 1314 'ID' => $parent_attachment_id, 1315 1315 'post_title' => wp_basename( $cropped ), … … 1320 1320 ); 1321 1321 1322 return $ object;1322 return $attachment; 1323 1323 } 1324 1324 … … 1328 1328 * @since 3.9.0 1329 1329 * 1330 * @param array $ object Attachment object.1331 * @param string $cropped File path to cropped image.1330 * @param array $attachment An array with attachment object data. 1331 * @param string $cropped File path to cropped image. 1332 1332 * @return int Attachment ID. 1333 1333 */ 1334 final public function insert_attachment( $ object, $cropped ) {1335 $parent_id = isset( $ object['post_parent'] ) ? $object['post_parent'] : null;1336 unset( $ object['post_parent'] );1337 1338 $attachment_id = wp_insert_attachment( $ object, $cropped );1334 final public function insert_attachment( $attachment, $cropped ) { 1335 $parent_id = isset( $attachment['post_parent'] ) ? $attachment['post_parent'] : null; 1336 unset( $attachment['post_parent'] ); 1337 1338 $attachment_id = wp_insert_attachment( $attachment, $cropped ); 1339 1339 $metadata = wp_generate_attachment_metadata( $attachment_id, $cropped ); 1340 1340 … … 1405 1405 $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication. 1406 1406 1407 $ object = $this->create_attachment_object( $cropped, $attachment_id );1408 1409 $previous = $this->get_previous_crop( $ object );1407 $attachment = $this->create_attachment_object( $cropped, $attachment_id ); 1408 1409 $previous = $this->get_previous_crop( $attachment ); 1410 1410 1411 1411 if ( $previous ) { 1412 $ object['ID'] = $previous;1412 $attachment['ID'] = $previous; 1413 1413 } else { 1414 unset( $ object['ID'] );1415 } 1416 1417 $new_attachment_id = $this->insert_attachment( $ object, $cropped );1418 1419 $ object['attachment_id'] = $new_attachment_id;1420 $ object['url'] = wp_get_attachment_url( $new_attachment_id );1421 1422 $ object['width'] = $dimensions['dst_width'];1423 $ object['height'] = $dimensions['dst_height'];1424 1425 wp_send_json_success( $ object );1414 unset( $attachment['ID'] ); 1415 } 1416 1417 $new_attachment_id = $this->insert_attachment( $attachment, $cropped ); 1418 1419 $attachment['attachment_id'] = $new_attachment_id; 1420 $attachment['url'] = wp_get_attachment_url( $new_attachment_id ); 1421 1422 $attachment['width'] = $dimensions['dst_width']; 1423 $attachment['height'] = $dimensions['dst_height']; 1424 1425 wp_send_json_success( $attachment ); 1426 1426 } 1427 1427 … … 1578 1578 * @since 4.9.0 1579 1579 * 1580 * @param array $ object A crop attachment object.1580 * @param array $attachment An array with a cropped attachment object data. 1581 1581 * @return int|false An attachment ID if one exists. False if none. 1582 1582 */ 1583 public function get_previous_crop( $ object ) {1583 public function get_previous_crop( $attachment ) { 1584 1584 $header_images = $this->get_uploaded_header_images(); 1585 1585 … … 1592 1592 1593 1593 foreach ( $header_images as $image ) { 1594 if ( $image['attachment_parent'] === $ object['post_parent'] ) {1594 if ( $image['attachment_parent'] === $attachment['post_parent'] ) { 1595 1595 $previous = $image['attachment_id']; 1596 1596 break;
Note: See TracChangeset
for help on using the changeset viewer.