Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save cyberwani/9089740 to your computer and use it in GitHub Desktop.
Save cyberwani/9089740 to your computer and use it in GitHub Desktop.
<?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