WordPress.org

Make WordPress Core

Changeset 14015


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

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

Location:
trunk
Files:
4 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/**
  • trunk/wp-admin/includes/post.php

    r13940 r14015  
    11441144function _wp_post_thumbnail_html( $thumbnail_id = NULL ) {
    11451145    global $content_width, $_wp_additional_image_sizes;
    1146     $content = '<p class="hide-if-no-js"><a href="#" id="set-post-thumbnail" onclick="jQuery(\'#add_image\').click();return false;">' . esc_html__( 'Set featured image' ) . '</a></p>';
     1146
     1147    $set_thumbnail_link = '<p class="hide-if-no-js"><a href="' . get_upload_iframe_src('image') . '" id="set-post-thumbnail" class="thickbox">%s</a></p>';
     1148    $content = sprintf($set_thumbnail_link, esc_html__( 'Set featured image' ));
    11471149
    11481150    if ( $thumbnail_id && get_post( $thumbnail_id ) ) {
     
    11541156            $thumbnail_html = wp_get_attachment_image( $thumbnail_id, 'post-thumbnail' );
    11551157        if ( !empty( $thumbnail_html ) ) {
    1156             $content = '<a href="#" id="set-post-thumbnail" onclick="jQuery(\'#add_image\').click();return false;">' . $thumbnail_html . '</a>';
     1158            $content = sprintf($set_thumbnail_link, $thumbnail_html);
    11571159            $content .= '<p class="hide-if-no-js"><a href="#" id="remove-post-thumbnail" onclick="WPRemoveThumbnail();return false;">' . esc_html__( 'Remove featured image' ) . '</a></p>';
    11581160        }
  • trunk/wp-includes/js/thickbox/thickbox.js

    r13864 r14015  
    2424//add thickbox to href & area elements that have a class of .thickbox
    2525function tb_init(domChunk){
    26     jQuery(domChunk).click(function(){
     26    jQuery(domChunk).live('click', function(){
    2727    var t = this.title || this.name || null;
    2828    var a = this.href || this.alt;
  • trunk/wp-includes/script-loader.php

    r13984 r14015  
    168168    $scripts->add_data( 'jquery-autocomplete', 'group', 1 );
    169169
    170     $scripts->add( 'thickbox', "/wp-includes/js/thickbox/thickbox.js", array('jquery'), '3.1-20100108');
     170    $scripts->add( 'thickbox', "/wp-includes/js/thickbox/thickbox.js", array('jquery'), '3.1-20104104');
    171171    $scripts->add_data( 'thickbox', 'group', 1 );
    172172    $scripts->localize( 'thickbox', 'thickboxL10n', array(
Note: See TracChangeset for help on using the changeset viewer.