Make WordPress Core


Ignore:
Timestamp:
04/06/2010 11:20:47 AM (15 years ago)
Author:
markjaquith
Message:

Make thumbnail work for custom post types even if the editor is not being displayed. props scribu. fixes #12792

File:
1 edited

Legend:

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

    r13940 r14015  
    352352 */
    353353function media_buttons() {
    354     global $post_ID, $temp_ID;
    355     $uploading_iframe_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID);
    356     $context = apply_filters('media_buttons_context', __('Upload/Insert %s'));
    357     $media_upload_iframe_src = "media-upload.php?post_id=$uploading_iframe_ID";
    358     $media_title = __('Add Media');
    359     $image_upload_iframe_src = apply_filters('image_upload_iframe_src', "$media_upload_iframe_src&type=image");
    360     $image_title = __('Add an Image');
    361     $video_upload_iframe_src = apply_filters('video_upload_iframe_src', "$media_upload_iframe_src&type=video");
    362     $video_title = __('Add Video');
    363     $audio_upload_iframe_src = apply_filters('audio_upload_iframe_src', "$media_upload_iframe_src&type=audio");
    364     $audio_title = __('Add Audio');
    365 
    366354    $do_image = $do_audio = $do_video = true;
    367355    if ( is_multisite() ) {
     
    377365
    378366    if ( $do_image )
    379         $out .= "<a href='{$image_upload_iframe_src}&amp;TB_iframe=true' id='add_image' class='thickbox' title='$image_title' onclick='return false;'><img src='" . esc_url( admin_url( 'images/media-button-image.gif' ) ) . "' alt='$image_title' /></a>";
     367        $out .= _media_button(__('Add an Image'), 'images/media-button-image.gif', 'image');
    380368    if ( $do_video )
    381         $out .= "<a href='{$video_upload_iframe_src}&amp;TB_iframe=true' id='add_video' class='thickbox' title='$video_title' onclick='return false;'><img src='" . esc_url( admin_url( 'images/media-button-video.gif' ) ) . "' alt='$video_title' /></a>";
     369        $out .= _media_button(__('Add Video'), 'images/media-button-video.gif', 'video');
    382370    if ( $do_audio )
    383         $out .= "<a href='{$audio_upload_iframe_src}&amp;TB_iframe=true' id='add_audio' class='thickbox' title='$audio_title' onclick='return false;'><img src='" . esc_url( admin_url( 'images/media-button-music.gif' ) ) . "' alt='$audio_title' /></a>";
    384     $out .= "<a href='{$media_upload_iframe_src}&amp;TB_iframe=true' id='add_media' class='thickbox' title='$media_title' onclick='return false;'><img src='" . esc_url( admin_url( 'images/media-button-other.gif' ) ) . "' alt='$media_title' /></a>";
     371        $out .= _media_button(__('Add Audio'), 'images/media-button-music.gif', 'audio');
     372
     373    $out .= _media_button(__('Add Media'), 'images/media-button-other.gif', 'media');
     374
     375    $context = apply_filters('media_buttons_context', __('Upload/Insert %s'));
    385376
    386377    printf($context, $out);
    387378}
    388379add_action( 'media_buttons', 'media_buttons' );
     380
     381function _media_button($title, $icon, $type) {
     382    return "<a href='" . get_upload_iframe_src($type) . "' id='add_$type' class='thickbox' title='$title'><img src='" . esc_url( admin_url( $icon ) ) . "' alt='$title' /></a>";
     383}
     384
     385function get_upload_iframe_src($type) {
     386    global $post_ID, $temp_ID;
     387    $uploading_iframe_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID);
     388    $upload_iframe_src = add_query_arg('post_id', $uploading_iframe_ID, 'media-upload.php');
     389
     390    if ( 'media' != $type )
     391        $upload_iframe_src = add_query_arg('type', $type, $upload_iframe_src);
     392    $upload_iframe_src = apply_filters($type . '_upload_iframe_src', $upload_iframe_src);
     393
     394    return add_query_arg('TB_iframe', true, $upload_iframe_src);
     395}
    389396
    390397/**
Note: See TracChangeset for help on using the changeset viewer.