
­­­­­­­­­­­­­­­­­­
<!DOCTYPE html>
<html>
<?php

add_action( 'widgets_init', 'presso_widgets_init_authors' );
if ( ! function_exists( 'presso_widgets_init_authors' ) ) {
	function presso_widgets_init_authors() {
		register_widget( 'Presso__widget_author_list' );
	}
}

if ( ! class_exists( 'Presso__widget_author_list' ) ) {
	class Presso__widget_author_list extends WP_Widget {
		private $default = array(
			'supertitle' => '',
			'title' => '',
			'subtitle' => '',
			'count' => 8,
			'role' => '',
		);

		public function __construct() {
			// widget actual processes
			parent::__construct(
		 		'vw_widget_author_list', // Base ID
				PRESSO_THEME_NAME.': Author List', // Name
				array( 'description' => esc_html__( 'Display authors', 'presso' ) ) // Args
			);
		}

		function widget( $args, $instance ) {
			global $wp_roles;
			extract($args);

			$instance['supertitle'] = apply_filters( 'wpml_translate_single_string', $instance['supertitle'], 'Widgets', $this->id.'_supertitle' );
			$instance['title'] = apply_filters( 'widget_title', $instance['title'], $instance, $this->id_base );
			$instance['subtitle'] = apply_filters( 'wpml_translate_single_string', $instance['subtitle'], 'Widgets', $this->id.'_subtitle' );

			$supertitle_html = '';
			if ( ! empty( $instance['supertitle'] ) ) {
				$supertitle_html = '<span class="vw-super-title">'.wp_kses_post( $instance['supertitle'] ).'</span>';
			}

			$title_html = '';
			if ( ! empty( $instance['title'] ) ) {
				$title_html = wp_kses_post( $instance['title'] );
			}

			$subtitle_html = '';
			if ( ! empty( $instance['subtitle'] ) ) {
				$subtitle_html = '<span class="vwspc-section-subtitle">'.wp_kses_post( $instance['subtitle'] ).'</span>';
			}

			echo wp_kses_post( $before_widget );
			if ( $instance['title'] ) echo wp_kses_post( $supertitle_html . $before_title . $title_html . $after_title . $subtitle_html );

			$authors = get_users( apply_filters( 'presso_filter_widget_author_list_args', array(
				'role' => $instance['role'],
				'order' => 'DESC',
				'orderby' => 'post_count',
				'number' => intval( $instance['count'] ),
			) ) );

			echo '<ul class="clearfix vw-flex-grid vw-flex-grid--xxs-4 vw-flex-grid--small-gap">';
			foreach ( $authors as $author ) : ?>
				<li class="vw-flex-grid__item">
					<?php presso_the_avatar( $author, 70 ); ?>
				</li>
			<?php endforeach;
			echo '</ul>';

			wp_reset_postdata();
			echo wp_kses_post( $after_widget );
		}

		function update( $new_instance, $old_instance ) {
			$instance = $old_instance;
			$new_instance = wp_parse_args( (array) $new_instance, $this->default );
			$instance['supertitle'] = sanitize_text_field( $new_instance['supertitle'] );
			$instance['title'] = sanitize_text_field( $new_instance['title'] );
			$instance['subtitle'] = sanitize_text_field( $new_instance['subtitle'] );
			$instance['count'] = intval( $new_instance['count'] );
			$instance['role'] = sanitize_text_field( $new_instance['role'] );

			do_action( 'wpml_register_single_string', 'Widgets', $this->id.'_supertitle', $instance['supertitle'] );
			do_action( 'wpml_register_single_string', 'Widgets', $this->id.'_title', $instance['title'] );
			do_action( 'wpml_register_single_string', 'Widgets', $this->id.'_subtitle', $instance['subtitle'] );

			return $instance;
		}

		function form( $instance ) {
			global $wp_roles;

			$instance = wp_parse_args( (array) $instance, $this->default );

			$supertitle = $instance['supertitle'];
			$title = $instance['title'];
			$subtitle = $instance['subtitle'];
			$role = $instance['role'];
			$count = $instance['count'];
			?>

			<!-- supertitle -->
			<p>
				<label for="<?php echo esc_attr( $this->get_field_id('supertitle') ); ?>"><?php esc_html_e( 'Super-title:', 'presso' ); ?></label>
				<input class="widefat" id="<?php echo esc_attr( $this->get_field_id('supertitle') ); ?>" name="<?php echo esc_attr( $this->get_field_name('supertitle') ); ?>" type="text" value="<?php echo esc_attr($supertitle); ?>" />
			</p>

			<!-- title -->
			<p>
				<label for="<?php echo esc_attr( $this->get_field_id('title') ); ?>"><?php esc_html_e( 'Title:', 'presso' ); ?></label>
				<input class="widefat" id="<?php echo esc_attr( $this->get_field_id('title') ); ?>" name="<?php echo esc_attr( $this->get_field_name('title') ); ?>" type="text" value="<?php echo esc_attr($title); ?>" />
			</p>

			<!-- subtitle -->
			<p>
				<label for="<?php echo esc_attr( $this->get_field_id('subtitle') ); ?>"><?php esc_html_e( 'Subtitle:', 'presso' ); ?></label>
				<input class="widefat" id="<?php echo esc_attr( $this->get_field_id('subtitle') ); ?>" name="<?php echo esc_attr( $this->get_field_name('subtitle') ); ?>" type="text" value="<?php echo esc_attr($subtitle); ?>" />
			</p>

			<!-- role -->
			<p>
				<label for="<?php echo esc_attr( $this->get_field_id('role') ); ?>"><?php esc_html_e( 'Author Role:', 'presso' ); ?></label>
				<select id="<?php echo esc_attr( $this->get_field_id('role') ); ?>" name="<?php echo esc_attr( $this->get_field_name('role') ); ?>">
					<option value="">All</option>
					<?php foreach ( $wp_roles->roles as $slug => $role_data ) : ?>
					<option value="<?php echo esc_attr( $slug ); ?>" <?php selected( $role, $slug ); ?>><?php echo esc_html( $role_data['name'] ); ?></option>
				<?php endforeach; ?>
				</select>
			</p>

			<!-- count -->
			<p>
				<label for="<?php echo esc_attr( $this->get_field_id('count') ); ?>">Number of authors to show:</label>
				<input id="<?php echo esc_attr( $this->get_field_id('count') ); ?>" name="<?php echo esc_attr( $this->get_field_name('count') ); ?>" type="text" value="<?php echo esc_attr( $count ); ?>" size="3">
			</p>

			<?php
		}
	}
}