Changeset 4365
- Timestamp:
- 11/09/2012 09:32:13 AM (12 years ago)
- Location:
- trunk/includes
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/includes/admin/users.php
r4352 r4365 51 51 52 52 // WordPress user screen 53 add_filter( 'manage_users_columns', array( $this, 'user_role_column' ) ); 54 add_filter( 'manage_users_custom_column', array( $this, 'user_role_row' ), 10, 3 ); 53 add_action( 'restrict_manage_users', array( $this, 'user_role_bulk_dropdown' ) ); 54 add_filter( 'manage_users_columns', array( $this, 'user_role_column' ) ); 55 add_filter( 'manage_users_custom_column', array( $this, 'user_role_row' ), 10, 3 ); 56 57 // Process bulk role change 58 add_action( 'load-users.php', array( $this, 'user_role_bulk_change' ) ); 55 59 } 56 60 … … 67 71 // Bail if current user cannot edit users 68 72 if ( ! current_user_can( 'edit_user', $profileuser->ID ) ) 69 return; ?> 73 return; 74 75 // Get the roles 76 $dynamic_roles = bbp_get_dynamic_roles(); 77 78 // Only keymasters can set other keymasters 79 if ( ! current_user_can( 'keep_gate' ) ) 80 unset( $dynamic_roles[ bbp_get_keymaster_role() ] ); ?> 70 81 71 82 <h3><?php _e( 'Forums', 'bbpress' ); ?></h3> … … 91 102 <?php endif; ?> 92 103 93 <?php foreach ( bbp_get_dynamic_roles()as $role => $details ) : ?>104 <?php foreach ( $dynamic_roles as $role => $details ) : ?> 94 105 95 106 <option <?php selected( $user_role, $role ); ?> value="<?php echo esc_attr( $role ); ?>"><?php echo translate_user_role( $details['name'] ); ?></option> … … 108 119 109 120 /** 121 * Add bulk forums role dropdown to the WordPress users table 122 * 123 * @since bbPress (r4360) 124 */ 125 public static function user_role_bulk_dropdown() { 126 127 // Bail if current user cannot promote users 128 if ( !current_user_can( 'promote_users' ) ) 129 return; 130 131 // Get the roles 132 $dynamic_roles = bbp_get_dynamic_roles(); 133 134 // Only keymasters can set other keymasters 135 if ( ! current_user_can( 'keep_gate' ) ) 136 unset( $dynamic_roles[ bbp_get_keymaster_role() ] ); ?> 137 138 <label class="screen-reader-text" for="bbp-new-role"><?php _e( 'Change forum role to…', 'bbpress' ) ?></label> 139 <select name="bbp-new-role" id="bbp-new-role" style="display:inline-block; float:none;"> 140 <option value=''><?php _e( 'Change forum role to…', 'bbpress' ) ?></option> 141 <?php foreach ( $dynamic_roles as $role => $details ) : ?> 142 143 <option value="<?php echo esc_attr( $role ); ?>"><?php echo translate_user_role( $details['name'] ); ?></option> 144 145 <?php endforeach; ?> 146 </select> 147 148 <?php submit_button( __( 'Change', 'bbpress' ), 'secondary', 'bbp-change-role', false ); 149 } 150 151 /** 152 * Process bulk dropdown form submission from the WordPress Users 153 * Table 154 * 155 * @uses current_user_can() to check for 'promote users' capability 156 * @uses bbp_get_dynamic_roles() to get forum roles 157 * @uses bbp_get_user_role() to get a user's current forums role 158 * @uses bbp_set_user_role() to set the user's new forums role 159 * @return bool Always false 160 */ 161 public function user_role_bulk_change() { 162 163 // Bail if current user cannot promote users 164 if ( !current_user_can( 'promote_users' ) ) 165 return; 166 167 // Bail if no users specified 168 if ( empty( $_REQUEST['users'] ) ) 169 return; 170 171 // Bail if this isn't a bbPress action 172 if ( empty( $_REQUEST['bbp-new-role'] ) || empty( $_REQUEST['bbp-change-role'] ) ) 173 return; 174 175 // Check that the new role exists 176 $dynamic_roles = bbp_get_dynamic_roles(); 177 if ( empty( $dynamic_roles[ $_REQUEST['bbp-new-role'] ] ) ) 178 return; 179 180 // Get the current user ID 181 $current_user_id = (int) bbp_get_current_user_id(); 182 183 // Run through user ids 184 foreach ( (array) $_REQUEST['users'] as $user_id ) { 185 $user_id = (int) $user_id; 186 187 // Don't let a user change their own role 188 if ( $user_id == $current_user_id ) 189 continue; 190 191 // Set up user and role data 192 $user_role = bbp_get_user_role( $user_id ); 193 $new_role = sanitize_text_field( $_REQUEST['bbp-new-role'] ); 194 195 // Only keymasters can set other keymasters 196 if ( in_array( bbp_get_keymaster_role(), array( $user_role, $new_role ) ) && ! current_user_can( 'keep_gate' ) ) 197 continue; 198 199 // Set the new forums role 200 if ( $new_role != $user_role ) { 201 bbp_set_user_role( $user_id, $new_role ); 202 } 203 } 204 } 205 206 /** 110 207 * Add Forum Role column to the WordPress Users table, and change the 111 208 * core role title to "Site Role" … … 118 215 public static function user_role_column( $columns = array() ) { 119 216 $columns['role'] = __( 'Site Role', 'bbpress' ); 120 217 $columns['bbp_user_role'] = __( 'Forum Role', 'bbpress' ); 121 218 122 219 return $columns; -
trunk/includes/users/template-tags.php
r4363 r4365 1004 1004 return; 1005 1005 1006 $user_role = bbp_get_user_role( bbp_get_displayed_user_id() ); ?> 1006 // Get the user's role 1007 $user_role = bbp_get_user_role( bbp_get_displayed_user_id() ); 1008 1009 // Get the roles 1010 $dynamic_roles = bbp_get_dynamic_roles(); 1011 1012 // Only keymasters can set other keymasters 1013 if ( ! current_user_can( 'keep_gate' ) ) 1014 unset( $dynamic_roles[ bbp_get_keymaster_role() ] ); ?> 1007 1015 1008 1016 <select name="bbp-forums-role" id="bbp-forums-role"> 1009 1017 <option value=""><?php _e( '— No role for this forum —', 'bbpress' ); ?></option> 1010 1018 1011 <?php foreach ( bbp_get_dynamic_roles()as $role => $details ) : ?>1019 <?php foreach ( $dynamic_roles as $role => $details ) : ?> 1012 1020 1013 1021 <option <?php selected( $user_role, $role ); ?> value="<?php echo esc_attr( $role ); ?>"><?php echo translate_user_role( $details['name'] ); ?></option>
Note: See TracChangeset
for help on using the changeset viewer.