Quantcast
Channel: WordPress › Support » Forum: Hacks - Recent Topics
Viewing all articles
Browse latest Browse all 8245

lwynne on "Automatic Page Generation Error"

$
0
0

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 all articles
Browse latest Browse all 8245

Trending Articles