Ticket #21776: 21776.6.diff
File 21776.6.diff, 18.6 KB (added by , 12 years ago) |
---|
-
wp-admin/includes/ajax-actions.php
1674 1674 } 1675 1675 1676 1676 function wp_ajax_set_post_thumbnail() { 1677 $json = ! empty( $_REQUEST['json'] ); 1678 1677 1679 $post_ID = intval( $_POST['post_id'] ); 1678 if ( !current_user_can( 'edit_post', $post_ID ) ) 1679 wp_die( -1 ); 1680 if ( !current_user_can( 'edit_post', $post_ID ) ) { 1681 $json ? wp_send_json_error() : wp_die( -1 ); 1682 } 1680 1683 $thumbnail_id = intval( $_POST['thumbnail_id'] ); 1681 1684 1682 1685 check_ajax_referer( "set_post_thumbnail-$post_ID" ); 1683 1686 1684 1687 if ( $thumbnail_id == '-1' ) { 1685 if ( delete_post_thumbnail( $post_ID ) ) 1686 wp_die( _wp_post_thumbnail_html( null, $post_ID ) ); 1687 else 1688 wp_die( 0 ); 1688 if ( delete_post_thumbnail( $post_ID ) ) { 1689 $return = _wp_post_thumbnail_html( null, $post_ID ); 1690 $json ? wp_send_json_success( $return ) : wp_die( $json ); 1691 } else { 1692 $json ? wp_send_json_error() : wp_die( 0 ); 1693 } 1689 1694 } 1690 1695 1691 if ( set_post_thumbnail( $post_ID, $thumbnail_id ) ) 1692 wp_die( _wp_post_thumbnail_html( $thumbnail_id, $post_ID ) ); 1693 wp_die( 0 ); 1696 if ( set_post_thumbnail( $post_ID, $thumbnail_id ) ) { 1697 $return = _wp_post_thumbnail_html( $thumbnail_id, $post_ID ); 1698 $json ? wp_send_json_success( $return ) : wp_die( $json ); 1699 } 1700 1701 $json ? wp_send_json_error() : wp_die( 0 ); 1694 1702 } 1695 1703 1696 1704 function wp_ajax_date_format() { -
wp-admin/includes/meta-boxes.php
1001 1001 * @since 2.9.0 1002 1002 */ 1003 1003 function post_thumbnail_meta_box( $post ) { 1004 global $_wp_additional_image_sizes; 1005 1006 ?><script type="text/javascript"> 1007 jQuery( function($) { 1008 var $element = $('#select-featured-image'), 1009 $thumbnailId = $element.find('input[name="thumbnail_id"]'), 1010 title = '<?php _e( "Choose a Featured Image" ); ?>', 1011 update = '<?php _e( "Update Featured Image" ); ?>', 1012 Attachment = wp.media.model.Attachment, 1013 frame, setFeaturedImage; 1014 1015 setFeaturedImage = function( thumbnailId ) { 1016 var selection; 1017 1018 $element.find('img').remove(); 1019 $element.toggleClass( 'has-featured-image', -1 != thumbnailId ); 1020 $thumbnailId.val( thumbnailId ); 1021 1022 if ( frame ) { 1023 selection = frame.state('library').get('selection'); 1024 1025 if ( -1 === thumbnailId ) 1026 selection.clear(); 1027 else 1028 selection.add( Attachment.get( thumbnailId ) ); 1029 } 1030 }; 1031 1032 $element.on( 'click', '.choose, img', function( event ) { 1033 var options, thumbnailId, attachment; 1034 1035 event.preventDefault(); 1036 1037 if ( frame ) { 1038 frame.open(); 1039 return; 1040 } 1041 1042 options = { 1043 title: title, 1044 library: { 1045 type: 'image' 1046 } 1047 }; 1048 1049 thumbnailId = $thumbnailId.val(); 1050 if ( '' !== thumbnailId && -1 !== thumbnailId ) { 1051 attachment = Attachment.get( thumbnailId ); 1052 attachment.fetch(); 1053 options.selection = [ attachment ]; 1054 } 1055 1056 frame = wp.media( options ); 1057 1058 frame.state('library').set( 'filterable', 'uploaded' ); 1059 1060 frame.toolbar.on( 'activate:select', function() { 1061 frame.toolbar.view().set({ 1062 select: { 1063 style: 'primary', 1064 text: update, 1065 1066 click: function() { 1067 var selection = frame.state().get('selection'), 1068 model = selection.first(), 1069 sizes = model.get('sizes'), 1070 size; 1071 1072 setFeaturedImage( model.id ); 1073 1074 // @todo: might need a size hierarchy equivalent. 1075 if ( sizes ) 1076 size = sizes['post-thumbnail'] || sizes.medium; 1077 1078 // @todo: Need a better way of accessing full size 1079 // data besides just calling toJSON(). 1080 size = size || model.toJSON(); 1081 1082 frame.close(); 1083 1084 $( '<img />', { 1085 src: size.url, 1086 width: size.width 1087 }).prependTo( $element ); 1088 } 1089 } 1090 }); 1091 }); 1092 1093 frame.toolbar.mode('select'); 1094 }); 1095 1096 $element.on( 'click', '.remove', function( event ) { 1097 event.preventDefault(); 1098 setFeaturedImage( -1 ); 1099 }); 1100 }); 1101 </script> 1102 1103 <?php 1104 $thumbnail_id = get_post_meta( $post->ID, '_thumbnail_id', true ); 1105 $thumbnail_size = isset( $_wp_additional_image_sizes['post-thumbnail'] ) ? 'post-thumbnail' : 'medium'; 1106 $thumbnail_html = wp_get_attachment_image( $thumbnail_id, $thumbnail_size ); 1107 1108 $classes = empty( $thumbnail_id ) ? '' : 'has-featured-image'; 1109 1110 ?><div id="select-featured-image" 1111 class="<?php echo esc_attr( $classes ); ?>" 1112 data-post-id="<?php echo esc_attr( $post->ID ); ?>"> 1113 <?php echo $thumbnail_html; ?> 1114 <input type="hidden" name="thumbnail_id" value="<?php echo esc_attr( $thumbnail_id ); ?>" /> 1115 <a href="#" class="choose button-secondary"><?php _e( 'Choose a Featured Image' ); ?></a> 1116 <a href="#" class="remove"><?php _e( 'Remove Featured Image' ); ?></a> 1117 </div> 1118 <?php 1004 $thumbnail_id = get_post_meta( $post->ID, '_thumbnail_id', true ); 1005 echo _wp_post_thumbnail_html( $thumbnail_id, $post->ID ); 1119 1006 } 1007 No newline at end of file -
wp-admin/includes/post.php
199 199 set_post_format( $post_ID, false ); 200 200 } 201 201 202 // Featured Images203 if ( isset( $post_data['thumbnail_id'] ) ) {204 if ( '-1' == $post_data['thumbnail_id'] )205 delete_post_thumbnail( $post_ID );206 else207 set_post_thumbnail( $post_ID, $post_data['thumbnail_id'] );208 }209 210 202 // Meta Stuff 211 203 if ( isset($post_data['meta']) && $post_data['meta'] ) { 212 204 foreach ( $post_data['meta'] as $key => $value ) { -
wp-admin/js/custom-background.js
57 57 }); 58 58 }); 59 59 60 frame.setState('library') ;60 frame.setState('library').open(); 61 61 }); 62 62 }); 63 63 })(jQuery); 64 No newline at end of file -
wp-admin/js/custom-header.js
40 40 }); 41 41 }); 42 42 43 frame.setState('library') ;43 frame.setState('library').open(); 44 44 }); 45 45 }); 46 46 }(jQuery)); -
wp-includes/css/media-views.css
403 403 */ 404 404 .media-frame { 405 405 overflow: hidden; 406 position: absolute; 407 top: 0; 408 left: 0; 409 right: 0; 410 bottom: 0; 406 411 } 407 412 408 413 .media-frame .region-content { -
wp-includes/js/media-editor.js
375 375 376 376 workflow = workflows[ id ] = wp.media( _.defaults( options || {}, { 377 377 frame: 'post', 378 state: 'upload', 378 379 title: wp.media.view.l10n.addMedia, 379 380 multiple: true 380 381 } ) ); … … 427 428 } 428 429 }, this ); 429 430 431 workflow.state('featured-image').on( 'select', function() { 432 var settings = wp.media.view.settings, 433 featuredImage = settings.featuredImage, 434 selection = this.get('selection').single(); 435 436 if ( ! featuredImage ) 437 return; 438 439 featuredImage.id = selection ? selection.id : -1; 440 wp.media.post( 'set-post-thumbnail', { 441 json: true, 442 post_id: settings.postId, 443 thumbnail_id: featuredImage.id, 444 _wpnonce: featuredImage.nonce 445 }).done( function( html ) { 446 $( '.inside', '#postimagediv' ).html( html ); 447 $('#set-post-thumbnail').removeClass('thickbox'); 448 }); 449 }); 450 451 workflow.setState( workflow.options.state ); 430 452 return workflow; 431 453 }, 432 454 455 id: function( id ) { 456 if ( id ) 457 return id; 458 459 // If an empty `id` is provided, default to `wpActiveEditor`. 460 id = wpActiveEditor; 461 462 // If that doesn't work, fall back to `tinymce.activeEditor.id`. 463 if ( ! id && typeof tinymce !== 'undefined' && tinymce.activeEditor ) 464 id = tinymce.activeEditor.id; 465 466 // Last but not least, fall back to the empty string. 467 id = id || ''; 468 return id; 469 }, 470 433 471 get: function( id ) { 472 id = this.id( id ); 434 473 return workflows[ id ]; 435 474 }, 436 475 437 476 remove: function( id ) { 477 id = this.id( id ); 438 478 delete workflows[ id ]; 439 479 }, 440 480 … … 497 537 } 498 538 }, 499 539 540 open: function( id ) { 541 var workflow, editor; 542 543 id = this.id( id ); 544 545 // Save a bookmark of the caret position in IE. 546 if ( typeof tinymce !== 'undefined' ) { 547 editor = tinymce.get( id ); 548 549 if ( tinymce.isIE && editor && ! editor.isHidden() ) { 550 editor.focus(); 551 editor.windowManager.insertimagebookmark = editor.selection.getBookmark(); 552 } 553 } 554 555 workflow = this.get( id ); 556 557 // Initialize the editor's workflow if we haven't yet. 558 if ( ! workflow ) 559 workflow = this.add( id ); 560 561 return workflow.open(); 562 }, 563 500 564 init: function() { 501 565 $(document.body).on( 'click', '.insert-media', function( event ) { 502 566 var $this = $(this), … … 513 577 514 578 wp.media.editor.open( editor ); 515 579 }); 516 },517 580 518 open: function( id ) { 519 var workflow, editor; 581 // Initialize post thumbnails. 582 $('#set-post-thumbnail').removeClass('thickbox'); 583 $('#postimagediv').on( 'click', '#set-post-thumbnail', function( event ) { 584 event.preventDefault(); 520 585 521 // If an empty `id` is provided, default to `wpActiveEditor`. 522 id = id || wpActiveEditor; 586 // Always get the 'content' frame, since this is tailored to post.php. 587 var frame = wp.media.editor.get('content') || wp.media.editor.add('content'), 588 id = wp.media.view.settings.featuredImage.id, 589 model = wp.media.model, 590 selection = [], 591 attachment; 523 592 524 if ( typeof tinymce !== 'undefined' && tinymce.activeEditor ) { 525 // If that doesn't work, fall back to `tinymce.activeEditor`. 526 if ( ! id ) { 527 editor = tinymce.activeEditor; 528 id = id || editor.id; 529 } else { 530 editor = tinymce.get( id ); 593 if ( '' !== id && -1 !== id ) { 594 attachment = model.Attachment.get( id ); 595 attachment.fetch(); 596 selection.push( attachment ); 531 597 } 532 598 533 // Save a bookmark of the caret position, needed for IE 534 if ( tinymce.isIE && editor && ! editor.isHidden() ) { 535 editor.focus(); 536 editor.windowManager.insertimagebookmark = editor.selection.getBookmark(); 537 } 538 } 599 selection = new model.Selection( selection ); 539 600 540 // Last but not least, fall back to the empty string. 541 id = id || ''; 542 543 workflow = wp.media.editor.get( id ); 544 545 // If the workflow exists, open it. 546 // Initialize the editor's workflow if we haven't yet. 547 if ( workflow ) 548 workflow.open(); 549 else 550 workflow = wp.media.editor.add( id ); 551 552 return workflow; 601 frame.state('featured-image').set( 'selection', selection ); 602 frame.setState('featured-image').open(); 603 }); 553 604 } 554 605 }; 555 606 607 _.bindAll( wp.media.editor, 'open' ); 556 608 $( wp.media.editor.init ); 557 609 }(jQuery)); -
wp-includes/js/media-models.js
30 30 frame = new MediaFrame.Post( attributes ); 31 31 32 32 delete attributes.frame; 33 // Set the default state. 34 frame.setState( frame.options.state ); 35 // Render, attach, and open the frame. 36 return frame.render().attach().open(); 33 34 return frame; 37 35 }; 38 36 39 37 _.extend( media, { model: {}, view: {}, controller: {} }); … … 235 233 236 234 // Overload the `update` request so properties can be saved. 237 235 } else if ( 'update' === method ) { 236 if ( ! this.get('nonces') ) 237 return $.Deferred().resolveWith( this ).promise(); 238 238 239 options = options || {}; 239 240 options.context = this; 240 241 -
wp-includes/js/media-views.js
169 169 // created the `states` collection, or are trying to select a state 170 170 // that does not exist. 171 171 if ( ( previous && id === previous.id ) || ! this.states || ! this.states.get( id ) ) 172 return ;172 return this; 173 173 174 174 if ( previous ) { 175 175 previous.trigger('deactivate'); … … 178 178 179 179 this._state = id; 180 180 this.state().trigger('activate'); 181 182 return this; 181 183 }, 182 184 183 185 // Returns the previous active state. … … 1075 1077 if ( this.options.modal ) { 1076 1078 this.modal = new media.view.Modal({ 1077 1079 controller: this, 1078 $content: this.$el,1079 1080 title: this.options.title 1080 1081 }); 1082 1083 this.modal.content( this ); 1081 1084 } 1082 1085 1083 1086 // Force the uploader off if the upload limit has been exceeded or … … 1100 1103 this.on( 'attach', _.bind( this.views.ready, this.views ), this ); 1101 1104 }, 1102 1105 1103 render: function() {1104 if ( this.modal )1105 this.modal.render();1106 1107 media.view.Frame.prototype.render.apply( this, arguments );1108 return this;1109 },1110 1111 1106 createIframeStates: function( options ) { 1112 1107 var settings = media.view.settings, 1113 1108 tabs = settings.tabs, … … 1200 1195 media.view.MediaFrame.prototype.initialize.apply( this, arguments ); 1201 1196 1202 1197 _.defaults( this.options, { 1203 state: 'upload',1204 1198 selection: [], 1205 1199 library: {}, 1206 1200 multiple: false … … 1347 1341 media.view.MediaFrame.Post = media.view.MediaFrame.Select.extend({ 1348 1342 initialize: function() { 1349 1343 _.defaults( this.options, { 1350 state: 'upload',1351 1344 multiple: true, 1352 1345 editing: false 1353 1346 }); … … 1407 1400 libraryState: 'gallery-edit' 1408 1401 }) 1409 1402 ]); 1403 1404 1405 if ( media.view.settings.featuredImage ) { 1406 this.states.add( new media.controller.Library({ 1407 id: 'featured-image', 1408 library: media.query({ type: 'image' }), 1409 filterable: 'uploaded', 1410 multiple: false, 1411 menu: 'main', 1412 toolbar: 'featured-image' 1413 }) ); 1414 } 1410 1415 }, 1411 1416 1412 1417 bindHandlers: function() { … … 1425 1430 toolbar: { 1426 1431 'main-attachments': 'mainAttachmentsToolbar', 1427 1432 'main-embed': 'mainEmbedToolbar', 1433 'featured-image': 'featuredImageToolbar', 1428 1434 'gallery-edit': 'galleryEditToolbar', 1429 1435 'gallery-add': 'galleryAddToolbar' 1430 1436 } … … 1442 1448 media.view.MediaFrame.Select.prototype.mainMenu.call( this, { silent: true }); 1443 1449 1444 1450 this.menu.view().set({ 1445 separateLibrary: new media.View({1451 'library-separator': new media.View({ 1446 1452 className: 'separator', 1447 1453 priority: 60 1448 1454 }), 1449 embed: {1455 'embed': { 1450 1456 text: l10n.fromUrlTitle, 1451 1457 priority: 80 1452 1458 } 1453 1459 }); 1460 1461 if ( media.view.settings.featuredImage ) { 1462 this.menu.view().set( 'featured-image', { 1463 text: l10n.featuredImageTitle, 1464 priority: 100 1465 }); 1466 } 1454 1467 }, 1455 1468 1456 1469 galleryMenu: function() { … … 1557 1570 }) ); 1558 1571 }, 1559 1572 1573 featuredImageToolbar: function() { 1574 this.toolbar.view( new media.view.Toolbar.Select({ 1575 controller: this, 1576 text: l10n.setFeaturedImage 1577 }) ); 1578 }, 1579 1560 1580 mainEmbedToolbar: function() { 1561 1581 this.toolbar.view( new media.view.Toolbar.Embed({ 1562 1582 controller: this … … 1641 1661 }); 1642 1662 }, 1643 1663 1644 render: function() { 1645 // Ensure content div exists. 1646 this.options.$content = this.options.$content || $('<div />'); 1647 1648 // Detach the content element from the DOM to prevent 1649 // `this.$el.html()` from garbage collecting its events. 1650 this.options.$content.detach(); 1651 1652 this.$el.html( this.template({ 1664 prepare: function() { 1665 return { 1653 1666 title: this.options.title 1654 }) ); 1655 1656 this.options.$content.addClass('media-modal-content'); 1657 this.$('.media-modal').append( this.options.$content ); 1658 return this; 1667 }; 1659 1668 }, 1660 1669 1661 1670 attach: function() { 1671 if ( this.views.attached ) 1672 return; 1673 1674 if ( ! this.views.rendered ) 1675 this.render(); 1676 1662 1677 this.$el.appendTo( this.options.container ); 1678 1679 // Manually mark the view as attached and trigger ready. 1680 this.views.attached = true; 1681 this.views.ready(); 1682 1663 1683 return this.propagate('attach'); 1664 1684 }, 1665 1685 1666 1686 detach: function() { 1687 if ( this.$el.is(':visible') ) 1688 this.close(); 1689 1667 1690 this.$el.detach(); 1691 this.views.attached = false; 1668 1692 return this.propagate('detach'); 1669 1693 }, 1670 1694 1671 1695 open: function() { 1696 if ( this.$el.is(':visible') ) 1697 return; 1698 1699 if ( ! this.views.attached ) 1700 this.attach(); 1701 1672 1702 this.$el.show().focus(); 1673 1703 return this.propagate('open'); 1674 1704 }, 1675 1705 1676 1706 close: function() { 1707 if ( ! this.views.attached || ! this.$el.is(':visible') ) 1708 return; 1709 1677 1710 this.$el.hide(); 1678 1711 return this.propagate('close'); 1679 1712 }, … … 1683 1716 this.close(); 1684 1717 }, 1685 1718 1686 content: function( $content ) { 1687 // Detach any existing content to prevent events from being lost. 1688 if ( this.options.$content ) 1689 this.options.$content.detach(); 1690 1691 // Set and render the content. 1692 this.options.$content = ( $content instanceof Backbone.View ) ? $content.$el : $content; 1693 return this.render(); 1719 content: function( content ) { 1720 this.views.set( '.media-modal-content', content ); 1721 return this; 1694 1722 }, 1695 1723 1696 1724 // Triggers a modal event and if the `propagate` option is set, -
wp-includes/media.php
1433 1433 if ( isset( $args['post'] ) ) { 1434 1434 $post = get_post( $args['post'] ); 1435 1435 $settings['postId'] = $post->ID; 1436 1437 if ( current_theme_supports( 'post-thumbnails', $post->post_type ) && post_type_supports( $post->post_type, 'thumbnail' ) ) { 1438 1439 $featuredImageId = get_post_meta( $post->ID, '_thumbnail_id', true ); 1440 1441 $settings['featuredImage'] = array( 1442 'id' => $featuredImageId ? $featuredImageId : -1, 1443 'nonce' => wp_create_nonce( 'set_post_thumbnail-' . $post->ID ), 1444 ); 1445 } 1436 1446 } 1437 1447 1438 1448 $hier = $post && is_post_type_hierarchical( $post->post_type ); … … 1466 1476 // From URL 1467 1477 'fromUrlTitle' => __( 'From URL' ), 1468 1478 1479 // Featured Images 1480 'featuredImageTitle' => __( 'Featured Image' ), 1481 'setFeaturedImage' => __( 'Set featured image' ), 1482 1469 1483 // Gallery 1470 1484 'createGalleryTitle' => __( 'Create Gallery' ), 1471 1485 'editGalleryTitle' => __( 'Edit Gallery' ), … … 1508 1522 <div class="media-modal wp-core-ui"> 1509 1523 <h3 class="media-modal-title">{{ data.title }}</h3> 1510 1524 <a class="media-modal-close media-modal-icon" href="#" title="<?php esc_attr_e('Close'); ?>"></a> 1525 <div class="media-modal-content"></div> 1511 1526 </div> 1512 1527 <div class="media-modal-backdrop"> 1513 1528 <div></div>