Skip to content

Instantly share code, notes, and snippets.

@cartpauj
Created January 18, 2019 19:05
Show Gist options
  • Save cartpauj/b97a82184144a23752671ab29b6fe743 to your computer and use it in GitHub Desktop.
Save cartpauj/b97a82184144a23752671ab29b6fe743 to your computer and use it in GitHub Desktop.
Unprotect MemberPress posts if they have a certain category
<?php
// This code can be pasted into a plugin like Code Snippets or My Custom Functions or
// pasted into a child-theme's functions.php file
// You might have a Rule protecting all posts, but want posts with a certain category
// to be unprotected.
// You can do that with the code below.
// EDIT: You will need to edit the category_slug_here part is all.
// change category_slug_here to the slug of the category you want UnProtected.
function mepr_override_protection($protect, $post) {
if(has_category('category_slug_here', $post)) { $protect = false; }
return $protect;
}
function mepr_override_content_protection($protect, $post, $uri) {
return mepr_override_protection($protect, $post);
}
function mepr_override_redirection_protection($protect, $uri, $delim) {
global $post; //$post - may not be availble here if not using "template_redirect" as the redirect action in MemberPress Options
if(!isset($post) || !($post instanceof WP_Post)) { return $protect; }
return mepr_override_protection($protect, $post);
}
add_filter('mepr-pre-run-rule-content', 'mepr_override_content_protection', 11, 3);
add_filter('mepr-pre-run-rule-redirection', 'mepr_override_redirection_protection', 11, 3);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment