Ticket #18708: 18708.8.patch
File 18708.8.patch, 15.6 KB (added by , 13 years ago) |
---|
-
wp-admin/async-upload.php
38 38 wp_die( __( 'You are not allowed to edit this item.' ) ); 39 39 40 40 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 ) ); 43 43 } 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 ); 45 48 echo get_media_item($id); 46 49 } 47 50 exit; -
wp-admin/css/media.dev.css
193 193 text-align: center; 194 194 } 195 195 196 #media-upload a.wp-post-thumbnail {197 margin: 0 20px;198 }199 200 196 #media-items a.delete { 201 197 display: block; 202 198 float: right; -
wp-admin/includes/media.php
7 7 */ 8 8 9 9 /** 10 * {@internal Missing Short Description}}10 * Sets up the default media upload tabs. 11 11 * 12 12 * @since 2.5.0 13 13 * 14 * @return unknown14 * @return array 15 15 */ 16 16 function media_upload_tabs() { 17 17 $_default_tabs = array( … … 25 25 } 26 26 27 27 /** 28 * {@internal Missing Short Description}}28 * Adds the number of attachments to the "Gallery" tab header. 29 29 * 30 30 * @since 2.5.0 31 31 * 32 * @param unknown_type$tabs33 * @return unknown32 * @param array $tabs 33 * @return array 34 34 */ 35 function update_gallery_tab( $tabs) {35 function update_gallery_tab( $tabs ) { 36 36 global $wpdb; 37 37 38 if ( ! isset($_REQUEST['post_id']) ) {39 unset( $tabs['gallery']);38 if ( ! isset( $_REQUEST['post_id'] ) ) { 39 unset( $tabs['gallery'] ); 40 40 return $tabs; 41 41 } 42 42 43 $post_id = intval( $_REQUEST['post_id']);43 $post_id = intval( $_REQUEST['post_id'] ); 44 44 45 45 if ( $post_id ) 46 46 $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 ) ) ); 47 47 48 if ( empty( $attachments) ) {49 unset( $tabs['gallery']);48 if ( empty( $attachments ) ) { 49 unset( $tabs['gallery'] ); 50 50 return $tabs; 51 51 } 52 52 53 $tabs['gallery'] = sprintf( __('Gallery (%s)'), "<span id='attachments-count'>$attachments</span>");53 $tabs['gallery'] = sprintf( __( 'Gallery (%s)' ), "<span id='attachments-count'>$attachments</span>" ); 54 54 55 55 return $tabs; 56 56 } 57 add_filter( 'media_upload_tabs', 'update_gallery_tab');57 add_filter( 'media_upload_tabs', 'update_gallery_tab' ); 58 58 59 59 /** 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 */ 67 function hide_from_url_tab( $tabs ) { 68 if ( isset( $_REQUEST['context'] ) && 'featured' == $_REQUEST['context'] ) 69 unset( $tabs['type_url'] ); 70 71 return $tabs; 72 } 73 add_filter( 'media_upload_tabs', 'hide_from_url_tab' ); 74 75 /** 60 76 * {@internal Missing Short Description}} 61 77 * 62 78 * @since 2.5.0 … … 665 681 $errors = $return; 666 682 } 667 683 684 if ( isset( $_REQUEST['context'] ) && 'featured' == $_REQUEST['context'] ) 685 add_filter( 'media_upload_mime_type_links', '__return_empty_array' ); 686 668 687 return wp_iframe( 'media_upload_library_form', $errors ); 669 688 } 670 689 … … 1152 1171 'extra_rows' => array(), 1153 1172 ); 1154 1173 1155 if ( $send ) 1174 if ( isset( $_REQUEST['context'] ) && 'featured' == $_REQUEST['context'] ) 1175 $send = ''; 1176 elseif ( $send ) 1156 1177 $send = get_submit_button( __( 'Insert into Post' ), 'button', "send[$attachment_id]", false ); 1157 1178 if ( $delete && current_user_can( 'delete_post', $attachment_id ) ) { 1158 1179 if ( !EMPTY_TRASH_DAYS ) { … … 1180 1201 if ( 'image' == $type && $calling_post_id && current_theme_supports( 'post-thumbnails', get_post_type( $calling_post_id ) ) 1181 1202 && post_type_supports( get_post_type( $calling_post_id ), 'thumbnail' ) && get_post_thumbnail_id( $calling_post_id ) != $attachment_id ) { 1182 1203 $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 type='submit' $class id='wp-post-thumbnail-$attachment_id' name='wp-post-thumbnail-$attachment_id' onclick='WPSetAsThumbnail(\"$attachment_id\", \"$ajax_nonce\");return false;' value='" . esc_attr__( "Use as featured image" ) . "' />"; 1184 1206 } 1185 1207 1186 1208 if ( ( $send || $thumbnail || $delete ) && !isset( $form_fields['buttons'] ) ) … … 1420 1442 1421 1443 media_upload_header(); 1422 1444 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'] : ''; 1424 1447 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"); 1426 1449 $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type); 1427 1450 $form_class = 'media-upload-form type-form validate'; 1428 1451 … … 1433 1456 <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"> 1434 1457 <?php submit_button( '', 'hidden', 'save', false ); ?> 1435 1458 <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'] ) : ''; ?>" /> 1436 1460 <?php wp_nonce_field('media-form'); ?> 1437 1461 1438 1462 <h3 class="media-title"><?php _e('Add media files from your computer'); ?></h3> … … 1485 1509 1486 1510 media_upload_header(); 1487 1511 1488 $post_id = intval($_REQUEST['post_id']); 1512 $post_id = intval( $_REQUEST['post_id'] ); 1513 $context = ( isset( $_REQUEST['context'] ) ) ? $_REQUEST['context'] : ''; 1489 1514 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"); 1491 1516 $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type); 1492 1517 $form_class = 'media-upload-form type-form validate'; 1493 1518 … … 1497 1522 1498 1523 <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"> 1499 1524 <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'] ) : ''; ?>" /> 1500 1526 <?php wp_nonce_field('media-form'); ?> 1501 1527 1502 1528 <h3 class="media-title"><?php _e('Insert media from another website'); ?></h3> … … 1620 1646 $redir_tab = 'gallery'; 1621 1647 media_upload_header(); 1622 1648 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"); 1625 1653 $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type); 1626 1654 $form_class = 'media-upload-form validate'; 1627 1655 … … 1646 1674 <a href="#" id="showall"><?php _e('Show'); ?></a> 1647 1675 <a href="#" id="hideall" style="display:none;"><?php _e('Hide'); ?></a> 1648 1676 </span> 1677 <?php if ( ! isset( $_REQUEST['context'] ) || 'featured' != $_REQUEST['context'] ) : ?> 1649 1678 <?php _e('Sort Order:'); ?> 1650 1679 <a href="#" id="asc"><?php _e('Ascending'); ?></a> | 1651 1680 <a href="#" id="desc"><?php _e('Descending'); ?></a> | 1652 1681 <a href="#" id="clear"><?php _ex('Clear', 'verb'); ?></a> 1682 <?php endif; ?> 1653 1683 </div> 1654 1684 <form enctype="multipart/form-data" method="post" action="<?php echo esc_attr($form_action_url); ?>" class="<?php echo $form_class; ?>" id="gallery-form"> 1655 1685 <?php wp_nonce_field('media-form'); ?> … … 1657 1687 <table class="widefat" cellspacing="0"> 1658 1688 <thead><tr> 1659 1689 <th><?php _e('Media'); ?></th> 1690 <?php if ( ! isset( $_REQUEST['context'] ) || 'featured' != $_REQUEST['context'] ) : ?> 1660 1691 <th class="order-head"><?php _e('Order'); ?></th> 1692 <?php endif; ?> 1661 1693 <th class="actions-head"><?php _e('Actions'); ?></th> 1662 1694 </tr></thead> 1663 1695 </table> 1664 1696 <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 1698 if ( isset( $_REQUEST['context'] ) && 'featured' == $_REQUEST['context'] ) 1699 add_filter( 'attachment_fields_to_edit', '__return_empty_array' ); 1700 else 1701 add_filter( 'attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2 ); 1702 1703 echo get_media_items( $post_id, $errors ); 1704 ?> 1667 1705 </div> 1668 1706 1669 1707 <p class="ml-submit"> 1670 1708 <?php submit_button( __( 'Save all changes' ), 'button savebutton', 'save', false, array( 'id' => 'save-all', 'style' => 'display: none;' ) ); ?> 1671 1709 <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'] ) : ''; ?>" /> 1672 1711 <input type="hidden" name="type" value="<?php echo esc_attr( $GLOBALS['type'] ); ?>" /> 1673 1712 <input type="hidden" name="tab" value="<?php echo esc_attr( $GLOBALS['tab'] ); ?>" /> 1674 1713 </p> 1675 1714 1715 <?php if ( ! isset( $_REQUEST['context'] ) || 'featured' != $_REQUEST['context'] ) : ?> 1676 1716 <div id="gallery-settings" style="display:none;"> 1677 1717 <div class="title"><?php _e('Gallery Settings'); ?></div> 1678 1718 <table id="basic" class="describe"><tbody> … … 1749 1789 <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' ); ?>" /> 1750 1790 </p> 1751 1791 </div> 1792 <?php endif; ?> 1752 1793 </form> 1753 1794 <?php 1754 1795 } … … 1765 1806 1766 1807 media_upload_header(); 1767 1808 1768 $post_id = intval($_REQUEST['post_id']); 1809 $post_id = intval( $_REQUEST['post_id'] ); 1810 $context = ( isset( $_REQUEST['context'] ) ) ? $_REQUEST['context'] : ''; 1769 1811 1770 1812 $form_action_url = admin_url("media-upload.php?type=$type&tab=library&post_id=$post_id"); 1771 1813 $form_action_url = apply_filters('media_upload_form_url', $form_action_url, $type); … … 1909 1951 </script> 1910 1952 1911 1953 <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 1955 if ( isset( $_REQUEST['context'] ) && 'featured' == $_REQUEST['context'] ) 1956 add_filter( 'attachment_fields_to_edit', '__return_empty_array' ); 1957 else 1958 add_filter( 'attachment_fields_to_edit', 'media_post_single_attachment_fields_to_edit', 10, 2 ); 1959 1960 echo get_media_items( null, $errors ); ?> 1914 1961 </div> 1915 1962 <p class="ml-submit"> 1916 1963 <?php submit_button( __( 'Save all changes' ), 'button savebutton', 'save', false ); ?> 1917 1964 <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'] ) : ''; ?>" /> 1918 1966 </p> 1919 1967 </form> 1920 1968 <?php … … 2056 2104 * @since 3.3.0 2057 2105 */ 2058 2106 function media_upload_text_after() { 2107 if ( isset( $_REQUEST['context'] ) && 'featured' == $_REQUEST['context'] ) 2108 return; 2059 2109 ?> 2060 2110 <span class="after-file-upload"><?php _e('After a file has been uploaded, you can add titles and descriptions.'); ?></span> 2061 2111 <?php -
wp-admin/includes/post.php
1147 1147 if ( empty( $post_id ) ) 1148 1148 $post_id = $post_ID; 1149 1149 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 ) ); 1151 1153 $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>'; 1152 1154 $content = sprintf( $set_thumbnail_link, $upload_iframe_src, esc_html__( 'Set featured image' ) ); 1153 1155 -
wp-admin/js/set-post-thumbnail.dev.js
1 1 function WPSetAsThumbnail(id, nonce){ 2 var $link = jQuery('a#wp-post-thumbnail-' + id);2 var button = jQuery('input#wp-post-thumbnail-' + id), context = jQuery('#context'); 3 3 4 $link.text( setPostThumbnailL10n.saving );4 button.val( setPostThumbnailL10n.saving ); 5 5 jQuery.post(ajaxurl, { 6 6 action:"set-post-thumbnail", post_id: post_id, thumbnail_id: id, _ajax_nonce: nonce, cookie: encodeURIComponent(document.cookie) 7 7 }, function(str){ 8 8 var win = window.dialogArguments || opener || parent || top; 9 $link.text( setPostThumbnailL10n.setThumbnail );9 button.val( setPostThumbnailL10n.setThumbnail ); 10 10 if ( str == '0' ) { 11 11 alert( setPostThumbnailL10n.error ); 12 12 } 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 ); 16 16 win.WPSetThumbnailID(id); 17 17 win.WPSetThumbnailHTML(str); 18 if ( 'featured' == context.val() ) 19 win.tb_remove(); 18 20 } 19 21 } 20 22 ); -
wp-includes/js/plupload/handlers.dev.js
111 111 } 112 112 113 113 function 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, c = jQuery('#context'), item = jQuery('#media-item-' + fileObj.id); 115 115 116 116 try { 117 117 if ( typeof topWin.tb_remove != 'undefined' ) 118 118 topWin.jQuery('#TB_overlay').click(topWin.tb_remove); 119 119 } catch(e){} 120 120 121 c = ( typeof c.val() != 'undefined' ) ? c.val() : ''; 122 121 123 if ( isNaN(serverData) || !serverData ) { // Old style: Append the HTML returned by the server -- thumbnail and form inputs 122 124 item.append(serverData); 123 125 prepareMediaItemInit(fileObj); 124 126 } 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()});127 item.load('async-upload.php', {attachment_id:serverData, fetch:f, context:c}, function(){prepareMediaItemInit(fileObj);updateMediaForm()}); 126 128 } 127 129 } 128 130