Home / Archive / MemberPress: Add Category Exception to All Post Rule
Duplicate Snippet

Embed Snippet on Your Site

MemberPress: Add Category Exception to All Post Rule

Add a category exception to the all posts rule instead of having to add the posts individually. Change category_slug_here to the slug of the category you want unprotected.

Code Preview
php
<?php
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 );

Comments

Add a Comment