Display all registered users that are non admin in a table. The table columns should include user ID, Display name publicly as , username, user role, website, Biographical Info, and email

WPTurbo » Snippets » Display all registered users that are non admin in a table. The table columns should include user ID, Display name publicly as , username, user role, website, Biographical Info, and email
0

Created with:

Visibility: 

public

Creator: Nick

Customize with WPTurbo AI
X

Add Snippet To Project

New Project
Add To Existing Project
					<?php
// Plugin Name: WP Plugin

// Function to display registered users in a table
function wpturbo_display_registered_users() {
    global $wpdb;

    // Get all non-admin users
    $users = get_users(array(
        'role__not_in' => array('administrator')
    ));

    // Check if any users found
    if (empty($users)) {
        echo 'No registered users found.';
        return;
    }

    // Table header
    echo '<table>';
    echo '<thead>';
    echo '<tr>';
    echo '<th>User ID</th>';
    echo '<th>Display Name</th>';
    echo '<th>Username</th>';
    echo '<th>User Role</th>';
    echo '<th>Website</th>';
    echo '<th>Biographical Info</th>';
    echo '<th>Email</th>';
    echo '</tr>';
    echo '</thead>';

    // Table body
    echo '<tbody>';
    foreach ($users as $user) {
        echo '<tr>';
        echo '<td>' . $user->ID . '</td>';
        echo '<td>' . $user->display_name . '</td>';
        echo '<td>' . $user->user_login . '</td>';
        echo '<td>' . implode(', ', $user->roles) . '</td>';
        echo '<td>' . $user->user_url . '</td>';
        echo '<td>' . $user->description . '</td>';
        echo '<td>' . $user->user_email . '</td>';
        echo '</tr>';
    }
    echo '</tbody>';

    echo '</table>';
}

// Display the registered users table
wpturbo_display_registered_users();
				

Explanation:

Register an account to save your snippets or go Pro to get more features.