Created
January 25, 2014 18:49
-
-
Save strangerstudios/8621394 to your computer and use it in GitHub Desktop.
Filter pmpro_has_membership_access so paid members have access to all addon packages, but free members must pay the per post price. Edit the $my_paid_level_ids array to include an array of your paid level ids. Put this code in your active theme's functions.php or a custom WordPress plugin.
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 | |
/* | |
Filter pmpro_has_membership_access based on paid membership access. | |
*/ | |
function my_pmpro_has_membership_access_filter( $hasaccess, $mypost, $myuser, $post_membership_levels ) { | |
$my_paid_level_ids = array(5,6,7); | |
// Check if the user doesn't have access | |
if( ! $hasaccess ) { | |
// If this post has membership levels associated with it and is supposed to be locked by the Addon Plugin | |
if ( ! empty( $post_membership_levels ) && pmproap_isPostLocked( $mypost->ID ) ) { | |
// Loop through post levels | |
foreach ( $post_membership_levels as $level ) { | |
// Change level ID here to match your paying membership level | |
if ( in_array($level->id, $my_paid_level_ids) && pmpro_hasMembershipLevel( $my_paid_level_ids, $myuser->ID ) ) { | |
$hasaccess = true; | |
} | |
} | |
} | |
} | |
return $hasaccess; | |
} | |
// Hook in after the PMPro Addon Plugin | |
add_filter( 'pmpro_has_membership_access_filter', 'my_pmpro_has_membership_access_filter', 20, 4 ); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment