pmpro_comments_filter

The Paid Memberships Pro pmpro comments filter function.

Description

pmpro_comments_filter( $comments, (constant) $post_id = NULL ); 

Parameters (2)

0. $comments
The comments.
1. $post_id — Optional. (constant) => NULL
The post id.

Usage

  1. if ( !function_exists( 'pmpro_comments_filter' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'paid-memberships-pro/includes/content.php'; 
  3.  
  4. // The comments. 
  5. $comments = null; 
  6.  
  7. // The post id. 
  8. $post_id = NULL; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = pmpro_comments_filter($comments, $post_id); 
  12.  

Defined (1)

The function is defined in the following location(s).

/includes/content.php  
  1. function pmpro_comments_filter($comments, $post_id = NULL) 
  2. global $post, $wpdb, $current_user; 
  3. if(!$post_id) 
  4. $post_id = $post->ID; 
  5.  
  6. if(!$comments) 
  7. return $comments; //if they are closed anyway, we don't need to check 
  8.  
  9. global $post, $current_user; 
  10.  
  11. $hasaccess = pmpro_has_membership_access(NULL, NULL, true); 
  12. if(is_array($hasaccess)) 
  13. //returned an array to give us the membership level values 
  14. $post_membership_levels_ids = $hasaccess[1]; 
  15. $post_membership_levels_names = $hasaccess[2]; 
  16. $hasaccess = $hasaccess[0]; 
  17.  
  18. if($hasaccess) 
  19. //all good, return content 
  20. return $comments; 
  21. else 
  22. if(!$post_membership_levels_ids) 
  23. $post_membership_levels_ids = array(); 
  24.  
  25. if(!$post_membership_levels_names) 
  26. $post_membership_levels_names = array(); 
  27.  
  28. //get the correct message 
  29. if(is_feed()) 
  30. if(is_array($comments)) 
  31. return array(); 
  32. else 
  33. return false; 
  34. elseif($current_user->ID) 
  35. //not a member 
  36. if(is_array($comments)) 
  37. return array(); 
  38. else 
  39. return false; 
  40. else 
  41. //not logged in! 
  42. if(is_array($comments)) 
  43. return array(); 
  44. else 
  45. return false; 
  46.  
  47. return $comments;