Home / Archive / MemberPress: Disable MemberPress Protection Based on Custom Post Type And Tag
Duplicate Snippet

Embed Snippet on Your Site

MemberPress: Disable MemberPress Protection Based on Custom Post Type And Tag

This code snippet disables content protection for specific post types that are also tagged with a specific term (e.g., 'free').

The sample code below will remove the protection on MemberPress Lesson (mpcs-lesson) posts with the tag free and make them publicly available.

Code Preview
php
<?php
add_filter('mepr-pre-run-rule-content', 'mepr_override_content_protection', 11, 3);
function mepr_override_content_protection($protect, $post, $uri) {
  // Unprotect posts that belong to a specific custom post type (mpcs-lesson), with the "free" tag
  if ('mpcs-lesson' === get_post_type($post->ID) && has_tag('free', $post)) {
    $protect = false; // Disable protection for these posts
  }
  return $protect;
}

Comments

Add a Comment