Last active
August 29, 2015 14:15
-
-
Save JudeRosario/be5dfcfe63ce6e4c5d77 to your computer and use it in GitHub Desktop.
New Blog Templates : Bulk update Template
This file contains hidden or 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
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; | |
} |
This file contains hidden or 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
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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi Jude. This is Gina from WPMU DEV. Could I commission you to do this for me?