pmpro_membership_content_filter

The Paid Memberships Pro pmpro membership content filter function.

Description

pmpro_membership_content_filter( $content, (constant) $skipcheck = false ); 

Parameters (2)

0. $content
The content.
1. $skipcheck — Optional. (constant) => false
The skipcheck.

Usage

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

Defined (1)

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

/includes/content.php  
  1. function pmpro_membership_content_filter($content, $skipcheck = false) 
  2. {  
  3. global $post, $current_user; 
  4.  
  5. if(!$skipcheck) 
  6. $hasaccess = pmpro_has_membership_access(NULL, NULL, true); 
  7. if(is_array($hasaccess)) 
  8. //returned an array to give us the membership level values 
  9. $post_membership_levels_ids = $hasaccess[1]; 
  10. $post_membership_levels_names = $hasaccess[2]; 
  11. $hasaccess = $hasaccess[0]; 
  12.  
  13. if($hasaccess) 
  14. //all good, return content 
  15. return $content; 
  16. else 
  17. //if show excerpts is set, return just the excerpt 
  18. if(pmpro_getOption("showexcerpts")) 
  19. {  
  20. //show excerpt 
  21. global $post; 
  22. if($post->post_excerpt) 
  23. {  
  24. //defined exerpt 
  25. $content = wpautop($post->post_excerpt); 
  26. elseif(strpos($content, "<span id=\"more-" . $post->ID . "\"></span>") !== false) 
  27. {  
  28. //more tag 
  29. $pos = strpos($content, "<span id=\"more-" . $post->ID . "\"></span>"); 
  30. $content = wpautop(substr($content, 0, $pos)); 
  31. elseif(strpos($content, 'class="more-link">') !== false) 
  32. //more link 
  33. $content = preg_replace("/\<a.*class\=\"more\-link\".*\>.*\<\/a\>/", "", $content); 
  34. else 
  35. //auto generated excerpt. pulled from wp_trim_excerpt 
  36. $content = strip_shortcodes( $content ); 
  37. $content = str_replace(']]>', ']]>', $content); 
  38. $content = strip_tags($content); 
  39. $excerpt_length = apply_filters('excerpt_length', 55); 
  40. $words = preg_split("/[\n\r\t ]+/", $content, $excerpt_length + 1, PREG_SPLIT_NO_EMPTY); 
  41. if ( count($words) > $excerpt_length ) { 
  42. array_pop($words); 
  43. $content = implode(' ', $words); 
  44. $content = $content . "... "; 
  45. } else { 
  46. $content = implode(' ', $words) . "... "; 
  47.  
  48. $content = wpautop($content); 
  49. else 
  50. //else hide everything 
  51. $content = ""; 
  52.  
  53. if(empty($post_membership_levels_ids)) 
  54. $post_membership_levels_ids = array(); 
  55.  
  56. if(empty($post_membership_levels_names)) 
  57. $post_membership_levels_names = array(); 
  58.  
  59. //hide levels which don't allow signups by default 
  60. if(!apply_filters("pmpro_membership_content_filter_disallowed_levels", false, $post_membership_levels_ids, $post_membership_levels_names)) 
  61. foreach($post_membership_levels_ids as $key=>$id) 
  62. //does this level allow registrations? 
  63. $level_obj = pmpro_getLevel($id); 
  64. if(!$level_obj->allow_signups) 
  65. unset($post_membership_levels_ids[$key]); 
  66. unset($post_membership_levels_names[$key]); 
  67.  
  68. $pmpro_content_message_pre = '<div class="pmpro_content_message">'; 
  69. $pmpro_content_message_post = '</div>'; 
  70.  
  71. $sr_search = array("!!levels!!", "!!referrer!!"); 
  72. $sr_replace = array(pmpro_implodeToEnglish($post_membership_levels_names), urlencode(site_url($_SERVER['REQUEST_URI']))); 
  73.  
  74. //get the correct message to show at the bottom 
  75. if(is_feed()) 
  76. $newcontent = apply_filters("pmpro_rss_text_filter", stripslashes(pmpro_getOption("rsstext"))); 
  77. $content .= $pmpro_content_message_pre . str_replace($sr_search, $sr_replace, $newcontent) . $pmpro_content_message_post; 
  78. elseif($current_user->ID) 
  79. //not a member 
  80. $newcontent = apply_filters("pmpro_non_member_text_filter", stripslashes(pmpro_getOption("nonmembertext"))); 
  81. $content .= $pmpro_content_message_pre . str_replace($sr_search, $sr_replace, $newcontent) . $pmpro_content_message_post; 
  82. else 
  83. //not logged in! 
  84. $newcontent = apply_filters("pmpro_not_logged_in_text_filter", stripslashes(pmpro_getOption("notloggedintext"))); 
  85. $content .= $pmpro_content_message_pre . str_replace($sr_search, $sr_replace, $newcontent) . $pmpro_content_message_post; 
  86.  
  87. return $content;