List unapproved users shortcode

This function will make a shortcode you can use to list all unapproved users.

Shortcode:

[unapproved_users]

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
/*
 * List unapproved users shortcode.
 * Usage: [unapproved_users]
 */
 
add_shortcode( 'unapproved_users', 'wppbc_unapproved_users' );
function wppbc_unapproved_users( $atts, $content ){
	$term_id = get_term_by( 'slug', 'unapproved', 'user_status');
	$term_tax = 'user_status';
	$users = get_objects_in_term( $term_id->term_id, $term_tax );
 
	if ( !empty( $users ) ) {
		$list = '<ul class="user-entry">';
		foreach ( $users as $user_id ) {
			$user = get_user_by('id', $user_id);
			if ( $user ) {
				$list .= '<li>';
				$list .= get_avatar( get_the_author_meta( 'email', $user_id ), '30' );
				$list .= '<strong style="margin-left: 20px;">'. get_the_author_meta('display_name', $user_id) . '</strong>';
			}
		}
		$list .= '</ul>';
	}
	return $list;
}