Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Last Months Leaderboard
- * @version 1.0
- */
- add_action( 'mycred_widgets_init', 'mycred_load_last_months_leaderboard_widget' );
- function mycred_load_last_months_leaderboard_widget() {
- if ( ! class_exists( 'myCRED_Widget_Last_Months_Leaderboard' ) ) {
- class myCRED_Widget_Last_Months_Leaderboard extends WP_Widget {
- // Constructor
- public function __construct() {
- parent::__construct(
- 'mycred_widget_last_months_leaderboard',
- sprintf( '(%s) Last Months Leaderboard', mycred_label() ),
- array(
- 'classname' => 'widget-mycred-last-months-leaderboard',
- 'description' => 'Shows last months points leaderboard.'
- )
- );
- }
- // Widget Output (what users see)
- public function widget( $args, $instance ) {
- extract( $args, EXTR_SKIP );
- // Load myCRED
- $mycred = mycred();
- echo $before_widget;
- // Title (if not empty)
- if ( ! empty( $instance['title'] ) )
- echo $before_title . $mycred->template_tags_general( $instance['title'] ) . $after_title;
- echo do_shortcode( '[mycred_leaderboard number=' . $instance['number'] . ' timeframe="last-month"]' );
- echo $after_widget;
- }
- // Widget Settings (when editing / setting up widget)
- public function form( $instance ) {
- $title = isset( $instance['title'] ) ? esc_attr( $instance['title'] ) : __( 'This Months Leaderboard', 'mycred' );
- $number = isset( $instance['number'] ) ? abs( $instance['number'] ) : 5;
- ?>
- <p class="myCRED-widget-field">
- <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title', 'mycred' ); ?>:</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>
- <p class="myCRED-widget-field">
- <label for="<?php echo esc_attr( $this->get_field_id( 'number' ) ); ?>"><?php _e( 'Number of users', 'mycred' ); ?>:</label>
- <input id="<?php echo esc_attr( $this->get_field_id( 'number' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'number' ) ); ?>" type="text" value="<?php echo $number; ?>" size="3" class="align-right" />
- </p>
- <?php
- }
- // Save Widget Settings
- public function update( $new_instance, $old_instance ) {
- $instance = $old_instance;
- $instance['number'] = absint( $new_instance['number'] );
- $instance['title'] = sanitize_text_field( $new_instance['title'] );
- return $instance;
- }
- }
- register_widget( 'myCRED_Widget_Last_Months_Leaderboard' );
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement