Skip to content

Instantly share code, notes, and snippets.

@travislima
Created November 19, 2016 10:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save travislima/788569f5c06fcc7197cd3ebb6ae72a47 to your computer and use it in GitHub Desktop.
Save travislima/788569f5c06fcc7197cd3ebb6ae72a47 to your computer and use it in GitHub Desktop.
Charge All access members for Packages if specific category is found even if their membership has access
/*
This gist is a modification of the "All Access" gist found here:
https://www.paidmembershipspro.com/allow-specific-membership-levels-to-view-addon-packages-and-require-others-to-pay/
This gist will allow you to add a specific category to any post.
This will in turn require users to pay for the post even if they have all access permissions.
Set levels as "all access levels" so members of these levels will be able to view all Addon Packages.
Requires Paid Memberships Pro and the pmpro-addon-packages plugin.
*/
function my_pmproap_all_access_levels($levels, $user_id, $post_id)
{
//I'm just adding the level, but I could do some calculation based on the user and post id to programatically give access to content
$levels = array(16);
if( has_category( 'category_slug' ) ){ //Change category_slug to your category that you wish to add to posts.
$levels = array();
}
return $levels;
}
add_filter("pmproap_all_access_levels", "my_pmproap_all_access_levels", 10, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment