How to use the same code for multiple pages?

The code below prevents a page (defined by its title) from being deleted.

When I try to implement two occurrences of this code (one for each page I want to prevent from being deleted) I receive the white screen of death.

Read More

How would I list more than one page by title and prevent both from being deleted?

add_action( 'wp_trash_post', 'stop_deleting');
function stop_deleting($page){
    $page = get_page_by_title( 'About' );
        if ($page)
            die('You are not allowed to delete this page');
}

Related posts

1 comment

  1. Please show us your actual code, and don’t just describe what you implemented. In this particular case, it is vital to see how you tried to implement two occurrences of the code.

    Anyway, from what I understand, the following function should do what you’ve asked for:

    add_action('wp_trash_post', 'wpse_136052_do_not_delete');
    function wpse_136052_do_not_delete($id) {
        if (in_array(get_post($id), array(
            get_page_by_title('About'),
            get_page_by_title('Other Page'),
            get_page_by_title('Third Page'),
        )))
            die('You are not allowed to delete this page');
    } // function wpse_136052_do_not_delete
    

Comments are closed.