'users',
'description' => esc_html__( 'Provides the ability to list the users of the site.', 'members' )
);
/* Set up the widget control options. */
$control_options = array(
'width' => 525,
'height' => 350,
'id_base' => 'members-widget-users'
);
/* Create the widget. */
$this->WP_Widget( 'members-widget-users', esc_attr__( 'Users', 'members' ), $widget_options, $control_options );
}
/**
* Outputs the widget based on the arguments input through the widget controls.
*
* @since 0.1.0
*/
function widget( $args, $instance ) {
extract( $args, EXTR_SKIP );
/* Set up the arguments for get_users(). */
$args = array(
'role' => $instance['role'],
'meta_key' => $instance['meta_key'],
'meta_value' => $instance['meta_value'],
'include' => ( !empty( $instance['include'] ) ? explode( ',', $instance['include'] ) : '' ),
'exclude' => ( !empty( $instance['exclude'] ) ? explode( ',', $instance['exclude'] ) : '' ),
'search' => $instance['search'],
'orderby' => $instance['orderby'],
'order' => $instance['order'],
'offset' => ( !empty( $instance['offset'] ) ? intval( $instance['offset'] ) : '' ),
'number' => ( !empty( $instance['number'] ) ? intval( $instance['number'] ) : '' ),
);
/* Output the theme's $before_widget wrapper. */
echo $before_widget;
/* If a title was input by the user, display it. */
if ( !empty( $instance['title'] ) )
echo $before_title . apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base ) . $after_title;
/* Get users. */
$users = get_users( $args );
/* If users were found. */
if ( !empty( $users ) ) {
echo '
';
/* Loop through each available user, creating a list item with a link to the user's archive. */
foreach ( $users as $user ) {
$url = get_author_posts_url( $user->ID, $user->user_nicename );
$class = "user-{$user->ID}";
if ( is_author( $user->ID ) )
$class .= ' current-user';
echo "- {$user->display_name}
\n";
}
echo '
';
}
/* Close the theme's widget wrapper. */
echo $after_widget;
}
/**
* Updates the widget control options for the particular instance of the widget.
*
* @since 0.1.0
*/
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags( $new_instance['title'] );
$instance['order'] = strip_tags( $new_instance['order'] );
$instance['orderby'] = strip_tags( $new_instance['orderby'] );
$instance['number'] = strip_tags( $new_instance['number'] );
$instance['offset'] = strip_tags( $new_instance['offset'] );
$instance['meta_key'] = strip_tags( $new_instance['meta_key'] );
$instance['meta_value'] = strip_tags( $new_instance['meta_value'] );
$instance['role'] = strip_tags( $new_instance['role'] );
$instance['include'] = strip_tags( $new_instance['include'] );
$instance['exclude'] = strip_tags( $new_instance['exclude'] );
$instance['search'] = strip_tags( $new_instance['search'] );
return $instance;
}
/**
* Displays the widget control options in the Widgets admin screen.
*
* @since 0.1.0
*/
function form( $instance ) {
global $wp_roles;
/* Set up the default form values. */
$defaults = array(
'title' => esc_attr__( 'Users', 'members' ),
'order' => 'ASC',
'orderby' => 'login',
'role' => '',
'meta_key' => '',
'meta_value' => '',
'include' => '',
'exclude' => '',
'search' => '',
'offset' => '',
'number' => ''
);
/* Merge the user-selected arguments with the defaults. */
$instance = wp_parse_args( (array) $instance, $defaults );
$order = array( 'ASC' => esc_attr__( 'Ascending', 'members' ), 'DESC' => esc_attr__( 'Descending', 'members' ) );
$orderby = array( 'display_name' => esc_attr__( 'Display Name', 'members' ), 'email' => esc_attr__( 'Email', 'members' ), 'ID' => esc_attr__( 'ID', 'members' ), 'nicename' => esc_attr__( 'Nice Name', 'members' ), 'post_count' => esc_attr__( 'Post Count', 'members' ), 'registered' => esc_attr__( 'Registered', 'members' ), 'url' => esc_attr__( 'URL', 'members' ), 'user_login' => esc_attr__( 'Login', 'members' ) );
$meta_key = array_merge( array( '' ), (array) members_get_user_meta_keys() );
$roles = array( '' => '' );
foreach ( $wp_roles->role_names as $role => $name )
$roles[$role] = $name;
?>