Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- * Restrict View Content Hook
- * This code snippet will restrict users / authors from getting
- * points when their post that is set for sale is viewed by someone
- * who has not paid for it.
- * @verion 1.0
- */
- add_filter( 'mycred_add', 'mycred_restrict_view_content', 10, 3 );
- function mycred_restrict_view_content( $reply, $request, $mycred ) {
- // Only applicable for view content hook
- if ( $reply === false || ! in_array( $request['ref'], array( 'view_content', 'view_content_author' ) ) )
- return $reply;
- // Get post and user IDs
- $post_id = absint( $request['ref_id'] );
- // User viewing content
- if ( $request['ref'] == 'view_content' )
- $user_id = absint( $request['user_id'] );
- else
- $user_id = absint( $request['data']['cui'] );
- // Get the sell content module
- $sell_content = new myCRED_Sell_Content_Module();
- // If post is for sale but has not been bought by user, decline payouts.
- if ( $sell_content->for_sale( $post_id ) && ! $sell_content->user_paid( $user_id, $post_id ) )
- return false;
- return $reply;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement