Advertisement
designbymerovingi

Charge Post Author for Link Click

Aug 29th, 2014
358
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.90 KB | None | 0 0
  1. add_filter( 'mycred_add', 'mycred_charge_post_author_for_click', 999, 3 );
  2. function mycred_charge_post_author_for_click( $reply, $request, $mycred ) {
  3.  
  4.     if ( $reply === false || $request['ref'] != 'link_click' || ! is_single() ) return $reply;
  5.  
  6.     global $post;
  7.  
  8.     if ( ! isset( $post->post_author ) ) return $reply;
  9.  
  10.     $author_id = $post->post_author;
  11.     $balance = $mycred->get_users_balance( $author_id, $request['type'] );
  12.  
  13.     // Charge if author can afford it
  14.     if ( $balance >= $mycred->number( $request['amount'] ) ) {
  15.  
  16.         // Charge the amount the user who clicked receives from the author
  17.         $mycred->update_users_balance( $author_id, 0-$request['amount'] );
  18.  
  19.         // Add a log entry
  20.         $mycred->add_to_log(
  21.             'link_click_charge',
  22.             $author_id,
  23.             0-$request['amount'],
  24.             'Charge for link click',
  25.             $request['ref_id'],
  26.             $request['data'],
  27.             $request['type']
  28.         );
  29.  
  30.     }
  31.  
  32.     return $reply;
  33.  
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement