$role__in,
'fields' => 'all',
'orderby' => 'display_name',
) );
$users = $users_query->get_results();
if ( is_array($users) && ! empty($users) ) {
echo '
';
$rowodd = false;
foreach ( $users as $user ) {
if ($user === FALSE) {
// Invalid $user_id
continue;
}
$class = '';
// rows have a different color.
if ($rowodd) {
$rowodd = false;
$class = ' alternate';
} else {
$rowodd = true;
$class = '';
} ?>
';
}
}
// Add the widget.
function auli_dashboard_setup() {
$user = wp_get_current_user(); // getting & setting the current user
$roles = (array) $user->roles;
$role__in = array(
'Administrator',
'Editor',
'Author',
);
/*
* Filters if the user has access to this widget based on his/her roles.
* Expects the name of a role with the first character capitalized.
*
* @since 1.0.5
*
* @param array $role__in Array with roles.
*/
$role__in = apply_filters( 'auli_show_for_role__in', $role__in );
$allowed_admin = false;
foreach ( $roles as $role ) {
$role = ucfirst( $role );
if ( in_array( $role, $role__in, true ) ) {
$allowed_admin = true;
break;
}
}
if ( $allowed_admin ) {
wp_add_dashboard_widget( 'auli_dashboard', esc_html__('Admin Users', 'admin-users-logged-in'), 'auli_dashboard' );
}
}
add_action( 'wp_dashboard_setup', 'auli_dashboard_setup' );
/*
* Save last login in user meta.
*
* @since 1.0.0
*/
function auli_admin_init() {
$user_id = get_current_user_id(); // returns 0 if no current user
$datetime = current_time( 'timestamp' );
update_user_meta( $user_id, 'auli_last', $datetime );
}
add_action( 'admin_init', 'auli_admin_init' );
/*
* Load Language files for dashboard only.
*
* @since 1.0.4
*/
function auli_load_lang() {
load_plugin_textdomain( 'admin-users-logged-in', false, plugin_basename( __DIR__ ) . '/lang' );
}
add_action( 'admin_init', 'auli_load_lang' );
display_name ) ) { echo esc_html( $user->display_name ); } else { echo esc_html( $user->user_login ); } ?>: ID, 'auli_last', true ); if ( $datetime ) { echo esc_html( date_i18n( get_option('date_format'), $datetime ) . ', ' . date_i18n( get_option('time_format'), $datetime ) ); } else { esc_html_e( 'Never logged in', 'admin-users-logged-in' ); } ?>