Advertisement
designbymerovingi

Shortcode: Total Points Shortcode

Oct 20th, 2015
150
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.78 KB | None | 0 0
  1. /**
  2.  * Total Point Balances
  3.  * Returns the total point balance amongst all users for a
  4.  * specific point type.
  5.  * @version 1.0
  6.  */
  7. if ( ! function_exists( 'mycred_pro_all_points_shortcode' ) ) :
  8.     function mycred_pro_all_points_shortcode( $atts ) {
  9.  
  10.         if ( ! function_exists( 'mycred' ) ) return 0;
  11.  
  12.         extract( shortcode_atts( array(
  13.             'type' => 'mycred_default'
  14.         ), $atts ) );
  15.  
  16.         global $wpdb;
  17.  
  18.         if ( $type == '' )
  19.             $type = 'mycred_default';
  20.  
  21.         $mycred = mycred( $type );
  22.  
  23.         $total = $wpdb->get_var( $wpdb->prepare( "SELECT SUM( meta_value ) FROM {$wpdb->usermeta} WHERE meta_key = %s", $type ) );
  24.         if ( $total === NULL ) $total = 0;
  25.  
  26.         return $mycred->format_creds( $total );
  27.  
  28.     }
  29. endif;
  30. add_shortcode( 'mycred_total_points', 'mycred_pro_all_points_shortcode' );
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement