WordPress.org

Make WordPress Core

Ticket #21776: 21776.2.diff

File 21776.2.diff, 6.0 KB (added by koopersmith, 10 months ago)
  • wp-includes/script-loader.php

     
    318318        $scripts->add( 'media-views',  "/wp-includes/js/media-views$suffix.js",  array( 'media-models', 'wp-plupload' ), false, 1 ); 
    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:' ), 
    324323        ) ); 
  • wp-admin/includes/post.php

     
    198198                        set_post_format( $post_ID, false ); 
    199199        } 
    200200 
     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'] ); 
     207        } 
     208 
    201209        // Meta Stuff 
    202210        if ( isset($post_data['meta']) && $post_data['meta'] ) { 
    203211                foreach ( $post_data['meta'] as $key => $value ) { 
  • wp-admin/includes/meta-boxes.php

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

     
    129129        add_meta_box('pageparentdiv', 'page' == $post_type ? __('Page Attributes') : __('Attributes'), 'page_attributes_meta_box', null, 'side', 'core'); 
    130130 
    131131if ( current_theme_supports( 'post-thumbnails', $post_type ) && post_type_supports( $post_type, 'thumbnail' ) ) 
    132                 add_meta_box('postimagediv', __('Featured Image'), 'post_thumbnail_meta_box', null, 'side', 'low'); 
     132                add_meta_box('featuredimagediv', __('Featured Image'), 'featured_image_meta_box', null, 'side', 'low'); 
    133133 
    134134if ( post_type_supports($post_type, 'excerpt') ) 
    135135        add_meta_box('postexcerpt', __('Excerpt'), 'post_excerpt_meta_box', null, 'normal', 'core'); 
  • wp-admin/css/wp-admin.css

     
    232311.0 - Write/Edit Post Screen 
    2424        11.1 - Custom Fields 
    2525        11.2 - Post Revisions 
     26        11.3 - Featured Images 
    262712.0 - Categories 
    272813.0 - Tags 
    282914.0 - Media Screen 
     
    32393240        text-decoration: none; 
    32403241} 
    32413242 
     3243/*------------------------------------------------------------------------------ 
     3244  11.3 - Featured Images 
     3245------------------------------------------------------------------------------*/ 
    32423246 
     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} 
     3271 
    32433272/*------------------------------------------------------------------------------ 
    32443273  12.0 - Categories 
    32453274------------------------------------------------------------------------------*/