Changeset 53027 for trunk/src/wp-admin/includes/ajax-actions.php
- Timestamp:
- 03/29/2022 09:46:09 PM (2 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/wp-admin/includes/ajax-actions.php
r52978 r53027 3971 3971 $cropped = apply_filters( 'wp_create_file_in_uploads', $cropped, $attachment_id ); // For replication. 3972 3972 3973 $parent_url = wp_get_attachment_url( $attachment_id ); 3974 $url = str_replace( wp_basename( $parent_url ), wp_basename( $cropped ), $parent_url ); 3973 $parent_url = wp_get_attachment_url( $attachment_id ); 3974 $parent_basename = wp_basename( $parent_url ); 3975 $url = str_replace( $parent_basename, wp_basename( $cropped ), $parent_url ); 3975 3976 3976 3977 $size = wp_getimagesize( $cropped ); 3977 3978 $image_type = ( $size ) ? $size['mime'] : 'image/jpeg'; 3978 3979 3980 // Get the original image's post to pre-populate the cropped image. 3981 $original_attachment = get_post( $attachment_id ); 3982 $sanitized_post_title = sanitize_file_name( $original_attachment->post_title ); 3983 $use_original_title = ( 3984 ( '' !== trim( $original_attachment->post_title ) ) && 3985 /* 3986 * Check if the original image has a title other than the "filename" default, 3987 * meaning the image had a title when originally uploaded or its title was edited. 3988 */ 3989 ( $parent_basename !== $sanitized_post_title ) && 3990 ( pathinfo( $parent_basename, PATHINFO_FILENAME ) !== $sanitized_post_title ) 3991 ); 3992 $use_original_description = ( '' !== trim( $original_attachment->post_content ) ); 3993 3979 3994 $object = array( 3980 'post_title' => wp_basename( $cropped ),3981 'post_content' => $u rl,3995 'post_title' => $use_original_title ? $original_attachment->post_title : wp_basename( $cropped ), 3996 'post_content' => $use_original_description ? $original_attachment->post_content : $url, 3982 3997 'post_mime_type' => $image_type, 3983 3998 'guid' => $url, 3984 3999 'context' => $context, 3985 4000 ); 4001 4002 // Copy the image caption attribute (post_excerpt field) from the original image. 4003 if ( '' !== trim( $original_attachment->post_excerpt ) ) { 4004 $object['post_excerpt'] = $original_attachment->post_excerpt; 4005 } 4006 4007 // Copy the image alt text attribute from the original image. 4008 if ( '' !== trim( $original_attachment->_wp_attachment_image_alt ) ) { 4009 $object['meta_input'] = array( 4010 '_wp_attachment_image_alt' => wp_slash( $original_attachment->_wp_attachment_image_alt ), 4011 ); 4012 } 3986 4013 3987 4014 $attachment_id = wp_insert_attachment( $object, $cropped );
Note: See TracChangeset
for help on using the changeset viewer.