Skip to content

Instantly share code, notes, and snippets.

@vincentorback
Last active August 31, 2020 14:45
Show Gist options
  • Save vincentorback/0f4d35d8acd7e724bcf8057ec95310bd to your computer and use it in GitHub Desktop.
Save vincentorback/0f4d35d8acd7e724bcf8057ec95310bd to your computer and use it in GitHub Desktop.
Undeletable WordPress pages
<?php
function restrict_post_deletion ($post_ID) {
$restricted_pages = [
get_option('page_on_front'),
123,
666
];
if (!current_user_can('administrator') && in_array($post_ID, $restricted_pages)) {
echo "You dont have permission 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);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment