WordPress Snippets at WPcustoms

Adjust settings on theme activation

This function changes a few default options on theme activation and deletes the demo posts and comments.


/**
 * Snippet Name: Adjust settings on theme activation
 * Snippet URL: http://www.wpcustoms.net/snippets/adjust-settings-theme-activation/
 */
 add_action( 'after_setup_theme', 'wpc_theme_activation' );
function wpc_theme_activation()
{
	// First we check to see if our default theme settings have been applied.
	$the_theme_status = get_option( 'theme_setup_status' );
	// If the theme has not yet been used we want to run our default settings.
	if ( $the_theme_status !== '1' ) {
		// Setup Default WordPress settings
		$core_settings = array(
			'avatar_default'	=> 'mystery',	// Comment Avatars should be using mystery by default
			'avatar_rating'		=> 'G',		// Avatar rating
			'comment_max_links'	=> 0,		// We do not allow links from comments
			'comments_per_page'	=> 20		// Default to 20 comments per page
		);
		foreach ( $core_settings as $k => $v ) {
			update_option( $k, $v );
		}
		// Delete dummy post, page and comment.
		wp_delete_post( 1, true );
		wp_delete_post( 2, true );
		wp_delete_comment( 1 );
		
		update_option( 'theme_setup_status', '1' );
		$msg = '
		

The ' . get_option( 'current_theme' ) . 'theme has changed your WordPress default settings and deleted default posts & comments.

'; add_action( 'admin_notices', $c = create_function( '', 'echo "' . addcslashes( $msg, '"' ) . '";' ) ); } elseif ( $the_theme_status === '1' and isset( $_GET['activated'] ) ) { $msg = '

The ' . get_option( 'current_theme' ) . ' theme was successfully re-activated.

'; add_action( 'admin_notices', $c = create_function( '', 'echo "' . addcslashes( $msg, '"' ) . '";' ) ); } }