WordPress.org

Make WordPress Core

Changeset 41937


Ignore:
Timestamp:
10/19/2017 04:17:31 AM (20 months ago)
Author:
joemcgill
Message:

Customizer: Improve handling of crops in the media library.

This is a follow up on r41732, implementing the following improvements:

  • Attachment parent info is now stored in attachment meta rather than a

separate post meta key.

  • Attachments created from contextual crops (e.g. header, logos, etc.) are

filtered out of the media library using a new _filterContext method in
wp.media.controller.Library.

Props joemcgill, westonruter.
See #21819.

Location:
trunk/src
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/wp-admin/custom-header.php

    r41732 r41937  
    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.
     
    11981203         */
    11991204        $metadata = apply_filters( 'wp_header_image_attachment_metadata', $metadata );
     1205
    12001206        wp_update_attachment_metadata( $attachment_id, $metadata );
    1201 
    1202         if ( $parent_id ) {
    1203             $meta = add_post_meta( $attachment_id, '_wp_attachment_parent', $parent_id, true );
    1204         }
    12051207
    12061208        return $attachment_id;
  • trunk/src/wp-includes/js/media-views.js

    r41752 r41937  
    954954        }
    955955
     956        this._filterContext();
     957        this.get('library').on( 'add', this._filterContext, this );
     958
    956959        this.resetDisplays();
    957960    },
     
    11531156            setUserSetting( 'libraryContent', mode );
    11541157        }
     1158    },
     1159
     1160    /**
     1161     * Filter out contextually created attachments (e.g. headers, logos, etc.)
     1162     *
     1163     * @since 4.9.0
     1164     */
     1165    _filterContext: function() {
     1166        var library = this.get('library');
     1167
     1168        library.set( library.filter( function( item ) {
     1169            return item.get('context') === '';
     1170        } ) );
    11551171    }
    11561172});
  • trunk/src/wp-includes/js/media/controllers/library.js

    r41351 r41937  
    8686        }
    8787
     88        this._filterContext();
     89        this.get('library').on( 'add', this._filterContext, this );
     90
    8891        this.resetDisplays();
    8992    },
     
    285288            setUserSetting( 'libraryContent', mode );
    286289        }
     290    },
     291
     292    /**
     293     * Filter out contextually created attachments (e.g. headers, logos, etc.)
     294     *
     295     * @since 4.9.0
     296     */
     297    _filterContext: function() {
     298        var library = this.get('library');
     299
     300        library.set( library.filter( function( item ) {
     301            return item.get('context') === '';
     302        } ) );
    287303    }
    288304});
  • trunk/src/wp-includes/media.php

    r41724 r41937  
    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 );
  • trunk/src/wp-includes/theme.php

    r41887 r41937  
    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'] ) )
Note: See TracChangeset for help on using the changeset viewer.