Skip to content

Instantly share code, notes, and snippets.

@mavieth
Created December 28, 2015 16:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mavieth/bf8affd8596ec5d027c9 to your computer and use it in GitHub Desktop.
Save mavieth/bf8affd8596ec5d027c9 to your computer and use it in GitHub Desktop.
<?php
/**
* Template Name: Sort User Table Page
*
* @package WordPress
*/
get_header();?>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.10/css/jquery.dataTables.min.css">
<?php
// Display whatever it is you want to show.
$blogusers = get_users( 'blog_id=1&orderby=nicename' );
// Array of WP_User objects.
$arr = array();
foreach ( $blogusers as $user ) {
$meta = get_user_meta($user->ID);
$link = get_edit_user_link( $user->ID);
$editUserLink = '<a href=' .$link. '>Edit User Profile</a>';
$profileArray =array(
"Display Name" => $user->display_name,
"Email Address" => $user->user_email,
"Edit User" => $editUserLink
);
array_push($arr, $profileArray);
}
// Adding headers and table data
if (count($arr) > 0): ?>
<div class="container">
<table id="example" class="order-column table table-striped">
<thead>
<tr>
<th><?php echo implode('</th><th>', array_keys(current($arr))); ?></th>
</tr>
</thead>
<tbody>
<?php foreach ($arr as $row): array_map('htmlentities', $row); ?>
<tr>
<td><?php echo implode('</td><td>', $row); ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
<footer>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script src='//maxcdn.bootstrapcdn.com/bootstrap/3.3.2/js/bootstrap.min.js'></script>
<script src="https://cdn.datatables.net/1.10.10/js/jquery.dataTables.min.js"></script>
<script>
$(document).ready(function() {
$('#example').DataTable();
} );
</script>
</footer>
<?php get_footer(); ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment