Make WordPress Core

Ticket #18708: 18708.7.patch

File 18708.7.patch, 15.6 KB (added by SergeyBiryukov, 13 years ago)
  • wp-admin/async-upload.php

     
    3838                wp_die( __( 'You are not allowed to edit this item.' ) );
    3939
    4040        if ( 2 == $_REQUEST['fetch'] ) {
    41                 add_filter('attachment_fields_to_edit', 'media_single_attachment_fields_to_edit', 10, 2);
    42                 echo get_media_item($id, array( 'send' => false, 'delete' => true ));
     41                add_filter( 'attachment_fields_to_edit', 'media_single_attachment_fields_to_edit', 10, 2 );
     42                echo get_media_item( $id, array( 'send' => false, 'delete' => true ) );
    4343        } else {
    44                 add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2);
     44                if ( isset( $_REQUEST['context'] ) && 'featured' == $_REQUEST['context'] )
     45                        add_filter( 'attachment_fields_to_edit', '__return_empty_array' );
     46                else
     47                        add_filter( 'attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2 );
    4548                echo get_media_item($id);
    4649        }
    4750        exit;
  • wp-admin/css/media.dev.css

     
    193193        text-align: center;
    194194}
    195195
    196 #media-upload a.wp-post-thumbnail {
    197         margin: 0 20px;
    198 }
    199 
    200196#media-items a.delete {
    201197        display: block;
    202198        float: right;
  • wp-admin/includes/media.php

     
    77 */
    88
    99/**
    10  * {@internal Missing Short Description}}
     10 * Sets up the default media upload tabs.
    1111 *
    1212 * @since 2.5.0
    1313 *
    14  * @return unknown
     14 * @return array
    1515 */
    1616function media_upload_tabs() {
    1717        $_default_tabs = array(
     
    2525}
    2626
    2727/**
    28  * {@internal Missing Short Description}}
     28 * Adds the number of attachments to the "Gallery" tab header.
    2929 *
    3030 * @since 2.5.0
    3131 *
    32  * @param unknown_type $tabs
    33  * @return unknown
     32 * @param array $tabs
     33 * @return array
    3434 */
    35 function update_gallery_tab($tabs) {
     35function update_gallery_tab( $tabs ) {
    3636        global $wpdb;
    3737
    38         if ( !isset($_REQUEST['post_id']) ) {
    39                 unset($tabs['gallery']);
     38        if ( ! isset( $_REQUEST['post_id'] ) ) {
     39                unset( $tabs['gallery'] );
    4040                return $tabs;
    4141        }
    4242
    43         $post_id = intval($_REQUEST['post_id']);
     43        $post_id = intval( $_REQUEST['post_id'] );
    4444
    4545        if ( $post_id )
    4646                $attachments = intval( $wpdb->get_var( $wpdb->prepare( "SELECT count(*) FROM $wpdb->posts WHERE post_type = 'attachment' AND post_status != 'trash' AND post_parent = %d", $post_id ) ) );
    4747
    48         if ( empty($attachments) ) {
    49                 unset($tabs['gallery']);
     48        if ( empty( $attachments ) ) {
     49                unset( $tabs['gallery'] );
    5050                return $tabs;
    5151        }
    5252
    53         $tabs['gallery'] = sprintf(__('Gallery (%s)'), "<span id='attachments-count'>$attachments</span>");
     53        $tabs['gallery'] = sprintf( __( 'Gallery (%s)' ), "<span id='attachments-count'>$attachments</span>" );
    5454
    5555        return $tabs;
    5656}
    57 add_filter('media_upload_tabs', 'update_gallery_tab');
     57add_filter( 'media_upload_tabs', 'update_gallery_tab' );
    5858
    5959/**
     60 * Hides "From URL" tab when setting a featured image.
     61 *
     62 * @since 3.5.0
     63 *
     64 * @param array $tabs
     65 * @return array
     66 */
     67function hide_from_url_tab( $tabs ) {
     68        if ( isset( $_REQUEST['context'] ) && 'featured' == $_REQUEST['context'] )
     69                unset( $tabs['type_url'] );
     70
     71        return $tabs;
     72}
     73add_filter( 'media_upload_tabs', 'hide_from_url_tab' );
     74
     75/**
    6076 * {@internal Missing Short Description}}
    6177 *
    6278 * @since 2.5.0
     
    665681                        $errors = $return;
    666682        }
    667683
     684        if ( isset( $_REQUEST['context'] ) && 'featured' == $_REQUEST['context'] )
     685                add_filter( 'media_upload_mime_type_links', '__return_empty_array' );
     686
    668687        return wp_iframe( 'media_upload_library_form', $errors );
    669688}
    670689
     
    11521171                'extra_rows' => array(),
    11531172        );
    11541173
    1155         if ( $send )
     1174        if ( isset( $_REQUEST['context'] ) && 'featured' == $_REQUEST['context'] )
     1175                $send = '';
     1176        elseif ( $send )
    11561177                $send = get_submit_button( __( 'Insert into Post' ), 'button', "send[$attachment_id]", false );
    11571178        if ( $delete && current_user_can( 'delete_post', $attachment_id ) ) {
    11581179                if ( !EMPTY_TRASH_DAYS ) {
     
    11801201        if ( 'image' == $type && $calling_post_id && current_theme_supports( 'post-thumbnails', get_post_type( $calling_post_id ) )
    11811202                && post_type_supports( get_post_type( $calling_post_id ), 'thumbnail' ) && get_post_thumbnail_id( $calling_post_id ) != $attachment_id ) {
    11821203                $ajax_nonce = wp_create_nonce( "set_post_thumbnail-$calling_post_id" );
    1183                 $thumbnail = "<a class='wp-post-thumbnail' id='wp-post-thumbnail-" . $attachment_id . "' href='#' onclick='WPSetAsThumbnail(\"$attachment_id\", \"$ajax_nonce\");return false;'>" . esc_html__( "Use as featured image" ) . "</a>";
     1204                $class = ( isset( $_REQUEST['context'] ) && 'featured' == $_REQUEST['context'] ) ? "class='button-primary'" : '';
     1205                $thumbnail = "<input $class id='wp-post-thumbnail-$attachment_id' type='submit' onclick='WPSetAsThumbnail(\"$attachment_id\", \"$ajax_nonce\");return false;' value='" . esc_attr__( "Use as featured image" ) . "' name='wp-post-thumbnail-$attachment_id' />";
    11841206        }
    11851207
    11861208        if ( ( $send || $thumbnail || $delete ) && !isset( $form_fields['buttons'] ) )
     
    14201442
    14211443        media_upload_header();
    14221444
    1423         $post_id = isset( $_REQUEST['post_id'] )? intval( $_REQUEST['post_id'] ) : 0;
     1445        $post_id = ( isset( $_REQUEST['post_id'] ) ) ? intval( $_REQUEST['post_id'] ) : 0;
     1446        $context = ( isset( $_REQUEST['context'] ) ) ? $_REQUEST['context'] : '';
    14241447
    1425         $form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id");
     1448        $form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id&context=$context");
    14261449        $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
    14271450        $form_class = 'media-upload-form type-form validate';
    14281451
     
    14331456<form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="<?php echo $form_class; ?>" id="<?php echo $type; ?>-form">
    14341457<?php submit_button( '', 'hidden', 'save', false ); ?>
    14351458<input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
     1459<input type="hidden" name="context" id="context" value="<?php echo isset( $_REQUEST['context'] ) ? esc_attr( $_REQUEST['context'] ) : ''; ?>" />
    14361460<?php wp_nonce_field('media-form'); ?>
    14371461
    14381462<h3 class="media-title"><?php _e('Add media files from your computer'); ?></h3>
     
    14851509
    14861510        media_upload_header();
    14871511
    1488         $post_id = intval($_REQUEST['post_id']);
     1512        $post_id = intval( $_REQUEST['post_id'] );
     1513        $context = ( isset( $_REQUEST['context'] ) ) ? $_REQUEST['context'] : '';
    14891514
    1490         $form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id");
     1515        $form_action_url = admin_url("media-upload.php?type=$type&tab=type&post_id=$post_id&context=$context");
    14911516        $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
    14921517        $form_class = 'media-upload-form type-form validate';
    14931518
     
    14971522
    14981523<form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="<?php echo $form_class; ?>" id="<?php echo $type; ?>-form">
    14991524<input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
     1525<input type="hidden" name="context" id="context" value="<?php echo isset( $_REQUEST['context'] ) ? esc_attr( $_REQUEST['context'] ) : ''; ?>" />
    15001526<?php wp_nonce_field('media-form'); ?>
    15011527
    15021528<h3 class="media-title"><?php _e('Insert media from another website'); ?></h3>
     
    16201646        $redir_tab = 'gallery';
    16211647        media_upload_header();
    16221648
    1623         $post_id = intval($_REQUEST['post_id']);
    1624         $form_action_url = admin_url("media-upload.php?type=$type&tab=gallery&post_id=$post_id");
     1649        $post_id = intval( $_REQUEST['post_id'] );
     1650        $context = ( isset( $_REQUEST['context'] ) ) ? $_REQUEST['context'] : '';
     1651
     1652        $form_action_url = admin_url("media-upload.php?type=$type&tab=gallery&post_id=$post_id&context=$context");
    16251653        $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
    16261654        $form_class = 'media-upload-form validate';
    16271655
     
    16461674<a href="#" id="showall"><?php _e('Show'); ?></a>
    16471675<a href="#" id="hideall" style="display:none;"><?php _e('Hide'); ?></a>
    16481676</span>
     1677<?php if ( ! isset( $_REQUEST['context'] ) || 'featured' != $_REQUEST['context'] ) : ?>
    16491678<?php _e('Sort Order:'); ?>
    16501679<a href="#" id="asc"><?php _e('Ascending'); ?></a> |
    16511680<a href="#" id="desc"><?php _e('Descending'); ?></a> |
    16521681<a href="#" id="clear"><?php _ex('Clear', 'verb'); ?></a>
     1682<?php endif; ?>
    16531683</div>
    16541684<form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="<?php echo $form_class; ?>" id="gallery-form">
    16551685<?php wp_nonce_field('media-form'); ?>
     
    16571687<table class="widefat" cellspacing="0">
    16581688<thead><tr>
    16591689<th><?php _e('Media'); ?></th>
     1690<?php if ( ! isset( $_REQUEST['context'] ) || 'featured' != $_REQUEST['context'] ) : ?>
    16601691<th class="order-head"><?php _e('Order'); ?></th>
     1692<?php endif; ?>
    16611693<th class="actions-head"><?php _e('Actions'); ?></th>
    16621694</tr></thead>
    16631695</table>
    16641696<div id="media-items">
    1665 <?php add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); ?>
    1666 <?php echo get_media_items($post_id, $errors); ?>
     1697<?php
     1698if ( isset( $_REQUEST['context'] ) && 'featured' == $_REQUEST['context'] )
     1699        add_filter( 'attachment_fields_to_edit', '__return_empty_array' );
     1700else
     1701        add_filter( 'attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2 );
     1702
     1703echo get_media_items( $post_id, $errors );
     1704?>
    16671705</div>
    16681706
    16691707<p class="ml-submit">
    16701708<?php submit_button( __( 'Save all changes' ), 'button savebutton', 'save', false, array( 'id' => 'save-all', 'style' => 'display: none;' ) ); ?>
    16711709<input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
     1710<input type="hidden" name="context" id="context" value="<?php echo isset( $_REQUEST['context'] ) ? esc_attr( $_REQUEST['context'] ) : ''; ?>" />
    16721711<input type="hidden" name="type" value="<?php echo esc_attr( $GLOBALS['type'] ); ?>" />
    16731712<input type="hidden" name="tab" value="<?php echo esc_attr( $GLOBALS['tab'] ); ?>" />
    16741713</p>
    16751714
     1715<?php if ( ! isset( $_REQUEST['context'] ) || 'featured' != $_REQUEST['context'] ) : ?>
    16761716<div id="gallery-settings" style="display:none;">
    16771717<div class="title"><?php _e('Gallery Settings'); ?></div>
    16781718<table id="basic" class="describe"><tbody>
     
    17491789<input type="button" class="button" style="display:none;" onMouseDown="wpgallery.update();" name="update-gallery" id="update-gallery" value="<?php esc_attr_e( 'Update gallery settings' ); ?>" />
    17501790</p>
    17511791</div>
     1792<?php endif; ?>
    17521793</form>
    17531794<?php
    17541795}
     
    17651806
    17661807        media_upload_header();
    17671808
    1768         $post_id = intval($_REQUEST['post_id']);
     1809        $post_id = intval( $_REQUEST['post_id'] );
     1810        $context = ( isset( $_REQUEST['context'] ) ) ? $_REQUEST['context'] : '';
    17691811
    17701812        $form_action_url = admin_url("media-upload.php?type=$type&tab=library&post_id=$post_id");
    17711813        $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type);
     
    19091951</script>
    19101952
    19111953<div id="media-items">
    1912 <?php add_filter('attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2); ?>
    1913 <?php echo get_media_items(null, $errors); ?>
     1954<?php
     1955if ( isset( $_REQUEST['context'] ) && 'featured' == $_REQUEST['context'] )
     1956        add_filter( 'attachment_fields_to_edit', '__return_empty_array' );
     1957else
     1958        add_filter( 'attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2 );
     1959
     1960echo get_media_items( null, $errors ); ?>
    19141961</div>
    19151962<p class="ml-submit">
    19161963<?php submit_button( __( 'Save all changes' ), 'button savebutton', 'save', false ); ?>
    19171964<input type="hidden" name="post_id" id="post_id" value="<?php echo (int) $post_id; ?>" />
     1965<input type="hidden" name="context" id="context" value="<?php echo isset( $_REQUEST['context'] ) ? esc_attr( $_REQUEST['context'] ) : ''; ?>" />
    19181966</p>
    19191967</form>
    19201968<?php
     
    20562104 * @since 3.3.0
    20572105 */
    20582106function media_upload_text_after() {
     2107        if ( isset( $_REQUEST['context'] ) && 'featured' == $_REQUEST['context'] )
     2108                return;
    20592109        ?>
    20602110        <span class="after-file-upload"><?php _e('After a file has been uploaded, you can add titles and descriptions.'); ?></span>
    20612111        <?php
  • wp-admin/includes/post.php

     
    11471147        if ( empty( $post_id ) )
    11481148                $post_id = $post_ID;
    11491149
    1150         $upload_iframe_src = esc_url( get_upload_iframe_src('image', $post_id) );
     1150        $upload_iframe_src = get_upload_iframe_src( 'image', $post_id );
     1151        $upload_iframe_src = remove_query_arg( 'TB_iframe', $upload_iframe_src );
     1152        $upload_iframe_src = esc_url( add_query_arg( array( 'context' => 'featured', 'TB_iframe' => 1 ), $upload_iframe_src ) );
    11511153        $set_thumbnail_link = '<p class="hide-if-no-js"><a title="' . esc_attr__( 'Set featured image' ) . '" href="%s" id="set-post-thumbnail" class="thickbox">%s</a></p>';
    11521154        $content = sprintf( $set_thumbnail_link, $upload_iframe_src, esc_html__( 'Set featured image' ) );
    11531155
  • wp-admin/js/set-post-thumbnail.dev.js

     
    11function WPSetAsThumbnail(id, nonce){
    2         var $link = jQuery('a#wp-post-thumbnail-' + id);
     2        var $button = jQuery('input#wp-post-thumbnail-' + id);
    33
    4         $link.text( setPostThumbnailL10n.saving );
     4        $button.val( setPostThumbnailL10n.saving );
    55        jQuery.post(ajaxurl, {
    66                action:"set-post-thumbnail", post_id: post_id, thumbnail_id: id, _ajax_nonce: nonce, cookie: encodeURIComponent(document.cookie)
    77        }, function(str){
    88                var win = window.dialogArguments || opener || parent || top;
    9                 $link.text( setPostThumbnailL10n.setThumbnail );
     9                $button.val( setPostThumbnailL10n.setThumbnail );
    1010                if ( str == '0' ) {
    1111                        alert( setPostThumbnailL10n.error );
    1212                } else {
    13                         jQuery('a.wp-post-thumbnail').show();
    14                         $link.text( setPostThumbnailL10n.done );
    15                         $link.fadeOut( 2000 );
     13                        jQuery('input.wp-post-thumbnail').show();
     14                        $button.val( setPostThumbnailL10n.done );
     15                        $button.fadeOut( 2000 );
    1616                        win.WPSetThumbnailID(id);
    1717                        win.WPSetThumbnailHTML(str);
     18                        if ( -1 != window.location.href.indexOf('featured') )
     19                                win.tb_remove();
    1820                }
    1921        }
    2022        );
  • wp-includes/js/plupload/handlers.dev.js

     
    111111}
    112112
    113113function prepareMediaItem(fileObj, serverData) {
    114         var f = ( typeof shortform == 'undefined' ) ? 1 : 2, item = jQuery('#media-item-' + fileObj.id);
     114        var f = ( typeof shortform == 'undefined' ) ? 1 : 2,
     115                c = jQuery('#context'),
     116                item = jQuery('#media-item-' + fileObj.id);
    115117
    116118        try {
    117119                if ( typeof topWin.tb_remove != 'undefined' )
    118120                        topWin.jQuery('#TB_overlay').click(topWin.tb_remove);
    119121        } catch(e){}
    120122
     123        c = ( typeof c.val() != 'undefined' ) ? c.val() : '';
     124
    121125        if ( isNaN(serverData) || !serverData ) { // Old style: Append the HTML returned by the server -- thumbnail and form inputs
    122126                item.append(serverData);
    123127                prepareMediaItemInit(fileObj);
    124128        } else { // New style: server data is just the attachment ID, fetch the thumbnail and form html from the server
    125                 item.load('async-upload.php', {attachment_id:serverData, fetch:f}, function(){prepareMediaItemInit(fileObj);updateMediaForm()});
     129                item.load('async-upload.php', {attachment_id:serverData, fetch:f, context:c}, function(){prepareMediaItemInit(fileObj);updateMediaForm()});
    126130        }
    127131}
    128132