Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save strangerstudios/8621394 to your computer and use it in GitHub Desktop.
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.
<?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