Created
January 6, 2016 21:47
-
-
Save strangerstudios/8b820deef574ec5fc966 to your computer and use it in GitHub Desktop.
Show a login/register link at the bottom of any post that uses PMPro's membership shortcode.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
Show a login/register link at the bottom of any post that uses the membership shortcode. | |
Note this doesn't check for specific membership levels. | |
Add this code to your active theme's functions.php or a custom plugin. | |
*/ | |
function show_login_register_links_on_member_pages($content) { | |
//bail if PMPro isn't loaded | |
if(!function_exists('pmpro_has_membership_access')) | |
return $content; | |
//does this post use the membership shortcode? | |
if(has_shortcode($content, "membership") && !pmpro_hasMembershipLevel() && pmpro_has_membership_access()) { | |
$pmpro_content_message_pre = '<div class="pmpro_content_message">'; | |
$pmpro_content_message_post = '</div>'; | |
$sr_search = array("!!levels!!", "!!referrer!!"); | |
$sr_replace = array("", urlencode(site_url($_SERVER['REQUEST_URI']))); | |
//get the correct message to show at the bottom | |
if(is_feed()) | |
{ | |
$newcontent = apply_filters("pmpro_rss_text_filter", stripslashes(pmpro_getOption("rsstext"))); | |
$content .= $pmpro_content_message_pre . str_replace($sr_search, $sr_replace, $newcontent) . $pmpro_content_message_post; | |
} | |
elseif(is_user_logged_in()) | |
{ | |
//not a member | |
$newcontent = apply_filters("pmpro_non_member_text_filter", stripslashes(pmpro_getOption("nonmembertext"))); | |
$content .= $pmpro_content_message_pre . str_replace($sr_search, $sr_replace, $newcontent) . $pmpro_content_message_post; | |
} | |
else | |
{ | |
//not logged in! | |
$newcontent = apply_filters("pmpro_not_logged_in_text_filter", stripslashes(pmpro_getOption("notloggedintext"))); | |
$content .= $pmpro_content_message_pre . str_replace($sr_search, $sr_replace, $newcontent) . $pmpro_content_message_post; | |
} | |
} | |
return $content; | |
} | |
add_filter('the_content', 'show_login_register_links_on_member_pages', 5); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This recipe is included in the blog post on "Show a login/register link for non-members when using the [membership] shortcode." at Paid Memberships Pro here: https://www.paidmembershipspro.com/show-loginregister-link-non-members-using-membership-shortcode/