Theme activation hooks

<?php

ActivationHooks::init();

class ActivationHooks {
function init(){
register_activation_hook(__FILE__,array(__CLASS__,'activate'));
register_deactivation_hook(__FILE__,array(__CLASS__,'deactivate'));
}
function activate(){
register_uninstall_hook(__FILE__,array(__CLASS__,'uninstall'));
}
function deactivate(){
// Remove cron jobs here
}
function uninstall(){
// Delete options here
}
}
?>

Theme activation hooks

//Activate Hooks
ddt_theme_activation_hook('desert_default','ddt_theme_activate');
ddt_theme_deactivation_hook('desert_default','ddt_theme_deactivate');

//Activation Routine
function ddt_theme_activate(){
$first_activation = get_option('desert_default_activated');
if(!$first_activation) update_option('desert_default_activated',1); //Set first activation option
}

//Deactivation Routine
function ddt_theme_deactivate(){
//Code here to run on de-activation
}

//Activation Hook
function ddt_theme_activation_hook($theme,$callback){
$option_name = $theme . "_active";
if(!get_option($option_name)) {
call_user_func($callback);
update_option($option_name,1);
}
}

//Deactivation Hook
function ddt_theme_deactivation_hook($theme,$callback){
$GLOBALS[$theme . '_deactivation_hook_fn'] = $callback;
$action_fn = create_function('$theme',' call_user_func($GLOBALS["' . $theme . '_deactivation_hook_fn"]); delete_option("' . $theme . '_active");');
add_action('switch_theme',$action_fn);
}

Create page with php

<?php

$page_check = get_page_by_title('My New Page');
$page_check_id = $page_check->ID;

$new_page = array(
'post_type' => 'page',
'post_title' => 'My New Page',
'post_content' => 'This is my new page',
'post_status' => 'publish',
'post_author' => 1,
);

if(!isset($page_check_id)){
wp_insert_post($new_page);
$new_page_data = get_page_by_title('My New Page');
$new_page_id = $new_page_data->ID;
update_post_meta($new_page_id, '_wp_page_template','template-video.php');
}

//This version works as an engine for creating many pages by running through one function.  The page title is used for the page template file name so: 'Audio Admin' will be tied to the template named template-audioadmin.php

$default_pages = array('Audio Admin','Video Admin');
foreach($default_pages as $page){
$page_check = get_page_by_title($page);
$page_check_id = $page_check->ID;
if(!isset($page_check_id)) lmcb_create_pg($page);
}
function lmcb_create_pg($title){
$new_page = array(
'post_type' => 'page',
'post_title' => $title,
'post_status' => 'publish',
'post_author' => 1,
);
wp_insert_post($new_page);
$new_page_data = get_page_by_title($title);
$new_page_id = $new_page_data->ID;
$lower_title = strtolower($title);
$template_file = 'template-' . str_replace(' ','',$lower_title) . '.php';
echo $template_file;
update_post_meta($new_page_id, '_wp_page_template',$template_file);
}

?>