setup_actions();
}
/**
* Setup the admin hooks, actions and filters
*
* @since 2.0.0 bbPress (r2646)
*
* @access private
*/
function setup_actions() {
// Bail if in network admin
if ( is_network_admin() ) {
return;
}
// User profile edit/display actions
add_action( 'edit_user_profile', array( $this, 'secondary_role_display' ) );
// WordPress user screen
// Remove the bottom list table "change forum role" dropdown from WordPress < 4.6.
// See https://bbpress.trac.wordpress.org/ticket/2906.
if ( bbp_get_major_wp_version() < 4.6 ) {
add_action( 'restrict_manage_users', array( __CLASS__, 'user_role_bulk_dropdown' ) );
} else {
add_action( 'restrict_manage_users', array( $this, 'user_role_bulk_dropdown' ), 10, 1 );
}
add_filter( 'manage_users_columns', array( $this, 'user_role_column' ), 10, 1 );
add_filter( 'manage_users_custom_column', array( $this, 'user_role_row' ), 10, 3 );
// Only list bbPress roles under Forum Role, remove from WordPress' > 4.4 Site Role list.
if ( bbp_get_major_wp_version() >= 4.4 ) {
add_filter( 'get_role_list', array( $this, 'user_role_list_filter' ), 10, 2 );
}
// User List Table
add_action( 'load-users.php', array( $this, 'user_role_bulk_change' ), 10, 1 );
add_action( 'user_row_actions', array( $this, 'user_row_actions' ), 10, 2 );
}
/**
* Default interface for setting a forum role
*
* @since 2.2.0 bbPress (r4285)
*
* @param WP_User $profileuser User data
* @return bool Always false
*/
public static function secondary_role_display( $profileuser ) {
// Bail if current user cannot edit users
if ( ! current_user_can( 'edit_user', $profileuser->ID ) ) {
return;
}
// Get the roles
$dynamic_roles = bbp_get_dynamic_roles();
// Only keymasters can set other keymasters
if ( ! bbp_is_user_keymaster() ) {
unset( $dynamic_roles[ bbp_get_keymaster_role() ] );
} ?>
ID ); ?>
ID ) ) . '" class="bbp-user-profile-link">' . esc_html__( 'View', 'bbpress' ) . '';
// Re-reverse
return array_reverse( $actions );
}
/**
* Add Forum Role column to the WordPress Users table, and change the
* core role title to "Site Role"
*
* @since 2.2.0 bbPress (r4337)
*
* @param array $columns Users table columns
* @return array $columns
*/
public static function user_role_column( $columns = array() ) {
// New title for old Role column
$columns['role'] = esc_html__( 'Site Role', 'bbpress' );
// New column
$bbp_user_role = array(
'bbp_user_role' => esc_html__( 'Forum Role', 'bbpress' )
);
// Make sure role columns are next to each other
$role_pos = array_search( 'role', array_keys( $columns ), true );
$result = array_slice( $columns, 0, $role_pos + 1 );
$result = array_merge( $result, $bbp_user_role );
// Merge and return
return array_merge( $result, array_slice( $columns, $role_pos ) );
}
/**
* Return user's forums role for display in the WordPress Users list table
*
* @since 2.2.0 bbPress (r4337)
*
* @param string $retval
* @param string $column_name
* @param int $user_id
*
* @return string Displayable bbPress user role
*/
public static function user_role_row( $retval = '', $column_name = '', $user_id = 0 ) {
// User role column
if ( 'bbp_user_role' === $column_name ) {
// Get the users role
$user_role = bbp_get_user_role( $user_id );
$retval = false;
// Translate user role for display
if ( ! empty( $user_role ) ) {
$roles = bbp_get_dynamic_roles();
$retval = bbp_translate_user_role( $roles[ $user_role ]['name'] );
}
}
// Pass retval through
return $retval;
}
/**
* Filter the list of roles included in the WordPress site role list
*
* Ensures forum roles are only displayed under the Forum Role list in the
* WordPress Users list table
*
* @since 2.6.0 bbPress (r6051)
*
* @return array $roles
*/
public static function user_role_list_filter( $roles, $user ) {
// Get the users role
$user_role = bbp_get_user_role( $user->ID );
if ( ! empty( $user_role ) ) {
unset( $roles[ $user_role ] );
}
return $roles;
}
}
new BBP_Users_Admin();
endif; // class exists