WordPress.org

Make WordPress Core

Ticket #16891: 16891.diff

File 16891.diff, 4.1 KB (added by garyc40, 4 years ago)
  • wp-admin/includes/media.php

    diff --git wp-admin/includes/media.php wp-admin/includes/media.php
    index 5a13bcc..0a977d8 100644
    function media_upload_tabs() { 
    3333 * @return unknown 
    3434 */ 
    3535function update_gallery_tab($tabs) { 
     36        static $attachments = null; 
    3637        global $wpdb; 
    3738 
    3839        if ( !isset($_REQUEST['post_id']) ) { 
    function update_gallery_tab($tabs) { 
    4243 
    4344        $post_id = intval($_REQUEST['post_id']); 
    4445 
    45         if ( $post_id ) 
     46        if ( $post_id && is_null( $attachments ) ) 
    4647                $attachments = intval( $wpdb->get_var( $wpdb->prepare( "SELECT count(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent = %d", $post_id ) ) ); 
    4748 
    4849        if ( empty($attachments) ) { 
    function get_media_items( $post_id, $errors ) { 
    11711172 * @return string HTML form for attachment. 
    11721173 */ 
    11731174function get_media_item( $attachment_id, $args = null ) { 
    1174         global $redir_tab; 
     1175        global $redir_tab, $tab; 
    11751176 
    11761177        if ( ( $attachment_id = intval( $attachment_id ) ) && $thumb_url = wp_get_attachment_image_src( $attachment_id, 'thumbnail', true ) ) 
    11771178                $thumb_url = $thumb_url[0]; 
    function get_media_item( $attachment_id, $args = null ) { 
    12851286        if ( $send ) 
    12861287                $send = get_submit_button( __( 'Insert into Post' ), 'button', "send[$attachment_id]", false ); 
    12871288        if ( $delete && current_user_can( 'delete_post', $attachment_id ) ) { 
     1289                $wp_redirect = empty( $redir_tab ) || $redir_tab == $tab ? '' : '&_wp_http_referer=' . urlencode(add_query_arg('tab', $redir_tab)); 
    12881290                if ( !EMPTY_TRASH_DAYS ) { 
    1289                         $delete = "<a href='" . wp_nonce_url( "post.php?action=delete&amp;post=$attachment_id", 'delete-attachment_' . $attachment_id ) . "' id='del[$attachment_id]' class='delete'>" . __( 'Delete Permanently' ) . '</a>'; 
     1291                        $delete = "<a href='" . wp_nonce_url( "post.php?action=delete&amp;post={$attachment_id}{$wp_redirect}", 'delete-attachment_' . $attachment_id ) . "' id='del[$attachment_id]' class='delete'>" . __( 'Delete Permanently' ) . '</a>'; 
    12901292                } elseif ( !MEDIA_TRASH ) { 
    12911293                        $delete = "<a href='#' class='del-link' onclick=\"document.getElementById('del_attachment_$attachment_id').style.display='block';return false;\">" . __( 'Delete' ) . "</a> 
    12921294                         <div id='del_attachment_$attachment_id' class='del-attachment' style='display:none;'>" . sprintf( __( 'You are about to delete <strong>%s</strong>.' ), $filename ) . " 
    1293                          <a href='" . wp_nonce_url( "post.php?action=delete&amp;post=$attachment_id", 'delete-attachment_' . $attachment_id ) . "' id='del[$attachment_id]' class='button'>" . __( 'Continue' ) . "</a> 
     1295                         <a href='" . wp_nonce_url( "post.php?action=delete&amp;post={$attachment_id}{$wp_redirect}", 'delete-attachment_' . $attachment_id ) . "' id='del[$attachment_id]' class='button'>" . __( 'Continue' ) . "</a> 
    12941296                         <a href='#' class='button' onclick=\"this.parentNode.style.display='none';return false;\">" . __( 'Cancel' ) . "</a> 
    12951297                         </div>"; 
    12961298                } else { 
    1297                         $delete = "<a href='" . wp_nonce_url( "post.php?action=trash&amp;post=$attachment_id", 'trash-attachment_' . $attachment_id ) . "' id='del[$attachment_id]' class='delete'>" . __( 'Move to Trash' ) . "</a> 
     1299                        $delete = "<a href='" . wp_nonce_url( "post.php?action=trash&amp;post={$attachment_id}{$wp_redirect}", 'trash-attachment_' . $attachment_id ) . "' id='del[$attachment_id]' class='delete'>" . __( 'Move to Trash' ) . "</a> 
    12981300                        <a href='" . wp_nonce_url( "post.php?action=untrash&amp;post=$attachment_id", 'untrash-attachment_' . $attachment_id ) . "' id='undo[$attachment_id]' class='undo hidden'>" . __( 'Undo' ) . "</a>"; 
    12991301                } 
    13001302        } else { 
  • wp-admin/media-upload.php

    diff --git wp-admin/media-upload.php wp-admin/media-upload.php
    index 19eda09..c6406e4 100644
    if ( isset($_GET['inline']) ) { 
    108108                $type = apply_filters('media_upload_default_type', 'file'); 
    109109 
    110110        // tab: gallery, library, or type-specific 
     111        $tabs = media_upload_tabs(); 
     112         
    111113        if ( isset($_GET['tab']) ) 
    112114                $tab = strval($_GET['tab']); 
    113         else 
    114                 $tab = apply_filters('media_upload_default_tab', 'type'); 
     115 
     116        if ( empty( $tab ) || empty( $tabs[$tab] ) ) 
     117                $tab = apply_filters( 'media_upload_default_tab', 'type' ); 
    115118 
    116119        $body_id = 'media-upload'; 
    117120