PluginProbe
Private groups / trunk
Private groups vtrunk
trunk 1.5 1.6 1.7 1.8 1.8.1 1.9.1 1.9.2 2.0 2.0.1 2.2 2.3 2.4 2.5 2.5.2 2.5.3 2.5.4 2.5.5 2.5.6 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 All 116 releases
bbp-private-groups / includes / user_management.php

user_management.php in Private groups trunk, at includes/user_management.php

359 lines 12.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3
4 //********************************************start of user management
5
6
7 function pg_user_management($group) {
8 //add the script for checkall ?>
9 <script type="text/javascript" language="javascript">// <![CDATA[
10 function checkAllPG(formname, checktoggle)
11 {
12 var checkboxes = new Array();
13 checkboxes = document[formname].getElementsByTagName('input');
14
15 for (var i=0; i<checkboxes.length; i++) {
16 if (checkboxes[i].type == 'checkbox') {
17 checkboxes[i].checked = checktoggle;
18 }
19 }
20 }
21 // ]]></script>
22 <?php
23
24 global $user_ID;
25 global $rpg_groups ;
26 global $rpg_disable_groups ;
27 global $wp_roles;
28 global $users ;
29
30 //from settings.php we enter this with $group = 'all' so unless changed it will show all users
31
32 //calls the set function to change bulk users to no-group
33 if ( $_POST && 'no-group' == $_POST['action'] && wp_verify_nonce( $_POST['confirm-bulk-action-nonce'], 'confirm-bulk-action' ) ) :
34 pg_no_group_users( $_POST['users'] );
35
36 //calls the set function to change bulk users to a specific group
37 elseif ( $_POST && 'group' == (substr($_POST['action'],0,5)) && wp_verify_nonce( $_POST['confirm-bulk-action-nonce'], 'confirm-bulk-action' )&& !empty($_POST['users']) ) :
38 pg_group_users( $_POST['users'] );
39
40 //then check if action 2 has a post, and if so extract the group from action 2 which will have filtergroupx
41 elseif ((!empty($_POST['action2'])) && 'filter' == (substr($_POST['action2'],0,6)) ) :
42 $group=substr($_POST['action2'],6,strlen($_POST['action2'])) ;
43 //now check if filter has been set for roles
44 elseif ((!empty($_POST['action3'])) && 'filter' !== (substr($_POST['action2'],0,6)) ) :
45 $group = 'role' ;
46 endif;
47
48 //WHICH USERS TO SHOW?
49
50 //if not been set, then $group will be 'all'
51 if ($group=='all') $users= get_users () ;
52
53 //if set to nogroup, then only show those
54 if ($group == 'nogroup') {
55 //take the opportunity to tidy the private group meta key
56 $users= get_users () ;
57 if ( $users ) {
58 foreach ( $users as $user ) {
59 $test = get_user_meta ($user->ID, 'private_group', true) ;
60 if (empty ($test)) {
61 delete_user_meta ($user->ID, 'private_group') ;
62 }
63 }
64 }
65 $users = get_users( array( 'meta_key' => 'private_group','meta_compare' => 'NOT EXISTS' )) ;
66 }
67
68
69 //if set to all groups, then don't show any without a group set
70 if ($group == 'allgroups') {
71 $users = get_users( array( 'meta_key' => 'private_group','meta_compare' => '!=', 'meta_value' => '' )) ;
72
73 }
74 //if a specific group, then only show that group
75 if (substr($group,0,5) =='group') {
76 $users1 = get_users( array( 'meta_key' => 'private_group', 'meta_value' => $group )) ;
77 $filtercheck='*'.$group.'*' ;
78 $users2 = get_users( array(
79 'meta_key' => 'private_group',
80 'meta_value' => '*'.$group.'*',
81 'meta_compare' => 'LIKE'
82 )
83 ) ;
84 $users=array_merge($users1,$users2);
85 }
86
87 //now check if filter has been set for roles
88 if ($group == 'role') {
89 $role = $_POST['action3'] ;
90 $users = get_users( array( 'meta_key' => 'wp_capabilities','meta_compare' => 'LIKE', 'meta_value' => $role )) ;
91 }
92 //adds the ability for an additional filter to change user display list
93 global $filter_check ;
94 do_action( 'pg_user_management_filter_results' );
95 if (!empty ($_POST['action4'] )) $users = $filter_check ;
96
97 ?>
98
99 <div class="icon32" id="icon-users"><br></div>
100 <p> <b>
101 <?php _e('Warning : The "bulk actions" CANNOT be used to set a multiple groups group against a user or users' , 'bbp-private-groups' ) ; ?></b> </p>
102 <p> <b>
103 <?php _e( 'Edit users at individual level if allocating multiple groups to users.' , 'bbp-private-groups' ) ; ?>
104 </b></p>
105
106
107 <form name="UserManagement" method="post">
108
109 <?php wp_nonce_field( 'confirm-bulk-action', 'confirm-bulk-action-nonce' ) ?>
110
111 <?php $number_of_users = count($users);
112 echo ' <b>Users in this selection : '.$number_of_users.'</b>' ; ?>
113
114 <div class="tablenav top">
115 <select name="action">
116 <option value=""><?php _e( 'Bulk Actions', 'bbp-private-groups' ); ?></option>
117 <option value="no-group"> <?php _e( 'No-Group', 'bbp-private-groups') ?></option>
118 <?php
119 //sets up the groups as actions
120 $count=count ($rpg_groups) ;
121 for ($i = 0 ; $i < $count ; ++$i) {
122 $g=$i+1 ;
123 $name="group".$g ;
124 $item=$name.' '.$rpg_groups[$name] ;
125 $display=__( 'Group', 'bbp-private-groups' ).$g.' '.$rpg_groups[$name] ;
126 if (empty ($rpg_disable_groups[$name] ) ) {
127 ?>
128 <option value="<?php echo $name ?>"><?php echo $display ?></option>
129 <?php
130 }
131 }
132 ?>
133 </select>
134 <input type="submit" value="<?php _e( 'Apply' , 'bbp-private-groups' ); ?>" class="button action doaction" name="">
135
136
137 <select name="action2">
138 <option value=""><?php _e( 'Filter user list by groups' , 'bbp-private-groups' ); ?></option>
139 <option value="filterallgroups"> <?php _e( 'All Groups' , 'bbp-private-groups') ?></option>
140 <option value="filternogroup"> <?php _e( 'No-Group-set' , 'bbp-private-groups' ) ?></option>
141 <?php
142 //sets up the groups as actions
143 for ($i = 0 ; $i < $count ; ++$i) {
144 $g=$i+1 ;
145 $name="group".$g ;
146 $name2="filtergroup".$g ;
147 $item=$name.' '.$rpg_groups[$name] ;
148 $display=__( 'Group', 'bbp-private-groups' ).$g.' '.$rpg_groups[$name] ;
149
150 ?>
151 <option value="<?php echo $name2 ?>"><?php echo $display ?></option>
152 <?php
153 }
154 ?>
155 </select>
156 <input type="submit" value="<?php _e( 'Filter' , 'bbp-private-groups' ); ?>" class="button action doaction" name="" >
157
158 <select name="action3">
159 <option value=""><?php _e( 'Filter user list by roles' , 'bbp-private-groups' ); ?></option>
160 <?php
161 //sets up the wordpress roles
162 $all_roles = $wp_roles->roles ;
163 foreach($all_roles as $role=>$value) {
164 $name = $value['name'] ;
165 ?>
166 <option value="<?php echo $role ?>"><?php echo $name ?></option>
167 <?php
168 }
169 ?>
170 </select>
171 <input type="submit" value="<?php _e( 'Filter' , 'bbp-private-groups' ); ?>" class="button action doaction" name="" >
172
173
174
175 <?php do_action( 'pg_user_management_filter' ); ?>
176
177
178
179
180
181
182 </div>
183
184 <table class="widefat">
185 <thead>
186 <tr>
187 <th id="cb-select-all-1">
188 <a onclick="javascript:checkAllPG('UserManagement', true);" href="javascript:void();">check all</a> |
189 <a onclick="javascript:checkAllPG('UserManagement', false);" href="javascript:void();">uncheck all</a>
190 </th>
191 <th id="gravatar"><?php _e( 'Gravatar', 'bbp-private-groups' ); ?></th>
192 <th id="display_name"><?php _e( 'Name', 'bbp-private-groups' ); ?></th>
193 <th id="private_group"><?php _e( 'Private Group(s)', 'bbp-private-groups' ); ?></th>
194 <?php do_action( 'pg_user_management_column_head' ); ?>
195 <th id="role"><?php _e( 'Wordpress & bbPress Roles', 'bbp-private-groups' ); ?></th>
196
197
198 </tr>
199 </thead>
200 <tbody>
201 <?php
202 if ( $users ) :
203 $i = 1;
204 foreach ( $users as $user ) :
205 $class = ( $i % 2 == 1 ) ? 'alternate' : 'default';
206 $user_data = get_userdata( $user->ID );
207 $user_registered = mysql2date(get_option('date_format'), $user->user_registered);
208 $private_group = get_user_meta($user->ID, 'private_group', true);
209 ?>
210 <tr id="user-<?php echo $user->ID ?>" class="<?php echo $class ?>">
211 <th>
212 <?php if ( $user->ID != $user_ID ) :?>
213 <input type="checkbox" name="users[]" value="<?php echo $user->ID ?>">
214 <?php endif; ?>
215 </th>
216 <td><img class="gravatar" src="http://www.gravatar.com/avatar/<?php echo md5( $user->user_email ) ?>?s=32"></td>
217 <td>
218 <a href="user-edit.php?user_id=<?php echo $user->ID ?>"><?php echo $user->display_name ?></a>
219 <div class="row-actions">
220 <?php if ( current_user_can( 'edit_user', $user->ID ) ) : ?>
221 <span class="edit"><a href="<?php echo admin_url( 'user-edit.php?user_id=' . $user->ID ) ?>"><?php _e( 'Edit', 'bbp-private-groups' ); ?></a>
222 <?php endif; ?>
223 <?php if ( current_user_can( 'edit_user', $user->ID ) && current_user_can( 'delete_user', $user->ID ) && $user_ID != $user->ID ) : ?>
224 &nbsp;|&nbsp;</span>
225 <?php endif; ?>
226 <?php if ( current_user_can( 'delete_user', $user->ID ) && $user_ID != $user->ID ) : ?>
227 <span class="delete"><a href="<?php echo admin_url( 'users.php?action=delete&user=' . $user->ID . '&_wpnonce=' . wp_create_nonce( 'bulk-users' ) ) ?>"><?php _e( 'Delete' ); ?></a></span>
228 <?php endif; ?>
229 </div>
230 </td>
231
232 <td><?php
233 //if no groups
234 if ($private_group == '') _e ('no group set', 'bbp-private-groups') ;
235 //if multiple groups
236 elseif (strpos($private_group, '*')!== FALSE) {
237 foreach ( $rpg_groups as $group => $details ) {
238 if (strpos($private_group, '*'.$group.'*') !== FALSE) {
239 $groupname=__('Group','bbp-private-groups').substr($group,5,strlen($group)) ;
240 echo $groupname." ".$details.'<br>' ;
241 }
242 }
243 }
244 //if only one group
245
246 else {
247 $groupname=__('Group','bbp-private-groups').substr($private_group,5,strlen($private_group)) ;
248 echo $groupname.' '.$rpg_groups[$private_group] ;
249 }
250 ?>
251 </td>
252 <?php
253 global $user_action_id ;
254 $user_action_id = $user->ID ;
255 do_action( 'pg_user_management_column_entry' );
256 ?>
257
258 <td>
259 <?php
260 if ( $user_data->roles ) :
261
262 foreach ( $user_data->roles as $role ) :
263 if ((substr($role,0,4)) == 'bbp_') $role = substr($role,4,strlen($role)) ;
264
265 echo _x( ucfirst( $role ), 'bbp-private-groups' ) . '<br>';
266
267 endforeach;
268
269 endif;
270 ?>
271 </td>
272
273
274 </tr>
275 <?php
276 $i++;
277 endforeach;
278
279 else :
280
281 ?>
282 <tr>
283 <td colspan="6"><strong><?php _e( 'No Users found', 'bbp-private-groups' ); ?></strong></td>
284 </tr>
285 <?php
286
287 endif;
288 ?>
289 </tbody>
290 </table>
291
292 </form>
293 <?php
294 }
295
296
297 /**
298 * Bulk no group users
299 * changes users to no-group
300 **/
301 function pg_no_group_users( array $user_ids ) {
302 $user = wp_get_current_user();
303 if ( $user_ids && current_user_can( 'edit_user', $user->ID ) ) :
304
305 foreach ( $user_ids as $user_id ) :
306
307 if ( is_numeric( $user_id ) ) :
308
309 delete_user_meta( $user_id, 'private_group' ) ;
310 //then update subscriptions
311 if (get_option( '_bbp_enable_subscriptions' )) rpg_amend_subscriptions ($user_id) ;
312 endif;
313
314 endforeach;
315
316 ?>
317 <div class="updated message">
318 <?php if ( 1 == count( $user_ids) ) : ?>
319 <p><?php _e( '1 user amended', 'bbp-private-groups' ) ?></p>
320 <?php else : ?>
321 <p><?php echo count( $user_ids ) . ' ' . __( 'users amended', 'bbp-private-groups' ) ?></p>
322 <?php endif; ?>
323 </div>
324 <?php
325
326 endif;
327 }
328
329 /**
330 * Bulk group users
331 * changes users to a group
332 **/
333 function pg_group_users( array $user_ids ) {
334 $user = wp_get_current_user();
335 if ( $user_ids && current_user_can( 'edit_user', $user->ID ) ) :
336
337 foreach ( $user_ids as $user_id ) :
338
339 if ( is_numeric( $user_id ) ) :
340
341 update_user_meta( $user_id, 'private_group', $_POST['action']);
342 //then update subscritions
343 if (get_option( '_bbp_enable_subscriptions' )) rpg_amend_subscriptions ($user_id) ;
344 endif;
345
346 endforeach;
347
348 ?>
349 <div class="updated message">
350 <?php if ( 1 == count( $user_ids) ) : ?>
351 <p><?php _e( '1 user amended', 'bbp-private-groups' ) ?></p>
352 <?php else : ?>
353 <p><?php echo count( $user_ids ) . ' ' . __( 'users amended', 'bbp-private-groups' ) ?></p>
354 <?php endif; ?>
355 </div>
356 <?php
357
358 endif;
359 }