Custom Content Restriction Detection

This guide explains how to use the wpai_is_content_restricted filter hook to add custom content restriction detection for membership plugins not officially supported by SensAI.

SensAI officially supports:

  • WooCommerce Memberships (100% coverage via official API)
  • MemberPress (100% coverage via official API)

If you’re using a different membership plugin, you can use the wpai_is_content_restricted filter hook to add custom restriction detection.

Important: This filter only runs when the “Index Membership-Restricted Content” setting is OFF (unchecked). It’s used to DETECT restrictions, not bypass them.

How it works

↑ Back to top

When SensAI indexes content, it checks if posts are restricted before including them in the AI’s knowledge base. The restriction check happens in this order:

  1. Native WordPress restrictions (private posts, password-protected)
  2. Officially supported membership plugins (WooCommerce Memberships, MemberPress)
  3. Custom filter hook: wpai_is_content_restricted

If ANY check returns true, the content is excluded from indexing.

Basic usage

↑ Back to top

Add this to your theme’s functions.php or a custom plugin:

add_filter('wpai_is_content_restricted', function($is_restricted, $post) {
// Your custom restriction check here
  if (/* your condition */) {
     return true; // Restrict content
  }return $is_restricted; // Keep existing restriction status}, 10, 2);

Example

↑ Back to top

Here’s a high-level example showing the pattern and logic:

add_filter('wpai_is_content_restricted', function($is_restricted, $post) {
    // STEP 1: Check if your membership plugin is active
    // Always verify the plugin exists before calling its functions
    if (!function_exists('your_plugin_check_function')) {
        return $is_restricted; // Plugin not active, return existing status
    }
    
    // STEP 2: Check for post-level restrictions
    // Most membership plugins store restriction data in post meta
    // or provide a function to check if content is restricted
    if (your_plugin_is_restricted($post->ID)) {
        return true; // Content is restricted, exclude from indexing
    }
    
    // STEP 3: Check for shortcode-based restrictions
    // Many plugins allow restrictions via shortcodes in content
    $restriction_shortcodes = ['restrict', 'members_only', 'premium'];
    foreach ($restriction_shortcodes as $shortcode) {
        if (has_shortcode($post->post_content, $shortcode)) {
            return true; // Found restriction shortcode
        }
    }
    
    // STEP 4: Return existing restriction status
    // If no restrictions found, keep the existing status
    return $is_restricted;
}, 10, 2);

The filter follows this decision flow:

Plugin detection
• First, verify your membership plugin is active
• Use function_exists(), class_exists(), or defined() checks
• If plugin isn’t active, return $is_restricted (don’t change anything)

Restriction checks
• Check post-level restrictions (meta fields, plugin functions)
• Check shortcode-based restrictions in content
• Check taxonomy/category restrictions if applicable
• Each check: if restricted → return true immediately

Return value
• true = Content is restricted → EXCLUDE from indexing
• false = Content is not restricted → ALLOW indexing
• $is_restricted = Keep existing status (from previous checks)

Safety first
• If you’re unsure, return true (restrict)
• Better to exclude content than accidentally index restricted content
• You can always refine later after testing

Quick reference

↑ Back to top

Finding your plugin’s restriction methods

↑ Back to top
  • Check plugin documentation for restriction functions
  • Inspect post meta fields (look for: restrict, member, access, level, plan)
  • Review shortcode documentation
  • Test with actual restricted/unrestricted content

Key points

↑ Back to top
  • Always check if plugin is active before calling functions
  • Return true to restrict (exclude), false to allow (include)
  • Check both post-level restrictions and shortcodes
  • Test thoroughly with restricted and unrestricted content
  • Add code to functions.php or a custom plugin

Important: The filter only runs when “Index Membership-Restricted Content”
is OFF. Always verify this setting in SensAI > Content & Indexing.