Home > Tips, WordPress > Creating a custom WordPress Installation with default settings

Creating a custom WordPress Installation with default settings

September 24th, 2011 Leave a comment Go to comments

One of the things that I’ve learned throughout my years of software development is that if you can automate something, do it. Automation, when done correctly, saves time, creates less bugs, and bring consistency. As someone who sets up quite a few WordPress sites, one of the things I’ve come to loath is the installation process, settings updates, and installing plugins. Recently I started keeping a copy of the WordPress files with my most commonly used plugins already in the wp-content folder. This meant I just had to activate them once installation was done. But I wanted to take that a step further.

What if you could have your WordPress installation activate plugins, set your permalink structure, setup your timezone, default your comment settings, and get rid of the ‘Hello World’ and ‘Example Page’ entries?! Yeah, that might save you a few minutes. So here’s the trick.

This is altering the core of WordPress during installation. Only do this if you are comfortable with the WordPress development practices.

First off, we’re going to be editing the file ‘wp-admin/install.php’, look around line 213 (in WordPress 3.2.1):

  if ( $error === false ) {
    $wpdb->show_errors();
    $result = wp_install($weblog_title, $user_name, $admin_email, $public, '', $admin_password);
    // Next line is our new include
    require_once('extras/install-extras.php');
    extract( $result, EXTR_SKIP );

So next we make a directory within the wp-admin directory provided by WordPress and name it ‘extras’. Within that we’re going to create a file called ‘install-extras.php’. In that file is where we will create our default settings. Here is an example file:

<?php
// Activate Plugins I've already added to the wp-content/plugins directory
// before starting the installation process
// download from wordpress.org/extend/plugins
activate_plugin( 'better-adsense-targeting/better-adsense.php', '', false, false );
activate_plugin( 'advertising-manager/advertising-manager.php', '', false, false );

// Delete the Hello World Post and Example Page
wp_delete_post( 1, true );
wp_delete_post( 2, true );

// Update Some WP Options to our liking
update_option( 'default_comment_status', 'closed' );
update_option( 'default_ping_status', 'closed' );
update_option( 'permalink_structure', '/%category%/%year%/%monthnum%/%postname%/' );
update_option( 'gmt_offset', '-7' );

// Plugin specific settings
update_option( 'bat_header', '1' );
update_option( 'bat_loop', '1' );
update_option( 'bat_sidebar', '1' );
?>

These settings above are not ‘suggestions’ but settings I use for one type of site I setup frequently. This setup does close comments and pings to act more as a CMS.

Currently I did not show you how to customize each plugin, and your plugins may still require some configuration, but this will bypass that process of having to activate the plugins.

This is just an example of what you can do with this process. What settings would you default in WordPress that would increase your productivity in setting up new sites? What plugins are you using on almost all your sites?

  1. October 12th, 2011 at 16:15 | #1

    I’ll try this, thanks for posting. I love your blog very much.

  1. No trackbacks yet.