Code chặn delete, edit, post bài viết hay page wordpress, tránh tình trạng xóa hay sửa nhầm trong wp-admin, code này có tính năng ngăn chặn các tình huống xấu nhất khi nhấn nhầm vào xóa thùng rác.
function restrict_page_deletion($post_ID){ $user = get_current_user_id(); $restricted_pageId = array(76, 80, 129, 142, 78, 17); if($post_ID == $restricted_pageId) { echo "You are not authorized to delete this page."; exit; } } add_action('before_delete_post', 'restrict_page_deletion', 10, 1); add_action('wp_trash_post', 'restrict_page_deletion', 10, 1);
Sửa các dãy số tại hàm array theo các id của page hoặc posts nhé : array(76, 80, 129, 142, 78, 17)
Các bạn gắn code sau vào Functions.php để thực hiện chặn nhé.