Amy-Mir / inc / secure-core-pages.php
secure-core-pages.php
Raw
<?php
/**
 * Restrict theme core pages from being deleted & trashed 
 *
 * @package UnderStrap
 */

// Exit if accessed directly.
defined( 'ABSPATH' ) || exit;

add_action('before_delete_post', 'restrict_page_deletion', 10, 1);
add_action('wp_trash_post', 'restrict_page_deletion', 10, 1);

function restrict_page_deletion($post_ID){
    $user = get_current_user_id();

    $restricted_pages_Ids = array(60, 140, 2);

    if(in_array($post_ID, $restricted_pages_Ids)) {
        echo "You are not authorized to delete this page.";
        exit;
    }
}