Created
September 24, 2018 16:58
-
-
Save kimcoleman/45bcf157971e25b7796b2d68ad2d0543 to your computer and use it in GitHub Desktop.
Make specific post IDs in a restricted category available publicly.
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 // Do not copy this tag | |
/* | |
* Make specific post IDs in a restricted category available publicly. | |
* | |
* Add this code below to your PMPro Customizations Plugin - https://www.paidmembershipspro.com/create-a-plugin-for-pmpro-customizations/ | |
*/ | |
function unlock_posts_by_ID( $hasaccess, $post, $user, $post_membership_levels ) { | |
// If they already have access, let them at it. | |
if ( $hasaccess ) { | |
return $hasaccess; | |
} | |
// Set which post IDs are public. | |
$public_post_IDs = array( 1, 2 ); | |
// Now check the post ID | |
if ( in_array( $post->ID, $public_post_IDs ) ) { | |
$hasaccess = true; | |
} | |
return $hasaccess; | |
} | |
add_filter('pmpro_has_membership_access_filter', 'unlock_posts_by_ID', 15, 4); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This recipe is included in the blog post "How to allow visitor access to specific posts in a Membership-restricted category." at Paid Memberships Pro here: https://www.paidmembershipspro.com/how-to-allow-visitor-access-to-specific-posts-in-a-membership-restricted-category/