• Resolved lwynne

    (@lwynne)


    I use the code below to generate a page called ‘Disclaimer’ if there is currently not a disclaimer page on the blog. This code works well. The problem is that if a user deletes the ‘Disclaimer’ page, this code will generate the page multiple times over again.

    I’m curious how to prevent this from happening by making it so the page cannot be deleted. Preferably, when a user deletes the page a dialog box of some sort would pop-up which would say “This page cannot be deleted.”

    Is this possible?

    // If there is no disclaimer, generate one from its template
    $disclaimer_query = new WP_Query(array(
        'pagename' => 'disclaimer',
        'post_type' => 'page',
        'post_status' => 'publish',
        'posts_per_page' => 1,
    ));
    if (! $disclaimer_query->post_count)
        wp_insert_post(array(
            'post_name' => 'disclaimer',
            'post_title' => 'Disclaimer',
            'post_status' => 'publish',
            'post_type' => 'page',
            'post_author' => 1,
            'page_template' => 'page.php',
        ));
    unset($disclaimer_query);
Viewing 1 replies (of 1 total)
  • Moderator bcworkz

    (@bcworkz)

    I’m not sure if you really resolved this or if it was a mistake. It’s always good for resolved threads to contain a solution for those coming here from a search results page. So here’s an answer ??

    Create a Custom Post Type to use for any pages that only certain users can delete. Each post type has an independent set of capabilities to edit, delete, publish, etc. Set up the capabilities so that only specific trusted users can delete this post type and no one else. Capabilities can be independent of roles, it’s possible to set up capabilities so even admins cannot delete this post type. Just ensure that someone can ??

Viewing 1 replies (of 1 total)
  • The topic ‘Automatic Page Generation Error’ is closed to new replies.