WordPress.org

Make WordPress Core

Ticket #21329: 21329.5.diff

File 21329.5.diff, 7.1 KB (added by martythornley, 3 years ago)

Fixed version of previous patches

  • wp-admin/includes/media.php

     
    77 */ 
    88 
    99/** 
    10  * {@internal Missing Short Description}} 
     10 * Defines media tabs to be used in thickbox  
    1111 * 
    1212 * @since 2.5.0 
    1313 * 
    14  * @return unknown 
     14 * @uses apply_filters() calls media_upload_tabs 
     15 * 
     16 * @return an associative array of tab names in the form of type=>name 
    1517 */ 
    1618function media_upload_tabs() { 
    1719        $_default_tabs = array( 
     
    2527} 
    2628 
    2729/** 
    28  * {@internal Missing Short Description}} 
     30 * Added to media_upload_tabs filter to define the gallery tab 
     31 * checks for attachments and removes gallery tab if the current post has none. 
    2932 * 
    3033 * @since 2.5.0 
    3134 * 
    32  * @param unknown_type $tabs 
    33  * @return unknown 
     35 * @param array $tabs 
     36 * @return an associative array of tab names in the form of type=>name 
    3437 */ 
    3538function update_gallery_tab($tabs) { 
    3639        global $wpdb; 
     
    5760add_filter('media_upload_tabs', 'update_gallery_tab'); 
    5861 
    5962/** 
    60  * {@internal Missing Short Description}} 
     63 * Echoes the thickbox media upload tabs to the screen 
    6164 * 
    6265 * @since 2.5.0 
    6366 */ 
     
    6568        global $redir_tab; 
    6669        $tabs = media_upload_tabs(); 
    6770        $default = 'type'; 
    68  
     71        $html = ''; 
     72         
    6973        if ( !empty($tabs) ) { 
    70                 echo "<ul id='sidemenu'>\n"; 
     74                $html = "<ul id='sidemenu'>\n"; 
    7175                if ( isset($redir_tab) && array_key_exists($redir_tab, $tabs) ) 
    7276                        $current = $redir_tab; 
    7377                elseif ( isset($_GET['tab']) && array_key_exists($_GET['tab'], $tabs) ) 
     
    8387 
    8488                        $href = add_query_arg(array('tab' => $callback, 's' => false, 'paged' => false, 'post_mime_type' => false, 'm' => false)); 
    8589                        $link = "<a href='" . esc_url($href) . "'$class>$text</a>"; 
    86                         echo "\t<li id='" . esc_attr("tab-$callback") . "'>$link</li>\n"; 
     90                        $html .= "\t<li id='" . esc_attr("tab-$callback") . "'>$link</li>\n"; 
    8791                } 
    88                 echo "</ul>\n"; 
     92                $html .= "</ul>\n"; 
    8993        } 
     94        echo $html; 
    9095} 
    9196 
    9297/** 
    93  * {@internal Missing Short Description}} 
     98 * Creates the html for an image as it is added to the editor 
    9499 * 
    95100 * @since 2.5.0 
    96101 * 
     102 * @uses apply_filters() calls image_send_to_editor 
    97103 * @param unknown_type $id 
    98104 * @param unknown_type $alt 
    99105 * @param unknown_type $title 
     
    101107 * @param unknown_type $url 
    102108 * @param unknown_type $rel 
    103109 * @param unknown_type $size 
    104  * @return unknown 
     110 * @return string - the html for an image tag 
    105111 */ 
    106112function get_image_send_to_editor($id, $caption, $title, $align, $url='', $rel = false, $size='medium', $alt = '') { 
    107113 
     
    118124} 
    119125 
    120126/** 
    121  * {@internal Missing Short Description}} 
     127 * Wraps an image in the caption code 
    122128 * 
    123129 * @since 2.6.0 
    124130 * 
     
    170176} 
    171177 
    172178/** 
    173  * {@internal Missing Short Description}} 
     179 * Echoes the javascript used to send html back to the editor 
    174180 * 
    175181 * @since 2.5.0 
    176182 * 
    177  * @param unknown_type $html 
     183 * @param string $html 
    178184 */ 
    179185function media_send_to_editor($html) { 
    180186?> 
     
    189195} 
    190196 
    191197/** 
    192  * {@internal Missing Short Description}} 
    193  * 
    194198 * This handles the file upload POST itself, creating the attachment post. 
    195199 * 
    196200 * @since 2.5.0 
     
    260264 * 
    261265 * @since 2.6.0 
    262266 * 
     267 * @uses wp_handle_sideload 
     268 * @uses wp_read_image_metadata 
     269 * @uses wp_insert_attachment 
     270 * @uses wp_update_attachment_metadata 
     271 * @uses wp_generate_attachment_metadata 
    263272 * @param array $file_array Array similar to a {@link $_FILES} upload array 
    264273 * @param int $post_id The post ID the media is associated with 
    265274 * @param string $desc Description of the sideloaded file 
     
    312321} 
    313322 
    314323/** 
    315  * {@internal Missing Short Description}} 
     324 * Generates html for the iframe used in the thickbox window for uploads 
    316325 * 
    317326 * Wrap iframe content (produced by $content_func) in a doctype, html head/body 
    318327 * etc any additional function args will be passed to content_func. 
     
    373382} 
    374383 
    375384/** 
    376  * {@internal Missing Short Description}} 
     385 * Echoes the html for media upload buttons 
     386 * added to the action call for 'media_buttons'  
    377387 * 
    378388 * @since 2.5.0 
    379389 */ 
     
    386396} 
    387397add_action( 'media_buttons', 'media_buttons' ); 
    388398 
     399/** 
     400 * Determine url of the upload thickbox to be used in the media_buttons() link 
     401 * 
     402 * @uses apply_filters() calls $type . '_upload_iframe_src' 
     403 * @param string $type 
     404 * @param int $post_id 
     405 * @param string $tab 
     406 * @since unknown 
     407 */ 
    389408function get_upload_iframe_src( $type = null, $post_id = null, $tab = null ) { 
    390409        global $post_ID; 
    391410 
     
    565584 
    566585        if ( isset($_POST['save']) ) { 
    567586                $errors['upload_notice'] = __('Saved.'); 
    568                 return media_upload_gallery(); 
     587                return media_upload('gallery'); 
    569588        } 
    570589 
    571590        if ( isset($_GET['tab']) && $_GET['tab'] == 'type_url' ) { 
     
    625644} 
    626645 
    627646/** 
    628  * {@internal Missing Short Description}} 
     647 * Returns wp_iframe with the proper upload form for media uploads 
     648 * added to the media_upload filter in media-upload.php 
    629649 * 
    630  * @since 2.5.0 
     650 * @since 3.5.0 
    631651 * 
    632  * @return unknown 
     652 * @return HTML from the wp_iframe function 
    633653 */ 
    634 function media_upload_gallery() { 
     654function media_upload() { 
    635655        $errors = array(); 
    636  
    637         if ( !empty($_POST) ) { 
     656        $current_filter = current_filter(); 
     657        $type = str_replace( 'media_upload_' , '' , $current_filter ); 
     658         
     659        if ( !empty($_POST) || empty($type) ) { 
    638660                $return = media_upload_form_handler(); 
    639  
    640661                if ( is_string($return) ) 
    641662                        return $return; 
    642663                if ( is_array($return) ) 
     
    644665        } 
    645666 
    646667        wp_enqueue_script('admin-gallery'); 
    647         return wp_iframe( 'media_upload_gallery_form', $errors ); 
     668         
     669        switch($type) { 
     670                case 'library' : 
     671                                $return = 'media_upload_library_form'; 
     672                        break; 
     673                case 'gallery' : 
     674                                $return = 'media_upload_gallery_form'; 
     675                        break; 
     676                default : 
     677                                $return = 'wp_media_upload_handler'; 
     678                        break;                           
     679        } 
     680        return wp_iframe( $return , $errors ); 
    648681} 
    649682 
    650683/** 
     
    654687 * 
    655688 * @return unknown 
    656689 */ 
     690function media_upload_gallery() { 
     691        media_upload( 'gallery' ); 
     692} 
     693 
     694/** 
     695 * {@internal Missing Short Description}} 
     696 * 
     697 * @since 2.5.0 
     698 * 
     699 * @return unknown 
     700 */ 
    657701function media_upload_library() { 
    658         $errors = array(); 
    659         if ( !empty($_POST) ) { 
    660                 $return = media_upload_form_handler(); 
    661  
    662                 if ( is_string($return) ) 
    663                         return $return; 
    664                 if ( is_array($return) ) 
    665                         $errors = $return; 
    666         } 
    667  
    668         return wp_iframe( 'media_upload_library_form', $errors ); 
     702        media_upload( 'library' ); 
    669703} 
    670704 
    671705/** 
     
    21002134add_filter( 'async_upload_video', 'get_media_item', 10, 2 ); 
    21012135add_filter( 'async_upload_file',  'get_media_item', 10, 2 ); 
    21022136 
    2103 add_action( 'media_upload_image', 'wp_media_upload_handler' ); 
    2104 add_action( 'media_upload_audio', 'wp_media_upload_handler' ); 
    2105 add_action( 'media_upload_video', 'wp_media_upload_handler' ); 
    2106 add_action( 'media_upload_file',  'wp_media_upload_handler' ); 
     2137add_action( 'media_upload_image', 'media_upload' ); 
     2138add_action( 'media_upload_audio', 'media_upload' ); 
     2139add_action( 'media_upload_video', 'media_upload' ); 
     2140add_action( 'media_upload_file',  'media_upload' ); 
    21072141 
    2108 add_filter( 'media_upload_gallery', 'media_upload_gallery' ); 
    2109 add_filter( 'media_upload_library', 'media_upload_library' ); 
     2142add_filter( 'media_upload_gallery', 'media_upload' ); 
     2143add_filter( 'media_upload_library', 'media_upload' );