Skip to content

Instantly share code, notes, and snippets.

@kimcoleman
Created September 24, 2018 16:58
Show Gist options
  • Save kimcoleman/45bcf157971e25b7796b2d68ad2d0543 to your computer and use it in GitHub Desktop.
Save kimcoleman/45bcf157971e25b7796b2d68ad2d0543 to your computer and use it in GitHub Desktop.
Make specific post IDs in a restricted category available publicly.
<?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);
@laurenhagan0306
Copy link

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/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment