Skip to content

Instantly share code, notes, and snippets.

@JudeRosario
Last active August 29, 2015 14:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save JudeRosario/be5dfcfe63ce6e4c5d77 to your computer and use it in GitHub Desktop.
Save JudeRosario/be5dfcfe63ce6e4c5d77 to your computer and use it in GitHub Desktop.
New Blog Templates : Bulk update Template
include_once( WP_CONTENT_DIR . '/plugins/blogtemplates/nbt-api.php' );
nbt_load_api();
// Fires when a new blog is created
add_action( 'wpmu_new_blog', 'bulk_update_blogs', 99, 2 );
// Hook this function to a good place
function bulk_update_blogs( $new_blog_id, $new_user_id ) {
global $wpdb ;
// Keep what you need, delete the rest. Preserve data structure
$nbt_args = array(
'to_copy' => array(
'posts' => true,
'pages' => true,
'menus' => true,
'terms' => false,
'users' => false,
'menus' => false,
'files' => false
),
'pages_ids' => array( 'all-pages' ),
'post_category' => array( 'all-categories' ),
// Put NEW Template ID here
'template_id' => 0,
'block_posts_pages' => false,
'update_dates' => false
);
// Once Again keep what you need here and delete the rest.
$blog_args = array(
'network_id' => $wpdb->siteid,
'public' => null,
'archived' => null,
'mature' => null,
'spam' => null,
'deleted' => null,
'limit' => 100,
'offset' => 0,
);
$blogs = wp_get_sites( $blog_args ) ;
if(!empty($blogs)):
foreach ($blogs as $blog) {
// If you want to apply a template from one blog to another then modify method signature below
// nbt_api_copy_contents_to_new_blog( $old_blog_id, $new_blog_id, $new_user_id, $nbt_args );
nbt_api_copy_contents_to_new_blog( $blog['blog_id'] , $new_blog_id , $new_user_id , $nbt_args) ;
}
endif;
}
include_once( WP_CONTENT_DIR . '/plugins/blogtemplates/nbt-api.php' );
nbt_load_api();
// Fires when a new blog is created
add_action( 'wpmu_new_blog', 'bulk_update_blogs', 99, 2 );
// Hook this function to a good place
function bulk_update_blogs( $new_blog_id, $new_user_id ) {
global $wpdb ;
// Keep what you need, delete the rest. Preserve data structure
$nbt_args = array(
'to_copy' => array(
'posts' => false,
'pages' => false,
),
// Put NEW Template ID here
'template_id' => 0,
);
$blogs = wp_get_sites( ) ;
if(!empty($blogs)):
foreach ($blogs as $blog) {
nbt_api_copy_contents_to_new_blog( $blog['blog_id'] , $new_blog_id , $new_user_id , $nbt_args) ;
}
endif;
}
@espyd
Copy link

espyd commented Feb 9, 2015

Hi Jude. This is Gina from WPMU DEV. Could I commission you to do this for me?

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