Last active
August 31, 2020 14:45
-
-
Save vincentorback/0f4d35d8acd7e724bcf8057ec95310bd to your computer and use it in GitHub Desktop.
Undeletable WordPress pages
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 | |
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