Make WordPress Core

Ticket #60524: 60524.patch

File 60524.patch, 1.8 KB (added by rcreators, 13 months ago)

I have extended class-wp-site-icon -> create_attachment_object to carry forward parent attachment title, alt text, caption and description as well. This will solve the issue.

  • src/wp-admin/includes/class-wp-site-icon.php

    diff --git a/src/wp-admin/includes/class-wp-site-icon.php b/src/wp-admin/includes/class-wp-site-icon.php
    index ff417718f6..6f4dad74b7 100644
    a b class WP_Site_Icon { 
    9191                $size       = wp_getimagesize( $cropped );
    9292                $image_type = ( $size ) ? $size['mime'] : 'image/jpeg';
    9393
     94                $sanitized_post_title = sanitize_file_name( $parent->post_title );
     95                $use_original_title   = (
     96                        ( '' !== trim( $parent->post_title ) ) &&
     97                        /*
     98                         * Check if the original image has a title other than the "filename" default,
     99                         * meaning the image had a title when originally uploaded or its title was edited.
     100                         */
     101                        ( $parent_basename !== $sanitized_post_title ) &&
     102                        ( pathinfo( $parent_basename, PATHINFO_FILENAME ) !== $sanitized_post_title )
     103                );
     104                $use_original_description = ( '' !== trim( $parent->post_content ) );
     105
    94106                $attachment = array(
    95107                        'ID'             => $parent_attachment_id,
    96                         'post_title'     => wp_basename( $cropped ),
    97                         'post_content'   => $url,
     108                        'post_title'     => $use_original_title ? $parent->post_title : wp_basename( $cropped ),
     109                        'post_content'   => $use_original_description ? $parent->post_content : $url,
    98110                        'post_mime_type' => $image_type,
    99111                        'guid'           => $url,
    100112                        'context'        => 'site-icon',
    101113                );
    102114
     115                // Copy the image caption attribute (post_excerpt field) from the original image.
     116                if ( '' !== trim( $parent->post_excerpt ) ) {
     117                        $attachment['post_excerpt'] = $parent->post_excerpt;
     118                }
     119
     120                // Copy the image alt text attribute from the original image.
     121                if ( '' !== trim( $parent->_wp_attachment_image_alt ) ) {
     122                        $attachment['meta_input'] = array(
     123                                '_wp_attachment_image_alt' => wp_slash( $parent->_wp_attachment_image_alt ),
     124                        );
     125                }       
     126
    103127                return $attachment;
    104128        }
    105129