最后,我发现我无法绑定或触发此操作。我必须用javascript和ajax回调复制它,如下所示。
Javascript:
function PrismSetAsThumbnail(id, nonce){
var $link = jQuery(\'a#wp-post-thumbnail-\' + id);
$link.text( setPostThumbnailL10n.saving );
jQuery.post(ajaxurl, {
action:"prism_set_thumbnail", post_id: post_id, thumbnail_id: id, _ajax_nonce: nonce, cookie: encodeURIComponent(document.cookie)
}, function(str){
var win = window.dialogArguments || opener || parent || top;
$link.text( setPostThumbnailL10n.setThumbnail );
if ( str == \'0\' ) {
alert( setPostThumbnailL10n.error );
} else {
jQuery(\'a.wp-post-thumbnail\').show();
$link.text( setPostThumbnailL10n.done );
$link.fadeOut( 2000 );
//display new thumbnail in the columns w/o refresh
jQuery(\'#post-\'+win.post_id + \' .postimagediv a\', win.parent.document).html(str).fadeIn();
//if successful close thickbox
win.parent.tb_remove();
}
}
);
}
Ajax Callback:
//add callback for custom version of set thumbnail
add_action(\'wp_ajax_prism_set_thumbnail\', \'kia_set_thumbnail_callback\');
// the function name must match the above passed name
function kia_set_thumbnail_callback(){
$post_ID = intval( $_POST[\'post_id\'] );
if ( !current_user_can( \'edit_post\', $post_ID ) )
die( \'-1\' );
$thumbnail_id = intval( $_POST[\'thumbnail_id\'] );
check_ajax_referer( "set_post_thumbnail-$post_ID" );
if ( $thumbnail_id == \'-1\' ) {
if ( delete_post_thumbnail( $post_ID ) )
die( _wp_post_thumbnail_html() );
else
die( \'0\' );
}
if ( set_post_thumbnail( $post_ID, $thumbnail_id ) )
$msg = get_the_post_thumbnail( $post_ID, array(35,35));
die($msg);
die( \'0\' );
}