Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_filter( 'mycred_add', 'mycred_charge_post_author_for_click', 999, 3 );
- function mycred_charge_post_author_for_click( $reply, $request, $mycred ) {
- if ( $reply === false || $request['ref'] != 'link_click' || ! is_single() ) return $reply;
- global $post;
- if ( ! isset( $post->post_author ) ) return $reply;
- $author_id = $post->post_author;
- $balance = $mycred->get_users_balance( $author_id, $request['type'] );
- // Charge if author can afford it
- if ( $balance >= $mycred->number( $request['amount'] ) ) {
- // Charge the amount the user who clicked receives from the author
- $mycred->update_users_balance( $author_id, 0-$request['amount'] );
- // Add a log entry
- $mycred->add_to_log(
- 'link_click_charge',
- $author_id,
- 0-$request['amount'],
- 'Charge for link click',
- $request['ref_id'],
- $request['data'],
- $request['type']
- );
- }
- return $reply;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement