AnsPress_Leaderboard_Widget::widget( array $args, array $instance )

Description #

Widget render method.

Parameters #

  • $args
    array (Required) Widget arguments.
  • $instance
    array (Required) Widget instance.

Source #

File: widgets/leaderboard.php

	public function widget( $args, $instance ) {
		$title         = ! empty( $instance['title'] ) ? $instance['title'] : '';
		$avatar_size   = ! empty( $instance['avatar_size'] ) ? $instance['avatar_size'] : 40;
		$show_users    = ! empty( $instance['show_users'] ) ? $instance['show_users'] : 12;
		$users_per_row = ! empty( $instance['users_per_row'] ) ? $instance['users_per_row'] : 4;
		$interval      = ! empty( $instance['interval'] ) ? $instance['interval'] : 30;

		/**
		 * Filters the widget title.
		 *
		 * @param string $title Widget title.
		 * @since 1.0.0
		 */
		$title = apply_filters( 'widget_title', $title );

		echo wp_kses_post( $args['before_widget'] );

		if ( ! empty( $title ) ) {
			echo wp_kses_post( $args['before_title'] . $title . $args['after_title'] );
		}

		echo '<div class="ap-widget-inner">';

		if ( ap_is_addon_active( 'reputation.php' ) ) {
			echo '<div class="ap-leaderbaord-widget">';

			$users = $this->get_top_users( $interval, $show_users );

			if ( empty( $users ) ) {
				esc_attr_e( 'No users found with reputation.', 'anspress-question-answer' );
			} else {
				foreach ( $users as $user ) {
					echo '<a href="' . esc_url( ap_user_link( $user->ID ) ) . '" class="ap-leaderbaord-user" style="width: ' . absint( 100 / $users_per_row ) . '%">';
					echo '<div class="ap-leaderbaord-user-img">';
					echo get_avatar( $user->ID, $avatar_size );
					echo '</div>';
					echo '<div class="ap-leaderbaord-user-name">';
					echo esc_html( $user->display_name );
					echo '<span class="ap-leaderbaord-point"><b>' . (int) $user->aggregated . '</b> ' . esc_attr__( 'Points', 'anspress-question-answer' ) . '</span>';
					echo '</div>';
					echo '</a>';
				}
			}

			echo '</div>';
		} else {
			esc_attr_e( 'Reputation add-on is not active.', 'anspress-question-answer' );
		}

		echo '</div>';

		echo wp_kses_post( $args['after_widget'] );
	}

Leave a Reply

Your email address will not be published.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Add your comment