WordPress.org

Make WordPress Core

Changeset 6820


Ignore:
Timestamp:
02/13/2008 06:36:40 PM (10 years ago)
Author:
ryan
Message:

Finish making upload tabs pluggable. Props andy. fixes #5843

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-admin/includes/media.php

    r6795 r6820  
    88    return apply_filters('image_upload_tabs', $_default_tabs);
    99}
     10
     11function the_image_upload_tabs() {
     12    $tabs = image_upload_tabs();
     13
     14    if ( !empty($tabs) ) {
     15        echo "<ul id='media-upload-tabs'>\n";
     16        if ( isset($_GET['tab']) && array_key_exists($_GET['tab'], $tabs) )
     17            $current = $_GET['tab'];
     18        else
     19            $current = array_shift(array_keys($tabs));
     20        foreach ( $tabs as $callback => $text ) {
     21            if ( ++$i == count($tabs) )
     22                $class = ' class="last"';
     23            if ( $callback == $current )
     24                $disabled = ' disabled="disabled"';
     25            else
     26                $disabled = '';
     27            $href = add_query_arg('tab', $callback);
     28            if ( $callback == $current )
     29                $link = $text;
     30            else
     31                $link = "<a href='$href'>$text</a>";
     32            echo "\t<li$class>$link</li>\n";
     33        }
     34        echo "</ul>\n";
     35    }
     36}
     37
     38function image_upload_callback() {
     39    $tabs = image_upload_tabs();
     40    if ( isset($_GET['tab']) && array_key_exists($_GET['tab'], $tabs) && is_callable($_GET['tab']) )
     41        return $_GET['tab']();
     42    elseif ( is_callable($first = array_shift(array_keys($tabs))) )
     43        return $first();
     44    else
     45        return image_upload_handler();
     46}
     47
     48add_action('media_upload_image', 'image_upload_callback');
    1049
    1150function image_upload_form( $action_url, $values = array(), $error = null ) {
     
    1958?>
    2059<div id="media-upload-header">
    21 <h3>Add Image</h3>
    22 <ul id="media-upload-tabs">
    23     <li><?php _e('From Computer'); ?></li>
    24     <li><?php _e('Media Library'); ?></li>
    25     <li class="last"><?php _e('Flickr'); ?></li>
    26 </ul>
     60<h3><?php _e('Add Image') ?></h3>
     61<?php the_image_upload_tabs(); ?>
    2762</div>
    2863<div id="media-upload-error">
     
    389424
    390425add_action('media_upload_multimedia', 'multimedia_upload_handler');
    391 add_action('media_upload_image', 'image_upload_handler');
    392426add_action('admin_head_image_upload_form', 'media_admin_css');
    393427
Note: See TracChangeset for help on using the changeset viewer.