Make WordPress Core

Ticket #21776: 21776.diff

File 21776.diff, 6.9 KB (added by koopersmith, 13 years 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/admin-ajax.php

     
    5151        'sample-permalink', 'inline-save', 'inline-save-tax', 'find_posts', 'widgets-order',
    5252        'save-widget', 'set-post-thumbnail', 'date_format', 'time_format', 'wp-fullscreen-save-post',
    5353        'wp-remove-post-lock', 'dismiss-wp-pointer', 'upload-attachment', 'get-attachment', 'query-attachments',
     54        'set-featured-image',
    5455);
    5556
    5657// Register core Ajax calls.
  • wp-admin/includes/ajax-actions.php

     
    18441844
    18451845        wp_send_json_success( $posts );
    18461846}
     1847
     1848/**
     1849 * Set featured images.
     1850 *
     1851 * @since 3.5.0
     1852 */
     1853function wp_ajax_set_featured_image() {
     1854        $post_ID = intval( $_POST['post_id'] );
     1855        if ( !current_user_can( 'edit_post', $post_ID ) )
     1856                wp_send_json_error();
     1857        $thumbnail_id = intval( $_POST['thumbnail_id'] );
     1858
     1859        check_ajax_referer( "set_post_thumbnail-$post_ID", 'nonce' );
     1860
     1861        if ( $thumbnail_id == '-1' ) {
     1862                if ( delete_post_thumbnail( $post_ID ) )
     1863                        wp_send_json_success();
     1864                else
     1865                        wp_send_json_error();
     1866        }
     1867
     1868        if ( set_post_thumbnail( $post_ID, $thumbnail_id ) )
     1869                wp_send_json_success();
     1870        wp_send_json_error();
     1871}
     1872 No newline at end of file
  • wp-admin/includes/meta-boxes.php

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

     
    32393239        text-decoration: none;
    32403240}
    32413241
     3242/*------------------------------------------------------------------------------
     3243  11.3 - Featured Images
     3244------------------------------------------------------------------------------*/
    32423245
     3246#select-featured-image {
     3247        padding: 4px 0;
     3248        overflow: hidden;
     3249}
     3250
     3251#select-featured-image img {
     3252        max-width: 100%;
     3253        height: auto;
     3254        margin-bottom: 10px;
     3255}
     3256
     3257#select-featured-image a {
     3258        float: left;
     3259        clear: both;
     3260}
     3261
     3262#select-featured-image .remove {
     3263        margin-top: 10px;
     3264        display: none;
     3265}
     3266
     3267#select-featured-image.has-featured-image .remove {
     3268        display: inline-block;
     3269}
     3270
    32433271/*------------------------------------------------------------------------------
    32443272  12.0 - Categories
    32453273------------------------------------------------------------------------------*/