diff --git a/wp-admin/includes/ajax-actions.php b/wp-admin/includes/ajax-actions.php index 4e72d1ec3e..adf6b7f2a5 100644 --- a/wp-admin/includes/ajax-actions.php +++ b/wp-admin/includes/ajax-actions.php @@ -1674,7 +1674,7 @@ function wp_ajax_image_editor() { } function wp_ajax_set_post_thumbnail() { - $json = ! empty( $_REQUEST['json'] ); + $json = ! empty( $_REQUEST['json'] ); // New-style request $post_ID = intval( $_POST['post_id'] ); if ( !current_user_can( 'edit_post', $post_ID ) ) { @@ -1682,7 +1682,10 @@ function wp_ajax_set_post_thumbnail() { } $thumbnail_id = intval( $_POST['thumbnail_id'] ); - check_ajax_referer( "set_post_thumbnail-$post_ID" ); + if ( $json ) + check_ajax_referer( "update-post_$post_ID" ); + else + check_ajax_referer( "set_post_thumbnail-$post_ID" ); if ( $thumbnail_id == '-1' ) { if ( delete_post_thumbnail( $post_ID ) ) { diff --git a/wp-admin/includes/dashboard.php b/wp-admin/includes/dashboard.php index c4a718e9e0..7414aaf464 100644 --- a/wp-admin/includes/dashboard.php +++ b/wp-admin/includes/dashboard.php @@ -505,6 +505,16 @@ function wp_dashboard_quick_press() { } $post_ID = (int) $post->ID; + + $media_settings = array( + 'id' => $post->ID, + 'nonce' => wp_create_nonce( 'update-post_' . $post->ID ), + ); + + if ( current_theme_supports( 'post-thumbnails', $post->post_type ) && post_type_supports( $post->post_type, 'thumbnail' ) ) { + $featured_image_id = get_post_meta( $post->ID, '_thumbnail_id', true ); + $media_settings['featuredImageId'] = $featured_image_id ? $featured_image_id : -1; + } ?>
@@ -524,7 +534,15 @@ function wp_dashboard_quick_press() { - +
diff --git a/wp-includes/js/media-editor.js b/wp-includes/js/media-editor.js index 64081c7d73..a00534c32c 100644 --- a/wp-includes/js/media-editor.js +++ b/wp-includes/js/media-editor.js @@ -163,7 +163,7 @@ return { defaults: { order: 'ASC', - id: wp.media.view.settings.postId, + id: wp.media.view.settings.post.id, itemtag: 'dl', icontag: 'dt', captiontag: 'dd', @@ -439,18 +439,17 @@ workflow.state('featured-image').on( 'select', function() { var settings = wp.media.view.settings, - featuredImage = settings.featuredImage, selection = this.get('selection').single(); - if ( ! featuredImage ) + if ( ! settings.post.featuredImageId ) return; - featuredImage.id = selection ? selection.id : -1; + settings.post.featuredImageId = selection ? selection.id : -1; wp.media.post( 'set-post-thumbnail', { json: true, - post_id: settings.postId, - thumbnail_id: featuredImage.id, - _wpnonce: featuredImage.nonce + post_id: settings.post.id, + thumbnail_id: settings.post.featuredImageId, + _wpnonce: settings.post.nonce }).done( function( html ) { $( '.inside', '#postimagediv' ).html( html ); }); @@ -526,7 +525,7 @@ nonce: wp.media.view.settings.nonce.sendToEditor, attachment: options, html: html, - post_id: wp.media.view.settings.postId + post_id: wp.media.view.settings.post.id }).done( function( resp ) { wp.media.editor.insert( resp ); }); @@ -538,7 +537,7 @@ src: embed.linkUrl, title: embed.title, html: wp.media.string.link( embed ), - post_id: wp.media.view.settings.postId + post_id: wp.media.view.settings.post.id }).done( function( resp ) { wp.media.editor.insert( resp ); }); @@ -614,7 +613,7 @@ // Update the featured image id when the 'remove' link is clicked. }).on( 'click', '#remove-post-thumbnail', function() { - wp.media.view.settings.featuredImage.id = -1; + wp.media.view.settings.post.featuredImageId = -1; }); } }; diff --git a/wp-includes/js/media-models.js b/wp-includes/js/media-models.js index c64a023fa1..332fe0e0fa 100644 --- a/wp-includes/js/media-models.js +++ b/wp-includes/js/media-models.js @@ -244,7 +244,7 @@ window.wp = window.wp || {}; action: 'save-attachment', id: this.id, nonce: this.get('nonces').update, - post_id: media.model.settings.postId + post_id: media.model.settings.post.id }); // Record the values of the changed attributes. @@ -289,7 +289,7 @@ window.wp = window.wp || {}; return media.post( 'save-attachment-compat', _.defaults({ id: this.id, nonce: this.get('nonces').update, - post_id: media.model.settings.postId + post_id: media.model.settings.post.id }, data ) ).done( function( resp, status, xhr ) { model.set( model.parse( resp, xhr ), options ); }); @@ -548,8 +548,8 @@ window.wp = window.wp || {}; return; return media.post( 'save-attachment-order', { - nonce: media.model.settings.updatePostNonce, - post_id: media.model.settings.postId, + nonce: media.model.settings.post.nonce, + post_id: media.model.settings.post.id, attachments: attachments }); } @@ -705,7 +705,7 @@ window.wp = window.wp || {}; options.context = this; options.data = _.extend( options.data || {}, { action: 'query-attachments', - post_id: media.model.settings.postId + post_id: media.model.settings.post.id }); // Clone the args so manipulation is non-destructive. diff --git a/wp-includes/js/media-views.js b/wp-includes/js/media-views.js index 89de1da126..89358ec1f1 100644 --- a/wp-includes/js/media-views.js +++ b/wp-includes/js/media-views.js @@ -12,9 +12,8 @@ media.view.settings = l10n.settings || {}; delete l10n.settings; - // Copy the `postId` setting over to the model settings. - media.model.settings.postId = media.view.settings.postId; - media.model.settings.updatePostNonce = media.view.settings.nonce.updatePost; + // Copy the `post` setting over to the model settings. + media.model.settings.post = media.view.settings.post; // Check if the browser supports CSS 3.0 transitions $.support.transition = (function(){ @@ -607,7 +606,7 @@ activate: function() { var selection = this.get('selection'), - id = media.view.settings.featuredImage.id, + id = media.view.settings.post.featuredImageId, attachment; if ( '' !== id && -1 !== id ) { @@ -1483,7 +1482,7 @@ ]); - if ( media.view.settings.featuredImage ) { + if ( media.view.settings.post.featuredImageId ) { this.states.add( new media.controller.FeaturedImage({ controller: this, menu: 'main' @@ -1535,7 +1534,7 @@ } }); - if ( media.view.settings.featuredImage ) { + if ( media.view.settings.post.featuredImageId ) { this.menu.view().set( 'featured-image', { text: l10n.featuredImageTitle, priority: 100 @@ -1862,7 +1861,7 @@ }, ready: function() { - var postId = media.view.settings.postId, + var postId = media.view.settings.post.id, dropzone; // If the uploader already exists, bail. @@ -1913,7 +1912,7 @@ this.options.$browser = this.controller.uploader.$browser; if ( _.isUndefined( this.options.postId ) ) - this.options.postId = media.view.settings.postId; + this.options.postId = media.view.settings.post.id; this.views.set( '.upload-inline-status', new media.view.UploaderStatus({ controller: this.controller @@ -3077,10 +3076,11 @@ change: 'change' }, - filters: {}, keys: [], initialize: function() { + this.createFilters(); + // Build `