PluginProbe
bbPress / 2.6.6
bbPress v2.6.6
trunk 2.0 2.0-beta-1 2.0-beta-2b 2.0-beta-3 2.0-beta-3b 2.0-rc-2 2.0-rc-3 2.0-rc-4 2.0-rc-5 2.0.1 2.0.2 2.0.3 2.1 2.1-beta-1 2.1-rc1 2.1-rc2 2.1-rc3 2.1-rc4 2.1.1 2.1.2 2.1.3 2.2 2.2.1 2.2.2 All 71 releases
← All changes | includes/admin/users.php +156 -62 2.22.6.6 View file →
@@ -7,17 +7,17 @@
7 7 * @subpackage Administration
8 8 */
9 9
10 10 // Exit if accessed directly
11 -if ( !defined( 'ABSPATH' ) ) exit;
11 +defined( 'ABSPATH' ) || exit;
12 12
13 -if ( !class_exists( 'BBP_Users_Admin' ) ) :
13 +if ( ! class_exists( 'BBP_Users_Admin' ) ) :
14 14 /**
15 15 * Loads bbPress users admin area
16 16 *
17 17 * @package bbPress
18 18 * @subpackage Administration
19 - * @since bbPress (r2464)
19 + * @since 2.0.0 bbPress (r2464)
20 20 */
21 21 class BBP_Users_Admin {
22 22
23 23 /**
@@ -22,12 +22,9 @@
22 22
23 23 /**
24 24 * The bbPress users admin loader
25 25 *
26 - * @since bbPress (r2515)
27 - *
28 - * @uses BBP_Users_Admin::setup_globals() Setup the globals needed
29 - * @uses BBP_Users_Admin::setup_actions() Setup the hooks and actions
26 + * @since 2.0.0 bbPress (r2515)
30 27 */
31 28 public function __construct() {
32 29 $this->setup_actions();
33 30 }
@@ -34,35 +31,47 @@
34 31
35 32 /**
36 33 * Setup the admin hooks, actions and filters
37 34 *
38 - * @since bbPress (r2646)
35 + * @since 2.0.0 bbPress (r2646)
36 + *
39 37 * @access private
40 - *
41 - * @uses add_action() To add various actions
42 38 */
43 39 function setup_actions() {
44 40
45 41 // Bail if in network admin
46 - if ( is_network_admin() )
42 + if ( is_network_admin() ) {
47 43 return;
44 + }
48 45
49 46 // User profile edit/display actions
50 47 add_action( 'edit_user_profile', array( $this, 'secondary_role_display' ) );
51 48
52 49 // WordPress user screen
53 - add_action( 'restrict_manage_users', array( $this, 'user_role_bulk_dropdown' ) );
54 - add_filter( 'manage_users_columns', array( $this, 'user_role_column' ) );
50 + // Remvove the bottom list table "change forum role" dropdown from WordPress < 4.6.
51 + // See https://bbpress.trac.wordpress.org/ticket/2906.
52 + if ( bbp_get_major_wp_version() < 4.6 ) {
53 + add_action( 'restrict_manage_users', array( __CLASS__, 'user_role_bulk_dropdown' ) );
54 + } else {
55 + add_action( 'restrict_manage_users', array( $this, 'user_role_bulk_dropdown' ), 10, 1 );
56 + }
57 + add_filter( 'manage_users_columns', array( $this, 'user_role_column' ), 10, 1 );
55 58 add_filter( 'manage_users_custom_column', array( $this, 'user_role_row' ), 10, 3 );
56 59
57 - // Process bulk role change
58 - add_action( 'load-users.php', array( $this, 'user_role_bulk_change' ) );
60 + // Only list bbPress roles under Forum Role, remove from WordPress' > 4.4 Site Role list.
61 + if ( bbp_get_major_wp_version() >= 4.4 ) {
62 + add_filter( 'get_role_list', array( $this, 'user_role_list_filter' ), 10, 2 );
63 + }
64 +
65 + // User List Table
66 + add_action( 'load-users.php', array( $this, 'user_role_bulk_change' ), 10, 1 );
67 + add_action( 'user_row_actions', array( $this, 'user_row_actions' ), 10, 2 );
59 68 }
60 69
61 70 /**
62 71 * Default interface for setting a forum role
63 72 *
64 - * @since bbPress (r4285)
73 + * @since 2.2.0 bbPress (r4285)
65 74 *
66 75 * @param WP_User $profileuser User data
67 76 * @return bool Always false
68 77 */
@@ -68,24 +77,26 @@
68 77 */
69 78 public static function secondary_role_display( $profileuser ) {
70 79
71 80 // Bail if current user cannot edit users
72 - if ( ! current_user_can( 'edit_user', $profileuser->ID ) )
81 + if ( ! current_user_can( 'edit_user', $profileuser->ID ) ) {
73 82 return;
83 + }
74 84
75 85 // Get the roles
76 86 $dynamic_roles = bbp_get_dynamic_roles();
77 87
78 88 // Only keymasters can set other keymasters
79 - if ( ! current_user_can( 'keep_gate' ) )
80 - unset( $dynamic_roles[ bbp_get_keymaster_role() ] ); ?>
89 + if ( ! bbp_is_user_keymaster() ) {
90 + unset( $dynamic_roles[ bbp_get_keymaster_role() ] );
91 + } ?>
81 92
82 - <h3><?php _e( 'Forums', 'bbpress' ); ?></h3>
93 + <h2><?php esc_html_e( 'Forums', 'bbpress' ); ?></h2>
83 94
84 95 <table class="form-table">
85 96 <tbody>
86 97 <tr>
87 - <th><label for="bbp-forums-role"><?php _e( 'Forum Role', 'bbpress' ); ?></label></th>
98 + <th><label for="bbp-forums-role"><?php esc_html_e( 'Forum Role', 'bbpress' ); ?></label></th>
88 99 <td>
89 100
90 101 <?php $user_role = bbp_get_user_role( $profileuser->ID ); ?>
91 102
@@ -92,19 +103,19 @@
92 103 <select name="bbp-forums-role" id="bbp-forums-role">
93 104
94 105 <?php if ( ! empty( $user_role ) ) : ?>
95 106
96 - <option value=""><?php _e( '&mdash; No role for this forum &mdash;', 'bbpress' ); ?></option>
107 + <option value=""><?php esc_html_e( '&mdash; No role for these forums &mdash;', 'bbpress' ); ?></option>
97 108
98 109 <?php else : ?>
99 110
100 - <option value="" selected="selected"><?php _e( '&mdash; No role for this forum &mdash;', 'bbpress' ); ?></option>
111 + <option value="" selected="selected"><?php esc_html_e( '&mdash; No role for these forums &mdash;', 'bbpress' ); ?></option>
101 112
102 113 <?php endif; ?>
103 114
104 115 <?php foreach ( $dynamic_roles as $role => $details ) : ?>
105 116
106 - <option <?php selected( $user_role, $role ); ?> value="<?php echo esc_attr( $role ); ?>"><?php echo translate_user_role( $details['name'] ); ?></option>
117 + <option <?php selected( $user_role, $role ); ?> value="<?php echo esc_attr( $role ); ?>"><?php echo bbp_translate_user_role( $details['name'] ); ?></option>
107 118
108 119 <?php endforeach; ?>
109 120
110 121 </select>
@@ -119,34 +130,47 @@
119 130
120 131 /**
121 132 * Add bulk forums role dropdown to the WordPress users table
122 133 *
123 - * @since bbPress (r4360)
134 + * @since 2.2.0 bbPress (r4360)
135 + * @since 2.6.0 bbPress (r6055) Introduced the `$which` parameter.
136 + *
137 + * @param string $which The location of the extra table nav markup: 'top' or 'bottom'.
124 138 */
125 - public static function user_role_bulk_dropdown() {
139 + public static function user_role_bulk_dropdown( $which ) {
126 140
127 - // Bail if current user cannot promote users
128 - if ( !current_user_can( 'promote_users' ) )
141 + // Remove the bottom list table "change forum role" dropdown from WordPress < 4.6.
142 + // See https://bbpress.trac.wordpress.org/ticket/2906.
143 + if ( bbp_get_major_wp_version() < 4.6 ) {
144 + remove_action( 'restrict_manage_users', array( __CLASS__, 'user_role_bulk_dropdown' ) );
145 + }
146 +
147 + // Bail if current user cannot promote users
148 + if ( ! current_user_can( 'promote_users' ) ) {
129 149 return;
150 + }
130 151
131 152 // Get the roles
132 153 $dynamic_roles = bbp_get_dynamic_roles();
133 154
134 155 // Only keymasters can set other keymasters
135 - if ( ! current_user_can( 'keep_gate' ) )
136 - unset( $dynamic_roles[ bbp_get_keymaster_role() ] ); ?>
156 + if ( ! bbp_is_user_keymaster() ) {
157 + unset( $dynamic_roles[ bbp_get_keymaster_role() ] );
158 + }
137 159
138 - <label class="screen-reader-text" for="bbp-new-role"><?php _e( 'Change forum role to&hellip;', '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&hellip;', 'bbpress' ) ?></option>
160 + $select_id = 'bottom' === $which ? 'bbp-new-role2' : 'bbp-new-role';
161 + $button_id = 'bottom' === $which ? 'bbp-change-role2' : 'bbp-change-role';
162 + ?>
163 +
164 + <label class="screen-reader-text" for="<?php echo $select_id; ?>"><?php esc_html_e( 'Change forum role to&hellip;', 'bbpress' ) ?></label>
165 + <select name="<?php echo $select_id; ?>" id="<?php echo $select_id; ?>" style="display:inline-block; float:none;">
166 + <option value=''><?php esc_html_e( 'Change forum role to&hellip;', 'bbpress' ) ?></option>
141 167 <?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 -
168 + <option value="<?php echo esc_attr( $role ); ?>"><?php echo bbp_translate_user_role( $details['name'] ); ?></option>
145 169 <?php endforeach; ?>
146 - </select>
170 + </select><?php submit_button( esc_html__( 'Change', 'bbpress' ), 'secondary', $button_id, false );
147 171
148 - <?php submit_button( __( 'Change', 'bbpress' ), 'secondary', 'bbp-change-role', false );
172 + wp_nonce_field( 'bbp-bulk-users', 'bbp-bulk-users-nonce' );
149 173 }
150 174
151 175 /**
152 176 * Process bulk dropdown form submission from the WordPress Users
@@ -151,33 +175,45 @@
151 175 /**
152 176 * Process bulk dropdown form submission from the WordPress Users
153 177 * Table
154 178 *
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
179 + * @since 2.2.0 bbPress (r4365)
180 + *
159 181 * @return bool Always false
160 182 */
161 183 public function user_role_bulk_change() {
162 184
163 - // Bail if current user cannot promote users
164 - if ( !current_user_can( 'promote_users' ) )
165 - return;
166 -
167 185 // Bail if no users specified
168 - if ( empty( $_REQUEST['users'] ) )
186 + if ( empty( $_REQUEST['users'] ) ) {
169 187 return;
188 + }
170 189
171 190 // Bail if this isn't a bbPress action
172 - if ( empty( $_REQUEST['bbp-new-role'] ) || empty( $_REQUEST['bbp-change-role'] ) )
191 + if ( ( empty( $_REQUEST['bbp-new-role'] ) && empty( $_REQUEST['bbp-new-role2'] ) ) || ( empty( $_REQUEST['bbp-change-role'] ) && empty( $_REQUEST['bbp-change-role2'] ) ) ) {
173 192 return;
193 + }
174 194
195 + $new_role = false;
196 + if ( ! empty( $_REQUEST['bbp-change-role2'] ) && ! empty( $_REQUEST['bbp-new-role2'] ) ) {
197 + $new_role = $_REQUEST['bbp-new-role2'];
198 + } elseif ( ! empty( $_REQUEST['bbp-change-role'] ) && ! empty( $_REQUEST['bbp-new-role'] ) ) {
199 + $new_role = $_REQUEST['bbp-new-role'];
200 + }
201 +
175 202 // Check that the new role exists
176 203 $dynamic_roles = bbp_get_dynamic_roles();
177 - if ( empty( $dynamic_roles[ $_REQUEST['bbp-new-role'] ] ) )
204 + if ( ! $new_role || empty( $dynamic_roles[ $new_role ] ) ) {
178 205 return;
206 + }
179 207
208 + // Bail if nonce check fails
209 + check_admin_referer( 'bbp-bulk-users', 'bbp-bulk-users-nonce' );
210 +
211 + // Bail if current user cannot promote users
212 + if ( ! current_user_can( 'promote_users' ) ) {
213 + return;
214 + }
215 +
180 216 // Get the current user ID
181 217 $current_user_id = (int) bbp_get_current_user_id();
182 218
183 219 // Run through user ids
@@ -184,21 +220,23 @@
184 220 foreach ( (array) $_REQUEST['users'] as $user_id ) {
185 221 $user_id = (int) $user_id;
186 222
187 223 // Don't let a user change their own role
188 - if ( $user_id == $current_user_id )
224 + if ( $user_id === $current_user_id ) {
189 225 continue;
226 + }
190 227
191 228 // 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'] );
229 + $user_role = bbp_get_user_role( $user_id );
230 + $new_role = sanitize_text_field( $new_role );
194 231
195 232 // Only keymasters can set other keymasters
196 - if ( in_array( bbp_get_keymaster_role(), array( $user_role, $new_role ) ) && ! current_user_can( 'keep_gate' ) )
233 + if ( in_array( bbp_get_keymaster_role(), array( $user_role, $new_role ), true ) && ! bbp_is_user_keymaster() ) {
197 234 continue;
235 + }
198 236
199 237 // Set the new forums role
200 - if ( $new_role != $user_role ) {
238 + if ( $new_role !== $user_role ) {
201 239 bbp_set_user_role( $user_id, $new_role );
202 240 }
203 241 }
204 242 }
@@ -203,27 +241,61 @@
203 241 }
204 242 }
205 243
206 244 /**
245 + * Add a "View" link for each user
246 + *
247 + * @since 2.6.0 bbPress (r6502)
248 + *
249 + * @param array $actions
250 + * @param WP_User $user
251 + *
252 + * @return array Actions with 'view' link added to them
253 + */
254 + public function user_row_actions( $actions = array(), $user = false ) {
255 +
256 + // Reverse
257 + $actions = array_reverse( $actions );
258 +
259 + // Add the view action link
260 + $actions['view'] = '<a href="' . esc_url( bbp_get_user_profile_url( $user->ID ) ) . '" class="bbp-user-profile-link">' . esc_html__( 'View', 'bbpress' ) . '</a>';
261 +
262 + // Re-reverse
263 + return array_reverse( $actions );
264 + }
265 +
266 + /**
207 267 * Add Forum Role column to the WordPress Users table, and change the
208 268 * core role title to "Site Role"
209 269 *
210 - * @since bbPress (r4337)
270 + * @since 2.2.0 bbPress (r4337)
211 271 *
212 272 * @param array $columns Users table columns
213 273 * @return array $columns
214 274 */
215 275 public static function user_role_column( $columns = array() ) {
216 - $columns['role'] = __( 'Site Role', 'bbpress' );
217 - $columns['bbp_user_role'] = __( 'Forum Role', 'bbpress' );
218 276
219 - return $columns;
277 + // New title for old Role column
278 + $columns['role'] = esc_html__( 'Site Role', 'bbpress' );
279 +
280 + // New column
281 + $bbp_user_role = array(
282 + 'bbp_user_role' => esc_html__( 'Forum Role', 'bbpress' )
283 + );
284 +
285 + // Make sure role columns are next to each other
286 + $role_pos = array_search( 'role', array_keys( $columns ), true );
287 + $result = array_slice( $columns, 0, $role_pos + 1 );
288 + $result = array_merge( $result, $bbp_user_role );
289 +
290 + // Merge and return
291 + return array_merge( $result, array_slice( $columns, $role_pos ) );
220 292 }
221 293
222 294 /**
223 295 * Return user's forums role for display in the WordPress Users list table
224 296 *
225 - * @since bbPress (r4337)
297 + * @since 2.2.0 bbPress (r4337)
226 298 *
227 299 * @param string $retval
228 300 * @param string $column_name
229 301 * @param int $user_id
@@ -231,10 +303,10 @@
231 303 * @return string Displayable bbPress user role
232 304 */
233 305 public static function user_role_row( $retval = '', $column_name = '', $user_id = 0 ) {
234 306
235 - // Only looking for bbPress's user role column
236 - if ( 'bbp_user_role' == $column_name ) {
307 + // User role column
308 + if ( 'bbp_user_role' === $column_name ) {
237 309
238 310 // Get the users role
239 311 $user_role = bbp_get_user_role( $user_id );
240 312 $retval = false;
@@ -241,14 +313,36 @@
241 313
242 314 // Translate user role for display
243 315 if ( ! empty( $user_role ) ) {
244 316 $roles = bbp_get_dynamic_roles();
245 - $retval = translate_user_role( $roles[$user_role]['name'] );
317 + $retval = bbp_translate_user_role( $roles[ $user_role ]['name'] );
246 318 }
247 319 }
248 320
249 321 // Pass retval through
250 322 return $retval;
323 + }
324 +
325 + /**
326 + * Filter the list of roles included in the WordPress site role list
327 + *
328 + * Ensures forum roles are only displayed under the Forum Role list in the
329 + * WordPress Users list table
330 + *
331 + * @since 2.6.0 bbPress (r6051)
332 + *
333 + * @return array $roles
334 + */
335 + public static function user_role_list_filter( $roles, $user ) {
336 +
337 + // Get the users role
338 + $user_role = bbp_get_user_role( $user->ID );
339 +
340 + if ( ! empty( $user_role ) ) {
341 + unset( $roles[ $user_role ] );
342 + }
343 +
344 + return $roles;
251 345 }
252 346 }
253 347 new BBP_Users_Admin();
254 348 endif; // class exists