Copy Settings From a Template Site to New Sites
Copies chosen options, such as Customizer settings, the site icon and reading settings, from a template site onto every new site.
Opens WPIDE on
Code
if ( ! is_multisite() ) {
return;
}
$wpide_template_id = 0; // Blog ID of the template site (0 = off until you set it).
$wpide_options = array( 'blogdescription', 'posts_per_page', 'date_format', 'time_format', 'timezone_string', 'permalink_structure', 'default_comment_status' );
add_action( 'wp_initialize_site', function ( $site ) use ( $wpide_template_id, $wpide_options ) {
if ( ! $wpide_template_id || (int) $site->blog_id === (int) $wpide_template_id || ! get_site( $wpide_template_id ) ) {
return;
}
switch_to_blog( $wpide_template_id );
$values = array();
foreach ( $wpide_options as $option ) {
$values[ $option ] = get_option( $option );
}
$stylesheet = get_option( 'stylesheet' );
$template = get_option( 'template' );
$mods = get_option( 'theme_mods_' . $stylesheet );
restore_current_blog();
switch_to_blog( $site->blog_id );
foreach ( $values as $option => $value ) {
if ( false !== $value ) {
update_option( $option, $value );
}
}
if ( $stylesheet && wp_get_theme( $stylesheet )->exists() ) {
update_option( 'template', $template );
update_option( 'stylesheet', $stylesheet );
if ( is_array( $mods ) ) {
unset( $mods['custom_logo'], $mods['nav_menu_locations'], $mods['custom_css_post_id'] );
update_option( 'theme_mods_' . $stylesheet, $mods );
}
}
delete_option( 'rewrite_rules' );
restore_current_blog();
}, 220 );
Notes
Set $wpide_template_id to the blog ID of your template site. Options that point to posts or media (like page_on_front) are not copied because IDs differ between sites.
How to add this snippet
- Install WPIDE on your WordPress site (it is free) and open Code Snippets.
- Use snippet above adds it from the library in one click. Or copy the code into a new snippet with the same code type.
- It is added inactive: review the code and settings, then switch it on.