Created
April 13, 2013 23:49
-
-
Save ninnypants/5380655 to your computer and use it in GitHub Desktop.
Sync all users to newly created blogs
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 | |
/* | |
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