Skip to content

Instantly share code, notes, and snippets.

@Steveorevo
Last active April 6, 2016 07:08
Show Gist options
  • Save Steveorevo/7575937 to your computer and use it in GitHub Desktop.
Save Steveorevo/7575937 to your computer and use it in GitHub Desktop.
Automate your WordPress installation with this WordPress "drop in" (goes in your wp-contents folder).
<?php
echo 'This has been customized!!!';
// Perform post-install customizations
if ( function_exists( 'add_action' ) ){
add_action( 'wp_mail_content_type' , 'customize_install' );
function customize_install(){
// Switch themes
switch_theme('twentytwelve');
// Default the timezone
update_option( 'timezone_string', 'America/Chicago' );
// Increase the Size of the Post Editor
update_option( 'default_post_edit_rows', 40 );
// Remove Hello Dolly
delete_plugins( array('hello.php') );
// Remove default hello world post
wp_delete_post(1,true);
// Remove default sample page
wp_delete_post(2,true);
// Remove default Mr.Wordpress comment
wp_delete_comment( 1, true ) ;
// Activate Akismet
activate_plugin( WP_PLUGIN_DIR . '/akismet/akismet.php' );
// Update Permalinks
update_option( 'selection','custom' );
update_option( 'permalink_structure','/%post_id%/%postname%/' );
global $wp_rewrite;
$wp_rewrite->flush_rules();
// Prevent new website notice
global $phpmailer;
$phpmailer = new PHPMailer(); // reset
}
}
@Steveorevo
Copy link
Author

Because we've hooked wp_mail_content_type in the install.php, all of WordPress' core API is available to us to customize WordPress' installation (i.e. you have access to the global $wpdb, etc.). This is a simplified adaption of http://www.kathyisawesome.com/421/customizing-wordpress-install/.

Unlike replacing the wp_install_defaults core function (and all the subject-to-core changes overhead that comes with it), our code is just about customizations and not about replicating any existing defaults or duplicating installer prerequisites.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment