Forked from strangerstudios/my_pmpro_has_membership_access_filter.php
Created
February 19, 2014 10:51
-
-
Save cyberwani/9089740 to your computer and use it in GitHub Desktop.
This file contains hidden or 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