In the QuickPress media modal, use the new post id when a post is published.

Props nacin, koopersmith
fixes #22673


git-svn-id: http://core.svn.wordpress.org/trunk@22994 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
Ryan Boren 2012-12-03 07:17:10 +00:00
parent 0848a51955
commit 63662a9b7b
8 changed files with 86 additions and 61 deletions

View File

@ -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 ) ) {

View File

@ -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;
}
?>
<form name="post" action="<?php echo esc_url( admin_url( 'post.php' ) ); ?>" method="post" id="quick-press">
@ -524,7 +534,15 @@ function wp_dashboard_quick_press() {
<textarea name="content" id="content" class="mceEditor" rows="3" cols="15"><?php echo esc_textarea( $post->post_content ); ?></textarea>
</div>
<script type="text/javascript">edCanvas = document.getElementById('content');edInsertContent = null;</script>
<script type="text/javascript">
edCanvas = document.getElementById('content');
edInsertContent = null;
<?php if ( $_POST ) : ?>
wp.media.editor.remove('content');
wp.media.view.settings.post = <?php echo json_encode( $media_settings ); // big juicy hack. ?>;
wp.media.editor.add('content');
<?php endif; ?>
</script>
<div class="input-text-wrap" id="tags-input-wrap">
<label class="screen-reader-text prompt" for="tags-input" id="tags-input-prompt-text"><?php _e( 'Tags (separate with commas)' ); ?></label>

View File

@ -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;
});
}
};

View File

@ -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.

View File

@ -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 `<option>` elements.
this.$el.html( _.chain( this.filters ).map( function( filter, value ) {
return {
@ -3093,6 +3093,10 @@
this.select();
},
createFilters: function() {
this.filters = {};
},
change: function( event ) {
var filter = this.filters[ this.el.value ];
@ -3119,31 +3123,33 @@
});
media.view.AttachmentFilters.Uploaded = media.view.AttachmentFilters.extend({
filters: {
all: {
text: l10n.allMediaItems,
props: {
uploadedTo: null,
orderby: 'date',
order: 'DESC'
createFilters: function() {
this.filters = {
all: {
text: l10n.allMediaItems,
props: {
uploadedTo: null,
orderby: 'date',
order: 'DESC'
},
priority: 10
},
priority: 10
},
uploaded: {
text: l10n.uploadedToThisPost,
props: {
uploadedTo: media.view.settings.postId,
orderby: 'menuOrder',
order: 'ASC'
},
priority: 20
}
uploaded: {
text: l10n.uploadedToThisPost,
props: {
uploadedTo: media.view.settings.post.id,
orderby: 'menuOrder',
order: 'ASC'
},
priority: 20
}
};
}
});
media.view.AttachmentFilters.All = media.view.AttachmentFilters.extend({
filters: (function() {
createFilters: function() {
var filters = {};
_.each( media.view.settings.mimeTypes || {}, function( text, key ) {
@ -3173,15 +3179,15 @@
text: l10n.uploadedToThisPost,
props: {
type: null,
uploadedTo: media.view.settings.postId,
uploadedTo: media.view.settings.post.id,
orderby: 'menuOrder',
order: 'ASC'
},
priority: 20
};
return filters;
}())
this.filters = filters;
}
});

View File

@ -157,7 +157,7 @@ window.wp = window.wp || {};
date: new Date(),
filename: file.name,
menuOrder: 0,
uploadedTo: wp.media.model.settings.postId
uploadedTo: wp.media.model.settings.post.id
}, _.pick( file, 'loaded', 'size', 'percent' ) );
// Handle early mime type scanning for images.

View File

@ -1427,23 +1427,22 @@ function wp_enqueue_media( $args = array() ) {
'nonce' => array(
'sendToEditor' => wp_create_nonce( 'media-send-to-editor' ),
),
'postId' => 0,
'post' => array(
'id' => 0,
),
);
$post = null;
if ( isset( $args['post'] ) ) {
$post = get_post( $args['post'] );
$settings['postId'] = $post->ID;
$settings['nonce']['updatePost'] = wp_create_nonce( 'update-post_' . $post->ID );
$settings['post'] = 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' ) ) {
$featuredImageId = get_post_meta( $post->ID, '_thumbnail_id', true );
$settings['featuredImage'] = array(
'id' => $featuredImageId ? $featuredImageId : -1,
'nonce' => wp_create_nonce( 'set_post_thumbnail-' . $post->ID ),
);
$featured_image_id = get_post_meta( $post->ID, '_thumbnail_id', true );
$settings['post']['featuredImageId'] = $featured_image_id ? $featured_image_id : -1;
}
}

View File

@ -323,7 +323,7 @@ function wp_default_scripts( &$scripts ) {
did_action( 'init' ) && $scripts->localize( 'media-models', '_wpMediaModelsL10n', array(
'settings' => array(
'ajaxurl' => admin_url( 'admin-ajax.php', 'relative' ),
'postId' => 0,
'post' => array( 'id' => 0 ),
),
) );