Advertisement
designbymerovingi

Minimum Balance Requirement for mycred_link

Mar 16th, 2016
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.94 KB | None | 0 0
  1. /**
  2.  * Replace the mycred_link shortcode
  3.  * @version 1.0
  4.  */
  5. add_action( 'mycred_init', 'mycredpro_replace_link_click_shortcode', 990 );
  6. function mycredpro_replace_link_click_shortcode() {
  7.  
  8.     remove_shortcode( 'mycred_link' );
  9.     add_shortcode( 'mycred_link', 'mycredpro_render_shortcode_link' );
  10.  
  11. }
  12.  
  13. /**
  14.  * Before showing the mycred_link shortcode, make sure the user
  15.  * can afford to click on it.
  16.  * @version 1.0
  17.  */
  18. function mycredpro_render_shortcode_link( $atts, $content = '' ) {
  19.  
  20.     extract( shortcode_atts( array( 'amount' => 0, 'ctype' => 'mycred_default' ), $atts ) );
  21.  
  22.     if ( ! is_user_logged_in() ) return '';
  23.  
  24.     $mycred = mycred( $ctype );
  25.  
  26.     $balance = $mycred->get_users_balance( get_current_user_id(), $ctype );
  27.  
  28.     // Do not show anything if a user can not afford to click
  29.     if ( $balance < abs( $amount ) ) return '';
  30.  
  31.     // Let myCRED generate the shortcode for us
  32.     return mycred_render_shortcode_link( $atts, $content );
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement