Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
Prevent users from deleting a specific page, post or CPT in WordPress.
function prevent_default_theme_deletion($allcaps, $caps, $args) {
$post_id = 123;
if ( isset( $args[0] ) && isset( $args[2] ) && $args[2] == $post_id && $args[0] == 'delete_post' ) {
$allcaps[ $caps[0] ] = false;
return $allcaps;
add_filter ('user_has_cap', 'prevent_default_theme_deletion', 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.