Skip to content

Instantly share code, notes, and snippets.

@woodroots
Last active December 15, 2015 12:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save woodroots/5262208 to your computer and use it in GitHub Desktop.
Save woodroots/5262208 to your computer and use it in GitHub Desktop.
[WordPress]削除処理をAjaxにしてサクサク削除
<?php
//削除処理Ajax化
function ajax_delete(){
//ヒアドキュメントでhead内にスクリプトを直接書いてます。
//スクリプトの処理自体は「ゴミ箱」のリンク先をAjaxするだけなので難しくないと思います。
print <<< EOF
<script type="text/javascript">
(function($){
$(function(){
$('a[href*="action=trash"]').on('click',function(){
var self = $(this);
//クリック直後に背景を灰色にして処理進行中であることをアピール
self.closest('tr').css({
backgroundColor: '#ccc'
});
$.ajax({
url: self.attr('href')
}).done(function(data){
self.closest('tr').remove();
$('.subsubsub').load(location.href + ' .subsubsub');
});
return false;
});
});
})(jQuery);
</script>
EOF;
}
//記事一覧ページのみにアクションフック
add_action("admin_head-edit.php", "ajax_delete");
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment