Make WordPress Core

Changeset 22528


Ignore:
Timestamp:
11/10/2012 08:40:35 AM (14 years ago)
Author:
koopersmith
Message:

Media: Keep the selected featured image in the media modal in sync with the page. fixes #22404, see #21390.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/meta-boxes.php

    r22500 r22528  
    10101010                        title        = '<?php _e( "Choose a Featured Image" ); ?>',
    10111011                        update       = '<?php _e( "Update Featured Image" ); ?>',
     1012                        Attachment   = wp.media.model.Attachment,
    10121013                        frame, setFeaturedImage;
    10131014
    10141015                setFeaturedImage = function( thumbnailId ) {
     1016                        var selection;
     1017
    10151018                        $element.find('img').remove();
    10161019                        $element.toggleClass( 'has-featured-image', -1 != thumbnailId );
    10171020                        $thumbnailId.val( thumbnailId );
     1021
     1022                        if ( frame ) {
     1023                                selection = frame.get('library').get('selection');
     1024
     1025                                if ( -1 === thumbnailId )
     1026                                        selection.clear();
     1027                                else
     1028                                        selection.add( Attachment.get( thumbnailId ) );
     1029                        }
    10181030                };
    10191031
    10201032                $element.on( 'click', '.choose, img', function( event ) {
     1033                        var options, thumbnailId;
     1034
    10211035                        event.preventDefault();
    10221036
    … …  
    10261040                        }
    10271041
    1028                         frame = wp.media({
    1029                                 title:     title,
    1030                                 selection: [ wp.media.model.Attachment.get( $thumbnailId.val() ) ],
    1031                                 library:   {
     1042                        options = {
     1043                                title:   title,
     1044                                library: {
    10321045                                        type: 'image'
    10331046                                }
    1034                         });
     1047                        };
     1048
     1049                        thumbnailId = $thumbnailId.val();
     1050                        if ( '' !== thumbnailId && -1 !== thumbnailId )
     1051                                options.selection = [ Attachment.get( thumbnailId ) ];
     1052
     1053                        frame = wp.media( options );
    10351054
    10361055                        frame.toolbar.on( 'activate:select', function() {
Note: See TracChangeset for help on using the changeset viewer.