Skip to content

Instantly share code, notes, and snippets.

@joelcloralt
Created February 28, 2012 19:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelcloralt/1934408 to your computer and use it in GitHub Desktop.
Save joelcloralt/1934408 to your computer and use it in GitHub Desktop.
Create Wordpress Page on Theme Activation
// Create a page on theme activation
function privateMessagePage () {
$default_pages = array('This content is private'); //Page Title
$existing_pages = get_pages();
$temp = array();
foreach ($existing_pages as $page) {
$temp[] = $page->post_title;
}
$pages_to_create = array_diff($default_pages, $temp);
foreach ($pages_to_create as $new_page_title) {
$defaultPage = array(
'comment_status' =>'closed',
'ping_status' =>'closed',
'post_content' => 'This content is restricted to site members. Please contact us for more details.',
'post_excerpt' => 'This content is restricted to site members. Please contact us for more details.',
'post_name' => 'private-content',
'post_status' => 'publish',
'post_title' => 'This content is private',
'post_type' => 'page'
);
$result = wp_insert_post($defaultPage);
}
}
add_action('init', 'privateMessagePage');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment