Skip to content

Instantly share code, notes, and snippets.

@ninnypants
Created April 13, 2013 23:49
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ninnypants/5380655 to your computer and use it in GitHub Desktop.
Save ninnypants/5380655 to your computer and use it in GitHub Desktop.
Sync all users to newly created blogs
<?php
/*
Plugin Name: Sync Users
Plugin URI: http://ninnypants.com
Description: Sync users to new blogs as a subscriber
Version: 1.0
Author: ninnypants
Author URI: http://ninnypants.com
License: GPL2
Copyright 2013 Tyrel Kelsey (email : tyrel@ninnypants.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
class MS_Sync_Users {
public function __construct(){
add_action( 'wpmu_new_blog', array( $this, 'sync_users' ) );
}
public function sync_users( $blog_id ){
$users = get_users();
foreach( $users as $user ){
if( current_user_can( 'manage_network' ) )
add_user_to_blog( $blog_id, $user->ID, 'admin' );
else
add_user_to_blog( $blog_id, $user->ID, 'subscriber' );
}
}
}
$ms_sync_users = new MS_Sync_Users;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment