Advertisement
designbymerovingi

Buy More Points Link Shortcode

Aug 22nd, 2014
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.73 KB | None | 0 0
  1. add_shortcode( 'mycred_buy_points_link', 'mycred_render_buy_points_link' );
  2. function mycred_render_buy_points_link( $atts ) {
  3.  
  4.     if ( ! is_user_logged_in() || ! function_exists( 'mycred' ) ) return '';
  5.  
  6.     $atts = shortcode_atts( array(
  7.         'ctype'   => 'mycred_default',
  8.         'balance' => 1,
  9.         'title'   => 'Buy More Points',
  10.         'url'     => ''
  11.     ), $atts );
  12.  
  13.     // Prep
  14.     $cui = get_current_user_id();
  15.     $mycred = mycred( $atts['ctype'] );
  16.  
  17.     // Check if current user is excluded
  18.     if ( $mycred->exclude_user( $cui ) ) return '';
  19.  
  20.     // If users balance is too low, show the url
  21.     if ( $mycred->get_users_balance( $cui, $atts['ctype'] ) < $atts['balance'] )
  22.         return '<a href="' . $atts['url'] . '">' . $atts['title'] . '</a>';
  23.  
  24.     return '';
  25. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement