2018-06-27 22:30:15 -04:00
|
|
|
/**
|
|
|
|
* @output wp-admin/js/set-post-thumbnail.js
|
|
|
|
*/
|
|
|
|
|
2020-07-07 14:55:04 -04:00
|
|
|
/* global ajaxurl, post_id, alert */
|
2013-11-15 00:12:09 -05:00
|
|
|
/* exported WPSetAsThumbnail */
|
|
|
|
|
2018-08-19 09:33:24 -04:00
|
|
|
window.WPSetAsThumbnail = function( id, nonce ) {
|
2012-08-22 20:04:18 -04:00
|
|
|
var $link = jQuery('a#wp-post-thumbnail-' + id);
|
|
|
|
|
2020-07-07 14:55:04 -04:00
|
|
|
$link.text( wp.i18n.__( 'Saving…' ) );
|
2012-08-22 20:04:18 -04:00
|
|
|
jQuery.post(ajaxurl, {
|
2013-11-15 00:12:09 -05:00
|
|
|
action: 'set-post-thumbnail', post_id: post_id, thumbnail_id: id, _ajax_nonce: nonce, cookie: encodeURIComponent( document.cookie )
|
2012-08-22 20:04:18 -04:00
|
|
|
}, function(str){
|
|
|
|
var win = window.dialogArguments || opener || parent || top;
|
2020-07-07 14:55:04 -04:00
|
|
|
$link.text( wp.i18n.__( 'Use as featured image' ) );
|
2012-08-22 20:04:18 -04:00
|
|
|
if ( str == '0' ) {
|
2020-07-07 14:55:04 -04:00
|
|
|
alert( wp.i18n.__( 'Could not set that as the thumbnail image. Try a different attachment.' ) );
|
2012-08-22 20:04:18 -04:00
|
|
|
} else {
|
|
|
|
jQuery('a.wp-post-thumbnail').show();
|
2020-07-07 14:55:04 -04:00
|
|
|
$link.text( wp.i18n.__( 'Done' ) );
|
2012-08-22 20:04:18 -04:00
|
|
|
$link.fadeOut( 2000 );
|
|
|
|
win.WPSetThumbnailID(id);
|
|
|
|
win.WPSetThumbnailHTML(str);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
);
|
2018-08-19 09:33:24 -04:00
|
|
|
};
|