BricksMembers API Reference

Quick reference for the public functions, actions, and filters exposed by BricksMembers. All entries below map directly to functions and hooks implemented in the plugin.

Core Instances

// Core singletons
$core   = brm_core();   // BRM_Core
$helper = brm_helper(); // BRM_Core_Helper

// Initialize system (normally automatic)
brm_initialize_core_system();

User Levels API

// Read levels
$all_levels  = brm_get_all_levels();
$level       = brm_get_level_by_id( $level_id );
$user_levels = brm_core()->get_user_levels( $user_id );

// Manage levels
$level_id = brm_create_level( 'Premium', 'Premium membership' );
brm_update_level( $level_id, ['name' => 'VIP'] );
brm_delete_level( $level_id );

// Assign to users
brm_core()->add_user_level( $user_id, $level_id );
brm_core()->remove_user_level( $user_id, $level_id );
brm_core()->set_user_levels( $user_id, [1, 2, 3] );
brm_user_has_level( $user_id, $level_id );

Content Access & Protection

// Access checks
$has_access = brm_user_can_access_content( $user_id, $post_id );
$protection = brm_get_content_protection( $post_id );

// Post/term protection
$required = brm_get_post_required_levels( $post_id );
brm_add_post_level( $post_id, $level_id );
brm_remove_post_level( $post_id, $level_id );
brm_set_post_levels( $post_id, [1, 2] );

$term_levels = brm_get_term_required_levels( $term_id );
brm_set_term_levels( $term_id, [1, 2] );

Progress Tracking

// Completion
brm_mark_content_completed( $user_id, $post_id );
brm_mark_content_incomplete( $user_id, $post_id );
$is_completed = brm_is_content_completed( $user_id, $post_id );
$date         = brm_get_completion_date( $user_id, $post_id );

// Progress data
$completed_posts   = brm_core()->get_user_completed_posts( $user_id );
$completed_parents = brm_core()->get_user_completed_parents( $user_id );
brm_reset_user_progress( $user_id, $post_id );

Structures & Navigation

// Navigation within structures (returns WP_Post objects or null)
$next_post = brm_get_next_structure_item( $post_id, $boundary );
$prev_post = brm_get_previous_structure_item( $post_id, $boundary );
$position = brm_get_structure_current_position( $post_id, $target_level );
// Position returns: ['current_level' => int, 'order_position' => int, 'structure_id' => string]

// Structure data
$structures = brm_get_all_structures();
$structure  = brm_get_structure_by_id( $structure_id );
$levels     = brm_get_structure_levels( $structure_id, 'auto' );


// Structure helpers
$structure_id = brm_get_structure_id_by_object( 'course', 'post_type' );
$level_index = brm_get_object_level_index( 'lesson', 'post_type', $structure_id );

Data Helpers

// Post data row (cached)
$post_data = brm_core()->get_post_data( $post_id );
brm_update_post_data( $post_id, ['required_levels' => [1,2]] );

// User data row (cached)
$user_data = brm_core()->get_user_data( $user_id );

Module Configuration

$config = brm_get_module_config();
if ( $config['progress_tracking'] ) {
    // Progress functions available
}
if ( $config['drip_system'] ) {
    // Drip functions available
}
if ( $config['protected_downloads'] ) {
    // Protected downloads enabled
}

Drip Content (Optional Module)

Drip content functions are available when the drip system module is enabled:

// Check if drip is enabled
if ( brm_get_module_config()['drip_system'] ) {
    // Check unlock status
    $is_unlocked = brm_drip_is_unlocked( $user_id, $post_id );
    
    // Get full drip status
    $status = brm_drip_service_get_status( $user_id, $post_id );
    // Returns: ['available' => bool, 'unlocked' => bool, 'unlock_date' => int, 'days_left' => int, ...]
    
    // Check time/prerequisite readiness
    $time_ready = brm_drip_is_time_ready( $user_id, $post_id );
    $prereq_ready = brm_drip_is_prereq_ready( $user_id, $post_id );
}

Protected Downloads (Optional Module)

Protected download functions are available when the protected downloads module is enabled:

// Check if protected downloads is enabled
if ( brm_get_module_config()['protected_downloads'] ) {
    // Check if current user can access download
    $can_access = brm_can_user_access_download( $download_id );
    
    // Check access for specific user (for dynamic tags)
    $can_access = brm_can_user_access_download_hybrid( $download_id, $user_id );
}

Recompute & Batch Processing

// Unified recompute (SPM, Progress, Drip)
brm_schedule_unified_recompute( [
    'structures' => ['courses'], // or null for all
    'spm'        => true,
    'progress'   => true,
    'drip'       => true,
] );

Webhooks

// Endpoint
POST /wp-json/bricksmembers/v1/webhook

// Auth: secret query param, HMAC signature header, or Authorization: Bearer {brm_api_key}

// Send a test webhook (admin utility)
brm_send_test_webhook( [ [ 'key' => 'event', 'value' => 'user_level_added' ] ] );

WordPress Actions

Hook into lifecycle events:

// User levels
add_action( 'brm_user_level_added', function( $user_id, $level_id ) {}, 10, 2 );
add_action( 'brm_user_level_removed', function( $user_id, $level_id ) {}, 10, 2 );
add_action( 'brm_user_levels_set', function( $user_id, $level_ids ) {}, 10, 2 );

// Progress
add_action( 'brm_post_completed', function( $user_id, $post_id ) {}, 10, 2 );
add_action( 'brm_post_incompleted', function( $user_id, $post_id ) {}, 10, 2 );

// Structures
add_action( 'brm_structure_deleted', function( $structure_id ) {}, 10, 1 );
add_action( 'brm_structure_updated', function( $structure_id, $data ) {}, 10, 2 );

WordPress Filters

Selected filters exposed by the plugin:

// Redirect behavior for protected content
add_filter( 'brm_should_apply_redirect', function( $should_redirect, $post_id, $user_id ) {
    return $should_redirect;
}, 10, 3 );

// Batch size for user backfill worker
add_filter( 'brm_unlocks_user_worker_posts_per_page', function( $posts_per_page ) {
    return 150;
} );

// Bricks integration hooks
add_filter( 'bricks/posts/query_vars', function( $query_vars, $settings, $element_id ) {
    return $query_vars;
}, 20, 3 );

add_filter( 'bricks/conditions/result', function( $result, $condition, $element_id ) {
    return $result;
}, 10, 3 );

Additional Utility Functions

// Get posts requiring a specific level
$result = brm_get_posts_requiring_level( $level_id, $page = 1, $per_page = 50 );
// Returns: ['posts' => array, 'total' => int, 'pages' => int]

// Get level user count
$count = brm_get_level_user_count( $level_id );

// Get users with a level
$user_ids = brm_get_level_users( $level_id );

// Get paginated users for a level
$result = brm_get_users_for_level_paginated( $level_id, $page = 1, $per_page = 50 );
Early Bird Deal

Start Building Your Membership Site Today

Create, sell, and manage your content without limits. BricksMembers gives you everything you need to build membership and LMS sites with Bricks Builder.

Lifetime updates & bug fixes • Premium support • 0% transaction fees • 60-day money-back guarantee