Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Last Months Points Leaderboard
- * @version 1.2.1
- */
- if ( ! function_exists( 'mycred_pro_last_months_leaderboard' ) ) :
- function mycred_pro_last_months_leaderboard( $atts, $content = '' ) {
- extract( shortcode_atts( array(
- 'number' => 25,
- 'start' => '',
- 'end' => '',
- 'order' => 'DESC',
- 'type' => MYCRED_DEFAULT_TYPE_KEY,
- 'wrap' => 'li',
- 'template' => '#%position% %user_profile_link% %cred_f%',
- 'nothing' => 'Leaderboard is empty'
- ), $atts ) );
- if ( $type != '' && ! mycred_point_type_exists( $type ) )
- $type = MYCRED_DEFAULT_TYPE_KEY;
- if ( ! in_array( $order, array( 'ASC', 'DESC' ) ) )
- $order = 'DESC';
- global $wpdb;
- $mycred = mycred( $type );
- $wheres = array();
- if ( $type != '' )
- $wheres[] = $wpdb->prepare( "ctype = %s", $type );
- $wheres[] = $wpdb->prepare( "( time BETWEEN %d AND %d )", strtotime( $start ), strtotime( $end ) );
- $where = implode( ' AND ', $wheres );
- $limit = '';
- if ( $number > 0 ) $limit = $wpdb->prepare( "LIMIT 0,%d", $number );
- $leaderboard = $wpdb->get_results( "SELECT DISTINCT user_id AS ID, SUM( creds ) AS cred FROM {$mycred->log_table} WHERE {$where} GROUP BY user_id ORDER BY cred {$order} {$limit};", 'ARRAY_A' );
- $output = '';
- $in_list = false;
- $current_user = wp_get_current_user();
- if ( ! empty( $leaderboard ) ) {
- // Wrapper
- if ( $wrap == 'li' )
- $output .= '<ol class="myCRED-leaderboard list-unstyled">';
- // Loop
- foreach ( $leaderboard as $position => $user ) {
- // Prep
- $class = array();
- // Classes
- $class[] = 'item-' . $position;
- if ( $position == 0 )
- $class[] = 'first-item';
- if ( isset( $current_user->ID ) && $user['ID'] == $current_user->ID )
- $class[] = 'current-user';
- if ( $position % 2 != 0 )
- $class[] = 'alt';
- $row_template = $template;
- if ( ! empty( $content ) )
- $row_template = $content;
- // Template Tags
- $layout = str_replace( array( '%ranking%', '%position%' ), $position+1, $row_template );
- $layout = $mycred->template_tags_amount( $layout, $user['cred'] );
- $layout = $mycred->template_tags_user( $layout, $user['ID'] );
- // Wrapper
- if ( ! empty( $wrap ) )
- $layout = '<' . $wrap . ' class="%classes%">' . $layout . '</' . $wrap . '>';
- $layout = str_replace( '%classes%', apply_filters( 'mycred_ranking_classes', implode( ' ', $class ) ), $layout );
- $layout = apply_filters( 'mycred_ranking_row', $layout, $template, $user, $position+1 );
- $output .= $layout . "\n";
- }
- if ( $wrap == 'li' )
- $output .= '</ol>';
- }
- // No result template is set
- else {
- $output .= '<p class="mycred-leaderboard-none">' . $nothing . '</p>';
- }
- return $output;
- }
- endif;
- function mycred_pro_load_custom_shortcode() {
- add_shortcode( 'last_months_leaderboard', 'mycred_pro_last_months_leaderboard' );
- }
- add_action( 'mycred_init', 'mycred_pro_load_custom_shortcode' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement