AnsPress_Leaderboard_Widget::widget( array $args, array $instance )
Description #
Widget render method.
Parameters #
- $argsarray (Required) Widget arguments.
- $instancearray (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'] ); }
Expand full source code Collapse full source code View on GitHub: widgets/leaderboard.php:76
Add your comment