In the QuickPress media modal, use the new post id when a post is published.
Props nacin, koopersmith fixes #22673 git-svn-id: https://develop.svn.wordpress.org/trunk@22994 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
parent
594bbe90df
commit
71d333f660
@ -1674,7 +1674,7 @@ function wp_ajax_image_editor() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function wp_ajax_set_post_thumbnail() {
|
function wp_ajax_set_post_thumbnail() {
|
||||||
$json = ! empty( $_REQUEST['json'] );
|
$json = ! empty( $_REQUEST['json'] ); // New-style request
|
||||||
|
|
||||||
$post_ID = intval( $_POST['post_id'] );
|
$post_ID = intval( $_POST['post_id'] );
|
||||||
if ( !current_user_can( 'edit_post', $post_ID ) ) {
|
if ( !current_user_can( 'edit_post', $post_ID ) ) {
|
||||||
@ -1682,6 +1682,9 @@ function wp_ajax_set_post_thumbnail() {
|
|||||||
}
|
}
|
||||||
$thumbnail_id = intval( $_POST['thumbnail_id'] );
|
$thumbnail_id = intval( $_POST['thumbnail_id'] );
|
||||||
|
|
||||||
|
if ( $json )
|
||||||
|
check_ajax_referer( "update-post_$post_ID" );
|
||||||
|
else
|
||||||
check_ajax_referer( "set_post_thumbnail-$post_ID" );
|
check_ajax_referer( "set_post_thumbnail-$post_ID" );
|
||||||
|
|
||||||
if ( $thumbnail_id == '-1' ) {
|
if ( $thumbnail_id == '-1' ) {
|
||||||
|
@ -505,6 +505,16 @@ function wp_dashboard_quick_press() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
$post_ID = (int) $post->ID;
|
$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">
|
<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>
|
<textarea name="content" id="content" class="mceEditor" rows="3" cols="15"><?php echo esc_textarea( $post->post_content ); ?></textarea>
|
||||||
</div>
|
</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">
|
<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>
|
<label class="screen-reader-text prompt" for="tags-input" id="tags-input-prompt-text"><?php _e( 'Tags (separate with commas)' ); ?></label>
|
||||||
|
@ -163,7 +163,7 @@
|
|||||||
return {
|
return {
|
||||||
defaults: {
|
defaults: {
|
||||||
order: 'ASC',
|
order: 'ASC',
|
||||||
id: wp.media.view.settings.postId,
|
id: wp.media.view.settings.post.id,
|
||||||
itemtag: 'dl',
|
itemtag: 'dl',
|
||||||
icontag: 'dt',
|
icontag: 'dt',
|
||||||
captiontag: 'dd',
|
captiontag: 'dd',
|
||||||
@ -439,18 +439,17 @@
|
|||||||
|
|
||||||
workflow.state('featured-image').on( 'select', function() {
|
workflow.state('featured-image').on( 'select', function() {
|
||||||
var settings = wp.media.view.settings,
|
var settings = wp.media.view.settings,
|
||||||
featuredImage = settings.featuredImage,
|
|
||||||
selection = this.get('selection').single();
|
selection = this.get('selection').single();
|
||||||
|
|
||||||
if ( ! featuredImage )
|
if ( ! settings.post.featuredImageId )
|
||||||
return;
|
return;
|
||||||
|
|
||||||
featuredImage.id = selection ? selection.id : -1;
|
settings.post.featuredImageId = selection ? selection.id : -1;
|
||||||
wp.media.post( 'set-post-thumbnail', {
|
wp.media.post( 'set-post-thumbnail', {
|
||||||
json: true,
|
json: true,
|
||||||
post_id: settings.postId,
|
post_id: settings.post.id,
|
||||||
thumbnail_id: featuredImage.id,
|
thumbnail_id: settings.post.featuredImageId,
|
||||||
_wpnonce: featuredImage.nonce
|
_wpnonce: settings.post.nonce
|
||||||
}).done( function( html ) {
|
}).done( function( html ) {
|
||||||
$( '.inside', '#postimagediv' ).html( html );
|
$( '.inside', '#postimagediv' ).html( html );
|
||||||
});
|
});
|
||||||
@ -526,7 +525,7 @@
|
|||||||
nonce: wp.media.view.settings.nonce.sendToEditor,
|
nonce: wp.media.view.settings.nonce.sendToEditor,
|
||||||
attachment: options,
|
attachment: options,
|
||||||
html: html,
|
html: html,
|
||||||
post_id: wp.media.view.settings.postId
|
post_id: wp.media.view.settings.post.id
|
||||||
}).done( function( resp ) {
|
}).done( function( resp ) {
|
||||||
wp.media.editor.insert( resp );
|
wp.media.editor.insert( resp );
|
||||||
});
|
});
|
||||||
@ -538,7 +537,7 @@
|
|||||||
src: embed.linkUrl,
|
src: embed.linkUrl,
|
||||||
title: embed.title,
|
title: embed.title,
|
||||||
html: wp.media.string.link( embed ),
|
html: wp.media.string.link( embed ),
|
||||||
post_id: wp.media.view.settings.postId
|
post_id: wp.media.view.settings.post.id
|
||||||
}).done( function( resp ) {
|
}).done( function( resp ) {
|
||||||
wp.media.editor.insert( resp );
|
wp.media.editor.insert( resp );
|
||||||
});
|
});
|
||||||
@ -614,7 +613,7 @@
|
|||||||
|
|
||||||
// Update the featured image id when the 'remove' link is clicked.
|
// Update the featured image id when the 'remove' link is clicked.
|
||||||
}).on( 'click', '#remove-post-thumbnail', function() {
|
}).on( 'click', '#remove-post-thumbnail', function() {
|
||||||
wp.media.view.settings.featuredImage.id = -1;
|
wp.media.view.settings.post.featuredImageId = -1;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -244,7 +244,7 @@ window.wp = window.wp || {};
|
|||||||
action: 'save-attachment',
|
action: 'save-attachment',
|
||||||
id: this.id,
|
id: this.id,
|
||||||
nonce: this.get('nonces').update,
|
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.
|
// Record the values of the changed attributes.
|
||||||
@ -289,7 +289,7 @@ window.wp = window.wp || {};
|
|||||||
return media.post( 'save-attachment-compat', _.defaults({
|
return media.post( 'save-attachment-compat', _.defaults({
|
||||||
id: this.id,
|
id: this.id,
|
||||||
nonce: this.get('nonces').update,
|
nonce: this.get('nonces').update,
|
||||||
post_id: media.model.settings.postId
|
post_id: media.model.settings.post.id
|
||||||
}, data ) ).done( function( resp, status, xhr ) {
|
}, data ) ).done( function( resp, status, xhr ) {
|
||||||
model.set( model.parse( resp, xhr ), options );
|
model.set( model.parse( resp, xhr ), options );
|
||||||
});
|
});
|
||||||
@ -548,8 +548,8 @@ window.wp = window.wp || {};
|
|||||||
return;
|
return;
|
||||||
|
|
||||||
return media.post( 'save-attachment-order', {
|
return media.post( 'save-attachment-order', {
|
||||||
nonce: media.model.settings.updatePostNonce,
|
nonce: media.model.settings.post.nonce,
|
||||||
post_id: media.model.settings.postId,
|
post_id: media.model.settings.post.id,
|
||||||
attachments: attachments
|
attachments: attachments
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -705,7 +705,7 @@ window.wp = window.wp || {};
|
|||||||
options.context = this;
|
options.context = this;
|
||||||
options.data = _.extend( options.data || {}, {
|
options.data = _.extend( options.data || {}, {
|
||||||
action: 'query-attachments',
|
action: 'query-attachments',
|
||||||
post_id: media.model.settings.postId
|
post_id: media.model.settings.post.id
|
||||||
});
|
});
|
||||||
|
|
||||||
// Clone the args so manipulation is non-destructive.
|
// Clone the args so manipulation is non-destructive.
|
||||||
|
@ -12,9 +12,8 @@
|
|||||||
media.view.settings = l10n.settings || {};
|
media.view.settings = l10n.settings || {};
|
||||||
delete l10n.settings;
|
delete l10n.settings;
|
||||||
|
|
||||||
// Copy the `postId` setting over to the model settings.
|
// Copy the `post` setting over to the model settings.
|
||||||
media.model.settings.postId = media.view.settings.postId;
|
media.model.settings.post = media.view.settings.post;
|
||||||
media.model.settings.updatePostNonce = media.view.settings.nonce.updatePost;
|
|
||||||
|
|
||||||
// Check if the browser supports CSS 3.0 transitions
|
// Check if the browser supports CSS 3.0 transitions
|
||||||
$.support.transition = (function(){
|
$.support.transition = (function(){
|
||||||
@ -607,7 +606,7 @@
|
|||||||
|
|
||||||
activate: function() {
|
activate: function() {
|
||||||
var selection = this.get('selection'),
|
var selection = this.get('selection'),
|
||||||
id = media.view.settings.featuredImage.id,
|
id = media.view.settings.post.featuredImageId,
|
||||||
attachment;
|
attachment;
|
||||||
|
|
||||||
if ( '' !== id && -1 !== id ) {
|
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({
|
this.states.add( new media.controller.FeaturedImage({
|
||||||
controller: this,
|
controller: this,
|
||||||
menu: 'main'
|
menu: 'main'
|
||||||
@ -1535,7 +1534,7 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
if ( media.view.settings.featuredImage ) {
|
if ( media.view.settings.post.featuredImageId ) {
|
||||||
this.menu.view().set( 'featured-image', {
|
this.menu.view().set( 'featured-image', {
|
||||||
text: l10n.featuredImageTitle,
|
text: l10n.featuredImageTitle,
|
||||||
priority: 100
|
priority: 100
|
||||||
@ -1862,7 +1861,7 @@
|
|||||||
},
|
},
|
||||||
|
|
||||||
ready: function() {
|
ready: function() {
|
||||||
var postId = media.view.settings.postId,
|
var postId = media.view.settings.post.id,
|
||||||
dropzone;
|
dropzone;
|
||||||
|
|
||||||
// If the uploader already exists, bail.
|
// If the uploader already exists, bail.
|
||||||
@ -1913,7 +1912,7 @@
|
|||||||
this.options.$browser = this.controller.uploader.$browser;
|
this.options.$browser = this.controller.uploader.$browser;
|
||||||
|
|
||||||
if ( _.isUndefined( this.options.postId ) )
|
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({
|
this.views.set( '.upload-inline-status', new media.view.UploaderStatus({
|
||||||
controller: this.controller
|
controller: this.controller
|
||||||
@ -3077,10 +3076,11 @@
|
|||||||
change: 'change'
|
change: 'change'
|
||||||
},
|
},
|
||||||
|
|
||||||
filters: {},
|
|
||||||
keys: [],
|
keys: [],
|
||||||
|
|
||||||
initialize: function() {
|
initialize: function() {
|
||||||
|
this.createFilters();
|
||||||
|
|
||||||
// Build `<option>` elements.
|
// Build `<option>` elements.
|
||||||
this.$el.html( _.chain( this.filters ).map( function( filter, value ) {
|
this.$el.html( _.chain( this.filters ).map( function( filter, value ) {
|
||||||
return {
|
return {
|
||||||
@ -3093,6 +3093,10 @@
|
|||||||
this.select();
|
this.select();
|
||||||
},
|
},
|
||||||
|
|
||||||
|
createFilters: function() {
|
||||||
|
this.filters = {};
|
||||||
|
},
|
||||||
|
|
||||||
change: function( event ) {
|
change: function( event ) {
|
||||||
var filter = this.filters[ this.el.value ];
|
var filter = this.filters[ this.el.value ];
|
||||||
|
|
||||||
@ -3119,7 +3123,8 @@
|
|||||||
});
|
});
|
||||||
|
|
||||||
media.view.AttachmentFilters.Uploaded = media.view.AttachmentFilters.extend({
|
media.view.AttachmentFilters.Uploaded = media.view.AttachmentFilters.extend({
|
||||||
filters: {
|
createFilters: function() {
|
||||||
|
this.filters = {
|
||||||
all: {
|
all: {
|
||||||
text: l10n.allMediaItems,
|
text: l10n.allMediaItems,
|
||||||
props: {
|
props: {
|
||||||
@ -3133,17 +3138,18 @@
|
|||||||
uploaded: {
|
uploaded: {
|
||||||
text: l10n.uploadedToThisPost,
|
text: l10n.uploadedToThisPost,
|
||||||
props: {
|
props: {
|
||||||
uploadedTo: media.view.settings.postId,
|
uploadedTo: media.view.settings.post.id,
|
||||||
orderby: 'menuOrder',
|
orderby: 'menuOrder',
|
||||||
order: 'ASC'
|
order: 'ASC'
|
||||||
},
|
},
|
||||||
priority: 20
|
priority: 20
|
||||||
}
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
media.view.AttachmentFilters.All = media.view.AttachmentFilters.extend({
|
media.view.AttachmentFilters.All = media.view.AttachmentFilters.extend({
|
||||||
filters: (function() {
|
createFilters: function() {
|
||||||
var filters = {};
|
var filters = {};
|
||||||
|
|
||||||
_.each( media.view.settings.mimeTypes || {}, function( text, key ) {
|
_.each( media.view.settings.mimeTypes || {}, function( text, key ) {
|
||||||
@ -3173,15 +3179,15 @@
|
|||||||
text: l10n.uploadedToThisPost,
|
text: l10n.uploadedToThisPost,
|
||||||
props: {
|
props: {
|
||||||
type: null,
|
type: null,
|
||||||
uploadedTo: media.view.settings.postId,
|
uploadedTo: media.view.settings.post.id,
|
||||||
orderby: 'menuOrder',
|
orderby: 'menuOrder',
|
||||||
order: 'ASC'
|
order: 'ASC'
|
||||||
},
|
},
|
||||||
priority: 20
|
priority: 20
|
||||||
};
|
};
|
||||||
|
|
||||||
return filters;
|
this.filters = filters;
|
||||||
}())
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
@ -157,7 +157,7 @@ window.wp = window.wp || {};
|
|||||||
date: new Date(),
|
date: new Date(),
|
||||||
filename: file.name,
|
filename: file.name,
|
||||||
menuOrder: 0,
|
menuOrder: 0,
|
||||||
uploadedTo: wp.media.model.settings.postId
|
uploadedTo: wp.media.model.settings.post.id
|
||||||
}, _.pick( file, 'loaded', 'size', 'percent' ) );
|
}, _.pick( file, 'loaded', 'size', 'percent' ) );
|
||||||
|
|
||||||
// Handle early mime type scanning for images.
|
// Handle early mime type scanning for images.
|
||||||
|
@ -1427,23 +1427,22 @@ function wp_enqueue_media( $args = array() ) {
|
|||||||
'nonce' => array(
|
'nonce' => array(
|
||||||
'sendToEditor' => wp_create_nonce( 'media-send-to-editor' ),
|
'sendToEditor' => wp_create_nonce( 'media-send-to-editor' ),
|
||||||
),
|
),
|
||||||
'postId' => 0,
|
'post' => array(
|
||||||
|
'id' => 0,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
|
|
||||||
$post = null;
|
$post = null;
|
||||||
if ( isset( $args['post'] ) ) {
|
if ( isset( $args['post'] ) ) {
|
||||||
$post = get_post( $args['post'] );
|
$post = get_post( $args['post'] );
|
||||||
$settings['postId'] = $post->ID;
|
$settings['post'] = array(
|
||||||
$settings['nonce']['updatePost'] = wp_create_nonce( 'update-post_' . $post->ID );
|
'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' ) ) {
|
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 );
|
||||||
$featuredImageId = get_post_meta( $post->ID, '_thumbnail_id', true );
|
$settings['post']['featuredImageId'] = $featured_image_id ? $featured_image_id : -1;
|
||||||
|
|
||||||
$settings['featuredImage'] = array(
|
|
||||||
'id' => $featuredImageId ? $featuredImageId : -1,
|
|
||||||
'nonce' => wp_create_nonce( 'set_post_thumbnail-' . $post->ID ),
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -323,7 +323,7 @@ function wp_default_scripts( &$scripts ) {
|
|||||||
did_action( 'init' ) && $scripts->localize( 'media-models', '_wpMediaModelsL10n', array(
|
did_action( 'init' ) && $scripts->localize( 'media-models', '_wpMediaModelsL10n', array(
|
||||||
'settings' => array(
|
'settings' => array(
|
||||||
'ajaxurl' => admin_url( 'admin-ajax.php', 'relative' ),
|
'ajaxurl' => admin_url( 'admin-ajax.php', 'relative' ),
|
||||||
'postId' => 0,
|
'post' => array( 'id' => 0 ),
|
||||||
),
|
),
|
||||||
) );
|
) );
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user