Created
July 12, 2012 20:08
-
-
Save strangerstudios/3100614 to your computer and use it in GitHub Desktop.
Per-level Teaser Text for Paid Memberships Pro
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
<?php | |
/* | |
Plugin Name: PMPro Per-level Teasers | |
Plugin URI: http://www.paidmembershipspro.com/pmpro-per-level-teasers/ | |
Description: Change the text shown when member content is filtered based on the membership level required to view that content. | |
Version: .1 | |
Author: Stranger Studios | |
Author URI: http://www.strangerstudios.com | |
*/ | |
/* | |
The Paid Memberships Pro plugin must be installed and active for this plugin to work. | |
(!) Edit these arrays to have the text for each level. | |
Note: There is a hook for pmpro_rss_text_filter as well, but we're not swapping that one. | |
*/ | |
global $plt_teaser_text; | |
$plt_teaser_text = array(); | |
$plt_teaser_text['non_member'] = array( | |
1 => 'This is the new teaser text for Level 1. This is the fancy signup button: [pmpro_button level="1"]', | |
2 => 'This is the new teaser text for Level 2. This is the fancy signup button: [pmpro_button level="2"]' | |
); | |
$plt_teaser_text['not_logged_in'] = array( | |
1 => 'This is the new teaser text for Level 1. <a href="/wp-login.php">Login</a> or... This is the fancy signup button: [pmpro_button level="1"]', | |
2 => 'This is the new teaser text for Level 2. <a href="/wp-login.php">Login</a> or... This is the fancy signup button: [pmpro_button level="2"]' | |
); | |
/* | |
Swap the non-member text. | |
*/ | |
function plt_pmpro_non_member_text_filter($content) | |
{ | |
global $plt_teaser_text; | |
//get level ids for this post | |
$hasaccess = pmpro_has_membership_access(NULL, NULL, true); | |
if(is_array($hasaccess)) | |
{ | |
//returned an array to give us the membership level values | |
$post_membership_levels_ids = $hasaccess[1]; | |
//only swap if there is one level for this page | |
if(count($post_membership_levels_ids) == 1) | |
{ | |
//only swap if there is text in the arrays defined above | |
if(!empty($plt_teaser_text['non_member'][$post_membership_levels_ids[0]])) | |
$content = $plt_teaser_text['non_member'][$post_membership_levels_ids[0]]; | |
} | |
} | |
return $content; | |
} | |
add_filter("pmpro_non_member_text_filter", "plt_pmpro_non_member_text_filter"); | |
/* | |
Swap the not logged in text. | |
*/ | |
function plt_pmpro_not_logged_in_text_filter($content) | |
{ | |
global $plt_teaser_text; | |
//get level ids for this post | |
$hasaccess = pmpro_has_membership_access(NULL, NULL, true); | |
if(is_array($hasaccess)) | |
{ | |
//returned an array to give us the membership level values | |
$post_membership_levels_ids = $hasaccess[1]; | |
//only swap if there is one level for this page | |
if(count($post_membership_levels_ids) == 1) | |
{ | |
//only swap if there is text in the arrays defined above | |
if(!empty($plt_teaser_text['not_logged_in'][$post_membership_levels_ids[0]])) | |
$content = $plt_teaser_text['not_logged_in'][$post_membership_levels_ids[0]]; | |
} | |
} | |
return $content; | |
} | |
add_filter("pmpro_not_logged_in_text_filter", "plt_pmpro_not_logged_in_text_filter"); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment