Advertisement
designbymerovingi

myCRED Daily limit for mycred_give with images

Dec 25th, 2013
230
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.44 KB | None | 0 0
  1. /**
  2.  * Overwrite the mycred_give shortcode
  3.  * Runs after myCRED has registered the shortcode in order for us
  4.  * to remove it and replace it with our own.
  5.  */
  6. add_action( 'mycred_init', 'custom_mycred_start' );
  7. function custom_mycred_start() {
  8.     remove_shortcode( 'mycred_give' );
  9.     add_shortcode( 'mycred_give', 'mycred_custom_render_shortcode_give' );
  10. }
  11.  
  12. if ( ! function_exists( 'mycred_custom_render_shortcode_give' ) ) :
  13.     function mycred_custom_render_shortcode_give( $atts, $content )
  14.     {
  15.         if ( ! is_user_logged_in() ) return;
  16.  
  17.         extract( shortcode_atts( array(
  18.             'uniqueid' => '',
  19.             'amount'   => NULL,
  20.             'user_id'  => '',
  21.             'log'      => '',
  22.             'ref'      => 'gift',
  23.             'limit'    => 0,
  24.             'type'     => 'mycred_default'
  25.         ), $atts ) );
  26.        
  27.         if ( $amount === NULL )
  28.             return '<strong>' . __( 'error', 'mycred' ) . '</strong> ' . __( 'Amount missing!', 'mycred' );
  29.  
  30.         if ( empty( $log ) )
  31.             return '<strong>' . __( 'error', 'mycred' ) . '</strong> ' . __( 'Log Template Missing!', 'mycred' );
  32.        
  33.         $mycred = mycred_get_settings();
  34.        
  35.         if ( empty( $user_id ) )
  36.             $user_id = get_current_user_id();
  37.        
  38.         // Check for exclusion
  39.         if ( $mycred->exclude_user( $user_id ) ) return;
  40.  
  41.         // Prep amount
  42.         $amount = $mycred->number( $amount );
  43.  
  44.         // Daily limit handling
  45.         if ( $limit == 'daily' ) {
  46.             // Todays date as a numeric value
  47.             $today = (int) date_i18n( 'Ymd' );
  48.  
  49.             // If user has received points today show image.
  50.             if ( $mycred->has_entry( $ref, $today, $user_id ) )
  51.                 return '
  52. <div align="center"><img src="http://mysite.com/images/youhaveflexpoint' . $uniqueid . '.jpg" alt="" /></div>';
  53.  
  54.             // Add Points
  55.             $mycred->add_creds(
  56.                 $ref,
  57.                 $user_id,
  58.                 $amount,
  59.                 $log,
  60.                 $today,
  61.                 '',
  62.                 $type
  63.             );
  64.  
  65.             // User has received points, show the image telling him about this.
  66.             return '
  67. <div align="center"><img src="http://mysite.com/images/1flexpoint' . $uniqueid . '.jpg" alt="" /></div>';
  68.         }
  69.         // Default limit handling
  70.         else {
  71.             $limit = abs( $limit );
  72.             if ( $limit != 0 && mycred_count_ref_instances( $ref, $user_id ) >= $limit ) return;
  73.  
  74.             // Add points
  75.             $mycred->add_creds(
  76.                 $ref,
  77.                 $user_id,
  78.                 $amount,
  79.                 $log,
  80.                 '',
  81.                 '',
  82.                 $type
  83.             );
  84.  
  85.             // User has received points, show the image telling him about this.
  86.             return '
  87. <div align="center"><img src="http://mysite.com/images/1flexpoint' . $uniqueid . '.jpg" alt="" /></div>';
  88.         }
  89.     }
  90. endif;
  91.  
  92. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement