// 后台 文章列表 ajax删除文章 add_action( 'admin_footer', 'dahuzi_custom_internal_javascript' );
function dahuzi_custom_internal_javascript()
{ echo " jQuery(function($){ $('body.post-type-post .row-actions .trash a').click(function( event ){ event.preventDefault();
var url = new URL( $(this).attr('href') )
, nonce = url.searchParams.get('_wpnonce'),
// MUST for security checks row = $(this).closest('tr'),
postID = url.searchParams.get('post'),
postTitle = row.find('.row-title').text();
row.css('background-color','#ffafaf').fadeOut(300,
function(){ row.removeAttr('style').HTML('
' + postTitle + ' 已被移动到回收站').show(); }); $.ajax({ method:'POST',url: ajaxurl, data: { 'action' : 'moveposttotrash', 'post_id' : postID, '_wpnonce' : nonce } }); }); }); "; } add_action('wp_ajax_moveposttotrash', function(){ check_ajax_referer( 'trash-post_' . $_POST['post_id'] ); wp_trash_post( $_POST['post_id']
); die(); });