WordPress.org

Make WordPress Core

Ticket #21329: 21329.4.diff

File 21329.4.diff, 9.4 KB (added by martythornley, 6 years ago)

remove media_upload_gallery and media_upload_library, add comments about functions that could be deprecated to end of file

  • 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 * Download an image from the specified URL and attach it to a post.
    629648 *
    630  * @since 2.5.0
     649 * @since 2.6.0
    631650 *
    632  * @return unknown
     651 * @param string $file The URL of the image to download
     652 * @param int $post_id The post ID the media is to be associated with
     653 * @param string $desc Optional. Description of the image
     654 * @return string|WP_Error Populated HTML img tag on success
    633655 */
    634 function media_upload_gallery() {
    635         $errors = array();
     656function media_sideload_image($file, $post_id, $desc = null) {
     657        if ( ! empty($file) ) {
     658                // Download file to temp location
     659                $tmp = download_url( $file );
    636660
    637         if ( !empty($_POST) ) {
    638                 $return = media_upload_form_handler();
     661                // Set variables for storage
     662                // fix file filename for query strings
     663                preg_match( '/[^\?]+\.(jpe?g|jpe|gif|png)\b/i', $file, $matches );
     664                $file_array['name'] = basename($matches[0]);
     665                $file_array['tmp_name'] = $tmp;
    639666
    640                 if ( is_string($return) )
    641                         return $return;
    642                 if ( is_array($return) )
    643                         $errors = $return;
     667                // If error storing temporarily, unlink
     668                if ( is_wp_error( $tmp ) ) {
     669                        @unlink($file_array['tmp_name']);
     670                        $file_array['tmp_name'] = '';
     671                }
     672
     673                // do the validation and storage stuff
     674                $id = media_handle_sideload( $file_array, $post_id, $desc );
     675                // If error storing permanently, unlink
     676                if ( is_wp_error($id) ) {
     677                        @unlink($file_array['tmp_name']);
     678                        return $id;
     679                }
     680
     681                $src = wp_get_attachment_url( $id );
    644682        }
    645683
    646         wp_enqueue_script('admin-gallery');
    647         return wp_iframe( 'media_upload_gallery_form', $errors );
     684        // Finally check to make sure the file has been saved, then return the html
     685        if ( ! empty($src) ) {
     686                $alt = isset($desc) ? esc_attr($desc) : '';
     687                $html = "<img src='$src' alt='$alt' />";
     688                return $html;
     689        }
    648690}
    649691
    650692/**
    651  * {@internal Missing Short Description}}
     693 * Returns wp_iframe with the proper upload form for media uploads
     694 * added to the media_upload filter in media-upload.php
    652695 *
    653  * @since 2.5.0
     696 * @since 3.5.0
    654697 *
    655  * @return unknown
     698 * @return HTML from the wp_iframe function
    656699 */
    657 function media_upload_library() {
     700function media_upload_form() {
    658701        $errors = array();
    659         if ( !empty($_POST) ) {
     702        $current_filter = current_filter();
     703        $type = str_replace( 'media_upload_' , '' , $current_filter );
     704       
     705        if ( !empty($_POST) || empty($type) ) {
    660706                $return = media_upload_form_handler();
    661 
    662707                if ( is_string($return) )
    663708                        return $return;
    664709                if ( is_array($return) )
    665710                        $errors = $return;
    666711        }
    667712
    668         return wp_iframe( 'media_upload_library_form', $errors );
     713        wp_enqueue_script('admin-gallery');
     714       
     715        switch($type) {
     716                case 'library' :
     717                                $return = 'media_upload_library_form';
     718                        break;
     719                case 'gallery' :
     720                                $return = 'media_upload_gallery_form';
     721                        break;
     722                default :
     723                                $return = 'wp_media_upload_handler';
     724                        break;                         
     725        }
     726        return wp_iframe( $return , $errors );
    669727}
    670728
    671729/**
     
    21002158add_filter( 'async_upload_video', 'get_media_item', 10, 2 );
    21012159add_filter( 'async_upload_file',  'get_media_item', 10, 2 );
    21022160
    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' );
     2161add_action( 'media_upload_image', 'media_upload_form' );
     2162add_action( 'media_upload_audio', 'media_upload_form' );
     2163add_action( 'media_upload_video', 'media_upload_form' );
     2164add_action( 'media_upload_file',  'media_upload_form' );
    21072165
    2108 add_filter( 'media_upload_gallery', 'media_upload_gallery' );
    2109 add_filter( 'media_upload_library', 'media_upload_library' );
     2166add_filter( 'media_upload_gallery', 'media_upload_form' );
     2167add_filter( 'media_upload_library', 'media_upload_form' );
     2168
     2169
     2170// These can be deprecated ( if needed at all )
     2171
     2172/*
     2173 * was only used once. Replaced media_upload_gallery() with media_upload( 'gallery' )
     2174 */
     2175function media_upload_gallery() {
     2176        media_upload( 'gallery' );
     2177}
     2178
     2179/*
     2180 * was not used anywhere
     2181 */
     2182function media_upload_library() {
     2183        media_upload( 'library' );
     2184}
     2185
     2186/*
     2187 * consolidated into new media_upload_form
     2188 */
     2189function media_upload_gallery() {
     2190        $errors = array();
     2191
     2192        if ( !empty($_POST) ) {
     2193                $return = media_upload_form_handler();
     2194
     2195                if ( is_string($return) )
     2196                        return $return;
     2197                if ( is_array($return) )
     2198                        $errors = $return;
     2199        }
     2200
     2201        wp_enqueue_script('admin-gallery');
     2202        return wp_iframe( 'media_upload_gallery_form', $errors );
     2203}
     2204
     2205/*
     2206 * consolidated into new media_upload_form
     2207 */
     2208function media_upload_library() {
     2209        $errors = array();
     2210        if ( !empty($_POST) ) {
     2211                $return = media_upload_form_handler();
     2212
     2213                if ( is_string($return) )
     2214                        return $return;
     2215                if ( is_array($return) )
     2216                        $errors = $return;
     2217        }
     2218
     2219        return wp_iframe( 'media_upload_library_form', $errors );
     2220}
     2221 No newline at end of file