Advertisement
designbymerovingi

Restrict View Content Hook

Nov 12th, 2014
239
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.05 KB | None | 0 0
  1. /**
  2.  * Restrict View Content Hook
  3.  * This code snippet will restrict users / authors from getting
  4.  * points when their post that is set for sale is viewed by someone
  5.  * who has not paid for it.
  6.  * @verion 1.0
  7.  */
  8. add_filter( 'mycred_add', 'mycred_restrict_view_content', 10, 3 );
  9. function mycred_restrict_view_content( $reply, $request, $mycred ) {
  10.  
  11.     // Only applicable for view content hook
  12.     if ( $reply === false || ! in_array( $request['ref'], array( 'view_content', 'view_content_author' ) ) )
  13.         return $reply;
  14.  
  15.     // Get post and user IDs
  16.     $post_id = absint( $request['ref_id'] );
  17.  
  18.     // User viewing content
  19.     if ( $request['ref'] == 'view_content' )
  20.         $user_id = absint( $request['user_id'] );
  21.     else
  22.         $user_id = absint( $request['data']['cui'] );
  23.  
  24.     // Get the sell content module
  25.     $sell_content = new myCRED_Sell_Content_Module();
  26.  
  27.     // If post is for sale but has not been bought by user, decline payouts.
  28.     if ( $sell_content->for_sale( $post_id ) && ! $sell_content->user_paid( $user_id, $post_id ) )
  29.         return false;
  30.  
  31.     return $reply;
  32.  
  33. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement