-
Notifications
You must be signed in to change notification settings - Fork 0
/
user_adder.php
113 lines (89 loc) · 2.89 KB
/
user_adder.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
<?php
/**
* Plugin Name: User Adder
* Plugin URI: http://l2tmedia.com
* Description: This plugin will add a specific user to all sites
* Version: 1.0
* Author: Bryan Zawlocki
* Author URI: http://l2tmedia.com
* License: GPL2
*/
//Hook the Network Admin Menu
add_action('network_admin_menu', 'user_adder_admin_actions');
//add "User Adder" submenu to Super Admin Users tab and Init User Adder admin options page
function user_adder_admin_actions() {
add_submenu_page('users.php', 'User Adder', 'User Adder', 'manage_options', 'user-adder', 'user_adder_init');
}
//init Admin Options and Page
function user_adder_init() {
user_adder_page();
user_adder_options();
}
//Put Sites into an Array
function user_adder_options() {
$getSitesArgs = array(
'network_id' => $wpdb->siteid,
'public' => null,
'archived' => null,
'mature' => null,
'spam' => null,
'deleted' => null,
'limit' => 100,
'offset' => 0,
);
$theSites = wp_get_sites( $getSitesArgs );
foreach ($theSites as $key => $value) {
$theSiteIDs[] = $value['blog_id'];
}
return $theSiteIDs;
}
$theSiteIDs = user_adder_options();
//Get options for user dropdown
function user_adder_dropdown($args){
$dropdownUsersArgs = array(
'show_option_all' => null, // string
'show_option_none' => null, // string
'hide_if_only_one_author' => null, // string
'orderby' => 'display_name',
'order' => 'ASC',
'include' => null, // string
'exclude' => null, // string
'multi' => false,
'show' => 'user_login',
'echo' => true,
'selected' => false,
'include_selected' => false,
'name' => 'user', // string
'id' => null, // integer
'class' => null, // string
'blog_id' => all,
'who' => null // string
);
wp_dropdown_users($dropdownUsersArgs);
};
function user_adder_page(){?>
<div id="user_adder_options_page" class="wrap">
<h2>User Adder</h2>
<?php if(isset($_POST['submit'])){ echo 'user successfully added!';} ?>
<p>Choose a User to add to All Existing Sites</p>
<div id="user_adder_options_container">
<form method="POST" action="">
<?php user_adder_dropdown(); ?>
<input type="submit" name="submit" value="Add User" />
</form>
</div>
</div>
<?php
if(isset($_POST['submit'])){
$selected_user = $_POST['user'];
$theSiteIDs = user_adder_options();
echo 'it works';
add_new_user_to_all_blogs( $theSiteIDs, $selected_user);
}
}
function add_new_user_to_all_blogs($theSiteIDs, $user){
foreach ($theSiteIDs as $key => $sites) {
add_user_to_blog($sites, $user, 'administrator');
}
}
?>