-
-
Save jeherve/9025d0cab66e28f61a43 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// We'll overwrite the default wp_install_defaults function, found in wp-admin/includes/upgrade.php | |
function wp_install_defaults( $user_id ) { | |
global $wpdb, $wp_rewrite, $table_prefix; | |
/** | |
* Set a site title. | |
*/ | |
update_option( 'blogname', 'My Great Test blog' ); | |
/** | |
* Set a site description. | |
*/ | |
update_option( 'blogdescription', 'A site description' ); | |
/** | |
* Set a default category, "News". | |
*/ | |
$cat_name = __( 'News' ); | |
$cat_slug = sanitize_title( _x( 'News', 'Default category slug' ) ); | |
if ( global_terms_enabled() ) { | |
$cat_id = $wpdb->get_var( $wpdb->prepare( "SELECT cat_ID FROM { $wpdb->sitecategories } WHERE category_nicename = %s", $cat_slug ) ); | |
if ( $cat_id == null ) { | |
$wpdb->insert( $wpdb->sitecategories, array( | |
'cat_ID' => 0, | |
'cat_name' => $cat_name, | |
'category_nicename' => $cat_slug, | |
'last_updated' => current_time('mysql', true) | |
) ); | |
$cat_id = $wpdb->insert_id; | |
} | |
update_option( 'default_category', $cat_id ); | |
} else { | |
$cat_id = 1; | |
} | |
$wpdb->insert( $wpdb->terms, array( | |
'term_id' => $cat_id, | |
'name' => $cat_name, | |
'slug' => $cat_slug, | |
'term_group' => 0 | |
) ); | |
$wpdb->insert( $wpdb->term_taxonomy, array( | |
'term_id' => $cat_id, | |
'taxonomy' => 'category', | |
'description' => '', | |
'parent' => 0, | |
'count' => 1 | |
) ); | |
$cat_tt_id = $wpdb->insert_id; | |
/** | |
* Set Timezone | |
*/ | |
$timezone = "Europe/Bucharest"; | |
update_option( 'timezone_string', $timezone ); | |
// Start the week on Monday | |
update_option( 'start_of_week', 1 ); | |
/** | |
* Update Permalinks and use post name only | |
*/ | |
update_option( 'selection','custom' ); | |
update_option( 'permalink_structure','/%postname%/' ); | |
$wp_rewrite->init(); | |
$wp_rewrite->flush_rules(); | |
/** | |
* Create Self as Admin User. | |
*/ | |
$username = 'jeherve'; | |
$userdata = array( | |
'user_login' => $username, | |
'user_pass' => wp_generate_password(), | |
'user_email' => 'jeremy@jeremy.hu', | |
'first_name' => 'Jeremy', | |
'last_name' => 'Herve', | |
'nickname' => 'Jeremy', | |
'display_name' => 'Jeremy', | |
'user_url' => 'http://jeremy.hu/', | |
'role' => 'administrator' | |
); | |
$self_id = username_exists( $username ); | |
if ( ! $self_id ) { | |
$self_id = wp_insert_user( $userdata ); | |
update_user_option( $self_id, 'default_password_nag', true, true ); | |
} | |
// Delete the default post | |
wp_delete_post( 1, true ); | |
/** | |
* Create a new contact page | |
*/ | |
// First post | |
$now = current_time( 'mysql' ); | |
$now_gmt = current_time( 'mysql', 1 ); | |
$first_post_guid = get_option( 'home' ) . '/?p=1'; | |
if ( is_multisite() ) { | |
$first_post = get_site_option( 'first_post' ); | |
if ( empty( $first_post ) ) | |
$first_post = __( "[contact-form][contact-field label='Name' type='name' required='1'/][contact-field label='Email' type='email' required='1'/][contact-field label='Website' type='url'/][contact-field label='Comment' type='textarea' required='1'/][/contact-form]" ); | |
$first_post = str_replace( "SITE_URL", esc_url( network_home_url() ), $first_post ); | |
$first_post = str_replace( "SITE_NAME", get_current_site()->site_name, $first_post ); | |
} else { | |
$first_post = __("[contact-form][contact-field label='Name' type='name' required='1'/][contact-field label='Email' type='email' required='1'/][contact-field label='Website' type='url'/][contact-field label='Comment' type='textarea' required='1'/][/contact-form]"); | |
} | |
$wpdb->insert( $wpdb->posts, array( | |
'post_author' => $user_id, | |
'post_date' => $now, | |
'post_date_gmt' => $now_gmt, | |
'post_content' => $first_post, | |
'post_excerpt' => '', | |
'post_title' => __('Contact Us'), | |
/* translators: Default post slug */ | |
'post_name' => sanitize_title( _x('contact', 'Default post slug') ), | |
'post_type' => 'page', | |
'post_modified' => $now, | |
'post_modified_gmt' => $now_gmt, | |
'guid' => $first_post_guid, | |
'comment_count' => 1, | |
'to_ping' => '', | |
'pinged' => '', | |
'post_content_filtered' => '' | |
)); | |
$wpdb->insert( $wpdb->term_relationships, array('term_taxonomy_id' => $cat_tt_id, 'object_id' => 1) ); | |
/** | |
* Switch to our favorite theme, Goran, a child theme of Edin. | |
* | |
* First parameter is the template, second is the stylesheet. | |
*/ | |
switch_theme( 'edin', 'goran' ); | |
/** | |
* Enable your favourite plugins. | |
*/ | |
require_once( ABSPATH . 'wp-admin/includes/plugin.php' ); | |
// Your plugin list. These files should be found in your Plugins directory. You could store them as Git submodules for example. | |
$plugin_list = array( | |
'akismet/akismet.php', | |
'jeherve-func/jeherve-func.php', | |
'jetpack/jetpack.php', | |
'vaultpress/vaultpress.php' | |
); | |
// Enable each one of them | |
foreach( $plugin_list as $plugin ) { | |
$plugin_dir = WP_PLUGIN_DIR . "/{$plugin}"; | |
if ( file_exists( $plugin_dir ) && !is_plugin_active( $plugin ) ) { | |
activate_plugin( $plugin ); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment