0

Im building a wp site, that has some pages that only shows when a form has been completed. (think of "thank you for gettin in touch, we'll get back to you as soon as possible" - type pages). I have created this as a page, and then i use wp_redirect after the form has been submitted to get to it.

But now the client will be able to delete this page, and it will then go 404 on the redirect.

So the question: Is there a way that i can lock certain pages in the wp-admin? Im interested in both a solution where the certain page will disappear from a specific role, and/or a way where specific roles can't trash specific pages - but still edit it.

Thank you so much.

0

Add this to your functions.php in your theme folder:

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('wp_delete_post', 'restrict_post_deletion', 10, 1);

Taken from here and updated to the latest WP version.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.