布莱恩·费特的答案几乎是完美的。
在我的测试中,只有将操作更改为“wp\\u trash\\u post”和“before\\u delete\\u post”时,他的答案才有效
function restrict_post_deletion($post_ID){
$user = get_current_user_id();
$restricted_users = array(21,25,54,2,19);
$restricted_pages = array(2,21,52,64);
if(in_array($user, $restricted_users) && in_array($post_ID, $restricted_pages)){
echo "You are not authorized to delete this page.";
exit;
}
}
add_action(\'wp_trash_post\', \'restrict_post_deletion\', 10, 1);
add_action(\'before_delete_post\', \'restrict_post_deletion\', 10, 1);