Make WordPress Core

Ticket #22524: 22524.3.diff

File 22524.3.diff, 5.7 KB (added by koopersmith, 12 years ago)
  • wp-admin/includes/ajax-actions.php

     
    18431843        if ( ! $id = absint( $_REQUEST['id'] ) )
    18441844                wp_send_json_error();
    18451845
    1846         check_ajax_referer( 'save-attachment', 'nonce' );
     1846        check_ajax_referer( 'update-post_' . $id, 'nonce' );
    18471847
    18481848        if ( ! current_user_can( 'edit_post', $id ) )
    18491849                wp_send_json_error();
     
    18891889                wp_send_json_error();
    18901890        $attachment_data = $_REQUEST['attachments'][ $id ];
    18911891
    1892         check_ajax_referer( 'save-attachment', 'nonce' );
     1892        check_ajax_referer( 'update-post_' . $id, 'nonce' );
    18931893
    18941894        if ( ! current_user_can( 'edit_post', $id ) )
    18951895                wp_send_json_error();
  • wp-includes/css/media-views.css

     
    11851185        float: left;
    11861186}
    11871187
     1188.attachment-info .delete-attachment a {
     1189        color: red;
     1190        padding: 2px 4px;
     1191        margin: -2px -4px;
     1192        text-decoration: none;
     1193}
     1194
     1195.attachment-info .delete-attachment a:hover {
     1196        color: #fff;
     1197        background: red;
     1198}
     1199
    11881200/**
    11891201 * Attachment Display Settings
    11901202 */
  • wp-includes/js/media-models.js

     
    218218         */
    219219        Attachment = media.model.Attachment = Backbone.Model.extend({
    220220                sync: function( method, model, options ) {
     221                        // If the attachment does not yet have an `id`, return an instantly
     222                        // rejected promise. Otherwise, all of our requests will fail.
     223                        if ( _.isUndefined( this.id ) )
     224                                return $.Deferred().reject().promise();
     225
    221226                        // Overload the `read` request so Attachment.fetch() functions correctly.
    222227                        if ( 'read' === method ) {
    223228                                options = options || {};
     
    237242                                options.data = _.extend( options.data || {}, {
    238243                                        action: 'save-attachment',
    239244                                        id:     this.id,
    240                                         nonce:  media.model.settings.saveAttachmentNonce
     245                                        nonce:  this.get('nonces').update
    241246                                });
    242247
    243248                                // Record the values of the changed attributes.
     
    251256                                }
    252257
    253258                                return media.ajax( options );
     259
     260                        // Overload the `delete` request so attachments can be removed.
     261                        // This will permanently delete an attachment.
     262                        } else if ( 'delete' === method ) {
     263                                options = options || {};
     264                                options.context = this;
     265                                options.data = _.extend( options.data || {}, {
     266                                        action:   'delete-post',
     267                                        id:       this.id,
     268                                        _wpnonce: this.get('nonces')['delete']
     269                                });
     270                                return media.ajax( options );
    254271                        }
    255272                },
    256273
     
    269286
    270287                        return media.post( 'save-attachment-compat', _.defaults({
    271288                                id:     this.id,
    272                                 nonce:  media.model.settings.saveAttachmentNonce
     289                                nonce:  this.get('nonces').update
    273290                        }, data ) ).done( function( resp, status, xhr ) {
    274291                                model.set( model.parse( resp, xhr ), options );
    275292                        });
  • wp-includes/js/media-views.js

     
    34033403                        'change [data-setting]':          'updateSetting',
    34043404                        'change [data-setting] input':    'updateSetting',
    34053405                        'change [data-setting] select':   'updateSetting',
    3406                         'change [data-setting] textarea': 'updateSetting'
     3406                        'change [data-setting] textarea': 'updateSetting',
     3407                        'click .delete-attachment':       'deleteAttachment'
     3408                },
     3409
     3410                deleteAttachment: function(event) {
     3411                        event.preventDefault();
     3412
     3413                        if ( confirm( l10n.warnDelete ) )
     3414                                this.model.destroy();
    34073415                }
    34083416        });
    34093417
  • wp-includes/media.php

     
    13271327                'subtype'     => $subtype,
    13281328                'icon'        => wp_mime_type_icon( $attachment->ID ),
    13291329                'dateFormatted' => mysql2date( get_option('date_format'), $attachment->post_date ),
     1330                'nonces'      => array(
     1331                        'update' => wp_create_nonce( 'update-post_' . $attachment->ID ),
     1332                        'delete' => wp_create_nonce( 'delete-post_' . $attachment->ID ),
     1333                ),
    13301334        );
    13311335
    13321336        if ( $meta && 'image' === $type ) {
     
    14521456                'allMediaItems'      => __( 'All media items' ),
    14531457                'insertIntoPost'     => $hier ? __( 'Insert into page' ) : __( 'Insert into post' ),
    14541458                'uploadedToThisPost' => $hier ? __( 'Uploaded to this page' ) : __( 'Uploaded to this post' ),
     1459                'warnDelete' =>      __( "You are about to permanently delete this item.\n  'Cancel' to stop, 'OK' to delete." ),
    14551460
    14561461                // Embed
    14571462                'embedFromUrlTitle' => __( 'Embed From URL' ),
     
    16421647                                <# if ( 'image' === data.type && ! data.uploading ) { #>
    16431648                                        <div class="dimensions">{{ data.width }} &times; {{ data.height }}</div>
    16441649                                <# } #>
     1650                                <# if ( ! data.uploading ) { #>
     1651                                        <div class="delete-attachment">
     1652                                                <a href="#"><?php _e( 'Delete Permanently' ); ?></a>
     1653                                        </div>
     1654                                <# } #>
    16451655                        </div>
    16461656                        <div class="compat-meta">
    16471657                                <# if ( data.compat && data.compat.meta ) { #>
  • wp-includes/script-loader.php

     
    322322        $scripts->add( 'media-models', "/wp-includes/js/media-models$suffix.js", array( 'backbone', 'jquery' ), false, 1 );
    323323        did_action( 'init' ) && $scripts->localize( 'media-models', '_wpMediaModelsL10n', array(
    324324                'settings' => array(
    325                         'saveAttachmentNonce' => wp_create_nonce( 'save-attachment' ),
    326325                        'ajaxurl' => admin_url( 'admin-ajax.php', 'relative' ),
    327326                ),
    328327        ) );