Make WordPress Core

Ticket #21819: 21819.3.diff

File 21819.3.diff, 4.4 KB (added by joemcgill, 8 years ago)
  • src/wp-admin/custom-header.php

    diff --git src/wp-admin/custom-header.php src/wp-admin/custom-header.php
    index 8b2973fc11..aa6d619625 100644
    wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?> 
    11871187                $attachment_id = wp_insert_attachment( $object, $cropped );
    11881188                $metadata = wp_generate_attachment_metadata( $attachment_id, $cropped );
    11891189
     1190                // If this is a crop, save the original attachment ID as metadata.
     1191                if ( $parent_id ) {
     1192                        $metadata['attachment_parent'] = $parent_id;
     1193                }
     1194               
    11901195                /**
    11911196                 * Filters the header image attachment metadata.
    11921197                 *
    wp_nonce_field( 'custom-header-options', '_wpnonce-custom-header-options' ); ?> 
    11971202                 * @param array $metadata Attachment metadata.
    11981203                 */
    11991204                $metadata = apply_filters( 'wp_header_image_attachment_metadata', $metadata );
    1200                 wp_update_attachment_metadata( $attachment_id, $metadata );
    12011205
    1202                 if ( $parent_id ) {
    1203                         $meta = add_post_meta( $attachment_id, '_wp_attachment_parent', $parent_id, true );
    1204                 }
     1206                wp_update_attachment_metadata( $attachment_id, $metadata );
    12051207
    12061208                return $attachment_id;
    12071209        }
  • src/wp-includes/js/media-views.js

    diff --git src/wp-includes/js/media-views.js src/wp-includes/js/media-views.js
    index 2e462971e2..fddfd7a5a4 100644
    Library = wp.media.controller.State.extend(/** @lends wp.media.controller.Librar 
    953953                        }) );
    954954                }
    955955
     956                this.get('library').on( 'add', this._filterContext, this );
     957
    956958                this.resetDisplays();
    957959        },
    958960
    Library = wp.media.controller.State.extend(/** @lends wp.media.controller.Librar 
    11521154                if ( view && view.get( mode ) ) {
    11531155                        setUserSetting( 'libraryContent', mode );
    11541156                }
     1157        },
     1158
     1159        /**
     1160         * Filter out contextually created attachments (e.g. headers, logos, etc.)
     1161         *
     1162         * @since 4.9.0
     1163         */
     1164        _filterContext: function() {
     1165                var library = this.get('library');
     1166
     1167                library.set( library.filter( function( item ) {
     1168                        return item.get('context') === '';
     1169                } ) );
    11551170        }
    11561171});
    11571172
  • src/wp-includes/js/media/controllers/library.js

    diff --git src/wp-includes/js/media/controllers/library.js src/wp-includes/js/media/controllers/library.js
    index 89dc0f4daa..52fad4da32 100644
    Library = wp.media.controller.State.extend(/** @lends wp.media.controller.Librar 
    8585                        }) );
    8686                }
    8787
     88                this.get('library').on( 'add', this._filterContext, this );
     89
    8890                this.resetDisplays();
    8991        },
    9092
    Library = wp.media.controller.State.extend(/** @lends wp.media.controller.Librar 
    284286                if ( view && view.get( mode ) ) {
    285287                        setUserSetting( 'libraryContent', mode );
    286288                }
     289        },
     290
     291        /**
     292         * Filter out contextually created attachments (e.g. headers, logos, etc.)
     293         *
     294         * @since 4.9.0
     295         */
     296        _filterContext: function() {
     297                var library = this.get('library');
     298
     299                library.set( library.filter( function( item ) {
     300                        return item.get('context') === '';
     301                } ) );
    287302        }
    288303});
    289304
  • src/wp-includes/media.php

    diff --git src/wp-includes/media.php src/wp-includes/media.php
    index a280e3e41e..1981f3ad9a 100644
    function wp_prepare_attachment_for_js( $attachment ) { 
    31593159                $response['filesizeHumanReadable'] = size_format( $bytes );
    31603160        }
    31613161
     3162        $context = get_post_meta( $attachment->ID, '_wp_attachment_context', true );
     3163        $response['context'] = ( $context ) ? $context : '';
     3164
    31623165        if ( current_user_can( 'edit_post', $attachment->ID ) ) {
    31633166                $response['nonces']['update'] = wp_create_nonce( 'update-post_' . $attachment->ID );
    31643167                $response['nonces']['edit'] = wp_create_nonce( 'image_editor-' . $attachment->ID );
  • src/wp-includes/theme.php

    diff --git src/wp-includes/theme.php src/wp-includes/theme.php
    index 66390ff2bf..a69f4830cc 100644
    function get_uploaded_header_images() { 
    12141214                $header_images[$header_index]['url'] =  $url;
    12151215                $header_images[$header_index]['thumbnail_url'] = $url;
    12161216                $header_images[$header_index]['alt_text'] = get_post_meta( $header->ID, '_wp_attachment_image_alt', true );
    1217                 $header_images[$header_index]['attachment_parent'] = (int) get_post_meta( $header->ID, '_wp_attachment_parent', true );
     1217                $header_images[$header_index]['attachment_parent'] = isset( $header_data['attachment_parent'] ) ? $header_data['attachment_parent'] : '';
    12181218
    12191219                if ( isset( $header_data['width'] ) )
    12201220                        $header_images[$header_index]['width'] = $header_data['width'];