Changeset 57755 for trunk/src/wp-admin/includes/ajax-actions.php
- Timestamp:
- 03/02/2024 08:13:02 PM (11 months ago)
- File:
-
- 1 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 );
Note: See TracChangeset
for help on using the changeset viewer.