Last active
December 15, 2015 12:48
-
-
Save woodroots/5262208 to your computer and use it in GitHub Desktop.
[WordPress]削除処理をAjaxにしてサクサク削除
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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