Skip to content

Instantly share code, notes, and snippets.

@nikitasinelnikov
Created October 14, 2024 10:48
Show Gist options
  • Save nikitasinelnikov/f049b5f911554586ff06633e9639da4c to your computer and use it in GitHub Desktop.
Save nikitasinelnikov/f049b5f911554586ff06633e9639da4c to your computer and use it in GitHub Desktop.
Ultimate Member >= 2.8.7. Add list table views instead of filter dropdown
function um_custom_add_status_links( $views ) {
remove_filter( 'pre_user_query', array( UM()->admin()->users_columns(), 'filter_users_by_status' ) );
$old_views = $views;
$views = array();
if ( ! isset( $_REQUEST['role'] ) && ! isset( $_REQUEST['um_user_status'] ) ) {
$views['all'] = '<a href="' . admin_url( 'users.php' ) . '" class="current">' . __( 'All', 'ultimate-member' ) . ' <span class="count">(' . UM()->query()->count_users() . ')</span></a>';
} else {
$views['all'] = '<a href="' . admin_url( 'users.php' ) . '">' . __( 'All', 'ultimate-member' ) . ' <span class="count">(' . UM()->query()->count_users() . ')</span></a>';
}
$status = array(
'approved' => __( 'Approved', 'ultimate-member' ),
'awaiting_admin_review' => __( 'Pending review', 'ultimate-member' ),
'awaiting_email_confirmation' => __( 'Waiting email confirmation', 'ultimate-member' ),
'inactive' => __( 'Inactive', 'ultimate-member' ),
'rejected' => __( 'Rejected', 'ultimate-member' ),
);
// set default statuses if not already done
UM()->setup()->set_default_user_status();
foreach ( $status as $k => $v ) {
if ( isset( $_REQUEST['um_user_status'] ) && sanitize_key( $_REQUEST['um_user_status'] ) === $k ) {
$current = 'class="current"';
} else {
$current = '';
}
$views[ $k ] = '<a href="' . esc_url( admin_url( 'users.php' ) . '?um_user_status=' . $k ) . '" ' . $current . '>' . $v . ' <span class="count">(' . UM()->query()->count_users_by_status( $k ) . ')</span></a>';
}
$views = apply_filters( 'um_admin_views_users', $views );
// remove all filters
unset( $old_views['all'] );
// add separator
$views['subsep'] = '<span></span>';
// merge views
foreach ( $old_views as $key => $view ) {
$views[ $key ] = $view;
}
// hide filters with not accessible roles
if ( ! current_user_can( 'administrator' ) ) {
$wp_roles = wp_roles();
$can_view_roles = um_user( 'can_view_roles' );
if ( ! empty( $can_view_roles ) ) {
foreach ( $wp_roles->get_names() as $this_role => $name ) {
if ( ! in_array( $this_role, $can_view_roles, true ) ) {
unset( $views[ $this_role ] );
}
}
}
}
return $views;
}
add_filter( 'views_users', 'um_custom_add_status_links' );
remove_action( 'manage_users_extra_tablenav', array( UM()->admin()->users_columns(), 'add_status_filter' ) );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment