diff --git a/misc/pmpro-restrict-all-cpt-posts.php b/misc/pmpro-restrict-all-cpt-posts.php new file mode 100644 index 0000000..67d9af6 --- /dev/null +++ b/misc/pmpro-restrict-all-cpt-posts.php @@ -0,0 +1,74 @@ +membership_levels = pmpro_getMembershipLevelsForUser( $theuser->ID ); + + $mylevelids = array(); + + foreach ( $theuser->membership_levels as $curlevel ) { + $mylevelids[] = $curlevel->id; + } + if ( count( $theuser->membership_levels ) > 0 && count( array_intersect( $mylevelids, $post_membership_levels_ids ) ) > 0 ) { + //the users membership id is one that will grant access + $hasaccess = true; + } else { + //user isn't a member of a level with access + $hasaccess = false; + } + + return $hasaccess; + } + // set the filter name to your post type name: pmpro_has_membership_access_filter_[post_type] + add_filter( 'pmpro_has_membership_access_filter_recipe', 'my_pmpro_restrict_all_cpt', 10, 4 ); + + function disable_pmpro_cpt_redirect() { + $my_cpt = 'recipe'; // Set your custom post type name here + + // check if post belongs to the CPT + if ( is_singular() && get_post_type() === $my_cpt ) { + if ( has_action( 'template_redirect', 'pmprocpt_template_redirect' ) ) { + remove_action( 'template_redirect', 'pmprocpt_template_redirect' ); + } + } +} +add_action( 'wp', 'disable_pmpro_cpt_redirect' ); \ No newline at end of file