How to Create a Custom WordPress Install Package?

I’ve answered a similar Question. Basically:

  • create a Dropin plugin at the root of wp-content named install.php

  • inside install.php, create a new version of the pluggable function wp_install_defaults()

  • remove all unwanted defaults and customize at will, like:

    • update_option('template', 'your-theme');

    • update_option('stylesheet', 'your-theme');

    • update_option('current_theme', 'Your Theme');

    • update_option('my_theme_options', $theme_options_array );

    • auto-activate some bundled plugins

  • bundle everything into one package (WordPress files and content files: Theme, Plugins, install.php)

  • now, whenever you run a install, the Dropin will be processed and the new site starts up with your pre-configurations


I did some more tests in my development environment and updated the Gist from the other answer with a working install.php.
Now it contains the function wpse_4041_run_activate_plugin($plugin) (to activate bundled plugins) and an empty wp_new_blog_notification() (which is another pluggable and prevents WP from sending a notification email about the site installation).

I used the theme F8 Lite for testing. Most of the code is an adaptation of the original script (default Page, Post, Comment, Category, Blogroll). And at the end, my custom commands (change theme, set theme options, activate plugins, set plugin options).

Check the comments on the file.


Not sure if it’s the best method, but inside the theme functions.php file I put this script that will delete the file wp-content/install.php. It will run only once (based on this Answer by @bainternet) and after WP has been installed.

// If the option doesn't exist and the install script is there, delete it
if ( wpse_25643_run_once( 'my_custom_install_2013' ) )
{
    if( file_exists( WP_CONTENT_DIR.'/install.php' ) ) 
    {
        unlink( WP_CONTENT_DIR.'/install.php' );
    }
}

/**
 * Check if option exist
 *
 * @param string $key
 * @return boolean
 **/
function wpse_25643_run_once( $key )
{
    $test_case = get_option( 'run_once' );

    if ( isset( $test_case[$key] ) && $test_case[$key] )
    {
        return false;
    }
    else
    {
        $test_case[$key] = true;
        update_option( 'run_once', $test_case );
        return true;
    }
}

Related Q&A with another method that doesn’t use install.php:
Initialization Script for “Standard” Aspects of a WordPress Website?

Leave a Comment