Make WordPress Core

Changeset 21770


Ignore:
Timestamp:
09/06/2012 08:49:35 AM (14 years ago)
Author:
koopersmith
Message:

First pass at integrating featured images with the new media workflow.

Updates the featured image when the publish/update button is clicked (rather than instantly). Uses the existing post_thumbnail_meta_box() function. Does not remove the old featured image meta box JS, ajax handler, or CSS.

see #21776, #21390.

Location:
trunk
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/css/wp-admin.css

    r21671 r21770  
    2424        11.1 - Custom Fields
    2525        11.2 - Post Revisions
     26        11.3 - Featured Images
    262712.0 - Categories
    272813.0 - Tags
     
    32403241}
    32413242
     3243/*------------------------------------------------------------------------------
     3244  11.3 - Featured Images
     3245------------------------------------------------------------------------------*/
     3246
     3247#select-featured-image {
     3248        padding: 4px 0;
     3249        overflow: hidden;
     3250}
     3251
     3252#select-featured-image img {
     3253        max-width: 100%;
     3254        height: auto;
     3255        margin-bottom: 10px;
     3256}
     3257
     3258#select-featured-image a {
     3259        float: left;
     3260        clear: both;
     3261}
     3262
     3263#select-featured-image .remove {
     3264        display: none;
     3265        margin-top: 10px;
     3266}
     3267
     3268#select-featured-image.has-featured-image .remove {
     3269        display: inline-block;
     3270}
    32423271
    32433272/*------------------------------------------------------------------------------
  • trunk/wp-admin/includes/meta-boxes.php

    r21735 r21770  
    912912 */
    913913function post_thumbnail_meta_box( $post ) {
    914         $thumbnail_id = get_post_meta( $post->ID, '_thumbnail_id', true );
    915         echo _wp_post_thumbnail_html( $thumbnail_id );
    916 }
     914        global $_wp_additional_image_sizes;
     915
     916        ?><script type="text/javascript">
     917        jQuery( function($) {
     918                var $element     = $('#select-featured-image'),
     919                        $thumbnailId = $element.find('input[name="thumbnail_id"]'),
     920                        title        = '<?php _e( "Choose a Featured Image" ); ?>',
     921                        workflow, setFeaturedImage;
     922
     923                setFeaturedImage = function( thumbnailId ) {
     924                        $element.find('img').remove();
     925                        $element.toggleClass( 'has-featured-image', -1 != thumbnailId );
     926                        $thumbnailId.val( thumbnailId );
     927                };
     928
     929                $element.on( 'click', '.choose, img', function( event ) {
     930                        event.preventDefault();
     931
     932                        if ( ! workflow ) {
     933                                workflow = wp.media();
     934                                workflow.selection.on( 'add', function( model ) {
     935                                        var sizes = model.get('sizes'),
     936                                                size;
     937
     938                                        setFeaturedImage( model.id );
     939
     940                                        // @todo: might need a size hierarchy equivalent.
     941                                        if ( sizes )
     942                                                size = sizes['post-thumbnail'] || sizes.medium;
     943
     944                                        // @todo: Need a better way of accessing full size
     945                                        // data besides just calling toJSON().
     946                                        size = size || model.toJSON();
     947
     948                                        workflow.modal.close();
     949                                        workflow.selection.clear();
     950
     951                                        $( '<img />', {
     952                                                src:    size.url,
     953                                                width:  size.width
     954                                        }).prependTo( $element );
     955                                });
     956                                workflow.modal.title( title );
     957                        }
     958
     959                        workflow.modal.open();
     960                });
     961
     962                $element.on( 'click', '.remove', function( event ) {
     963                        event.preventDefault();
     964                        setFeaturedImage( -1 );
     965                });
     966        });
     967        </script>
     968
     969        <?php
     970        $thumbnail_id   = get_post_meta( $post->ID, '_thumbnail_id', true );
     971        $thumbnail_size = isset( $_wp_additional_image_sizes['post-thumbnail'] ) ? 'post-thumbnail' : 'medium';
     972        $thumbnail_html = wp_get_attachment_image( $thumbnail_id, $thumbnail_size );
     973
     974        $classes = empty( $thumbnail_id ) ? '' : 'has-featured-image';
     975
     976        ?><div id="select-featured-image"
     977                class="<?php echo esc_attr( $classes ); ?>"
     978                data-post-id="<?php echo esc_attr( $post->ID ); ?>">
     979                <?php echo $thumbnail_html; ?>
     980                <input type="hidden" name="thumbnail_id" value="<?php echo esc_attr( $thumbnail_id ); ?>" />
     981                <a href="#" class="choose button-secondary"><?php _e( 'Choose a Featured Image' ); ?></a>
     982                <a href="#" class="remove"><?php _e( 'Remove Featured Image' ); ?></a>
     983        </div>
     984        <?php
     985}
  • trunk/wp-admin/includes/post.php

    r21735 r21770  
    197197                elseif ( '0' == $post_data['post_format'] )
    198198                        set_post_format( $post_ID, false );
     199        }
     200
     201        // Featured Images
     202        if ( isset( $post_data['thumbnail_id'] ) ) {
     203                if ( '-1' == $post_data['thumbnail_id'] )
     204                        delete_post_thumbnail( $post_ID );
     205                else
     206                        set_post_thumbnail( $post_ID, $post_data['thumbnail_id'] );
    199207        }
    200208
  • trunk/wp-includes/script-loader.php

    r21697 r21770  
    319319        did_action( 'init' ) && $scripts->localize( 'media-views', '_wpMediaViewsL10n', array(
    320320                'insertMedia'         => __( 'Insert Media' ),
    321                 'chooseFeatured'      => __( 'Choose a Featured Image' ),
    322321                'selectMediaSingular' => __( 'Select a media file:' ),
    323322                'selectMediaMultiple' => __( 'Select one or more media files:' ),
Note: See TracChangeset for help on using the changeset viewer.