Make WordPress Core

Ticket #16165: 16165_r21080.patch

File 16165_r21080.patch, 3.0 KB (added by bpetty, 11 years ago)
  • wp-admin/upload.php

    diff --git wp-admin/upload.php wp-admin/upload.php
    index d172327..5e5a185 100644
    if ( $doaction ) { 
    3636                        $location = remove_query_arg( array( 'trashed', 'untrashed', 'deleted', 'message', 'ids', 'posted' ), $referer );
    3737        }
    3838
     39        $errors = array();
     40
     41        // Escape item titles displayed in error messages.
     42        add_filter( 'the_title', 'esc_html' );
     43
    3944        switch ( $doaction ) {
    4045                case 'find_detached':
    4146                        if ( !current_user_can('edit_posts') )
    if ( $doaction ) { 
    9499                                break;
    95100                        foreach ( (array) $post_ids as $post_id ) {
    96101                                if ( !current_user_can( 'delete_post', $post_id ) )
    97                                         wp_die( __( 'You are not allowed to move this post to the trash.' ) );
     102                                        $errors[] = sprintf( __( 'You are not allowed to move "%s" to the trash.' ), get_the_title( $post_id ) );
    98103
    99104                                if ( !wp_trash_post( $post_id ) )
    100                                         wp_die( __( 'Error in moving to trash...' ) );
     105                                        $errors[] = sprintf( __( 'There was a problem moving "%s" to the trash.' ), get_the_title( $post_id ) );
     106                        }
     107
     108                        if( ! empty( $errors ) ) {
     109                                $wp_err = new WP_Error();
     110                                foreach( $errors as $err )
     111                                        $wp_err->add( 'bulk_media_trash_error', $err );
     112                                wp_die( $wp_err );
    101113                        }
     114
    102115                        $location = add_query_arg( array( 'trashed' => count( $post_ids ), 'ids' => join( ',', $post_ids ) ), $location );
    103116                        break;
    104117                case 'untrash':
    if ( $doaction ) { 
    106119                                break;
    107120                        foreach ( (array) $post_ids as $post_id ) {
    108121                                if ( !current_user_can( 'delete_post', $post_id ) )
    109                                         wp_die( __( 'You are not allowed to move this post out of the trash.' ) );
     122                                        $errors[] = sprintf( __( 'You are not allowed to move "%s" out of the trash.' ), get_the_title( $post_id ) );
    110123
    111124                                if ( !wp_untrash_post( $post_id ) )
    112                                         wp_die( __( 'Error in restoring from trash...' ) );
     125                                        $errors[] = sprintf( __( 'There was a problem restoring "%s" from the trash.' ), get_the_title( $post_id ) );
     126                        }
     127
     128                        if( ! empty( $errors ) ) {
     129                                $wp_err = new WP_Error();
     130                                foreach( $errors as $err )
     131                                        $wp_err->add( 'bulk_media_untrash_error', $err );
     132                                wp_die( $wp_err );
    113133                        }
     134
    114135                        $location = add_query_arg( 'untrashed', count( $post_ids ), $location );
    115136                        break;
    116137                case 'delete':
    117138                        if ( !isset( $post_ids ) )
    118139                                break;
    119140                        foreach ( (array) $post_ids as $post_id_del ) {
     141                                if( !get_post( $post_id_del ) )
     142                                        continue;
     143
    120144                                if ( !current_user_can( 'delete_post', $post_id_del ) )
    121                                         wp_die( __( 'You are not allowed to delete this post.' ) );
     145                                        $errors[] = sprintf( __( 'You are not allowed to delete "%s".' ), get_the_title( $post_id_del ) );
    122146
    123147                                if ( !wp_delete_attachment( $post_id_del ) )
    124                                         wp_die( __( 'Error in deleting...' ) );
     148                                        $errors[] = sprintf( __( 'There was a problem deleting "%s".' ), get_the_title( $post_id_del ) );
    125149                        }
     150
     151                        if( ! empty( $errors ) ) {
     152                                $wp_err = new WP_Error();
     153                                foreach( $errors as $err )
     154                                        $wp_err->add( 'bulk_media_delete_error', $err );
     155                                wp_die( $wp_err );
     156                        }
     157
    126158                        $location = add_query_arg( 'deleted', count( $post_ids ), $location );
    127159                        break;
    128160        }