Getting Started with BricksMembers API

BricksMembers provides a comprehensive API for extending and customizing the plugin. This guide introduces the core concepts and APIs you’ll use to build custom integrations.

Core API Functions

BricksMembers exposes all functionality through public functions prefixed with brm_. These functions provide safe, consistent access to plugin features.

// Access core functionality
$core = brm_core();
$helper = brm_helper();

// Get user levels
$levels = brm_core()->get_user_levels( $user_id );

// Check content access
$has_access = brm_user_can_access_content( $user_id, $post_id );

// Manage progress
brm_mark_content_completed( $user_id, $post_id );
$is_completed = brm_is_content_completed( $user_id, $post_id );

Key Concepts

User Levels

Levels are membership tiers that control content access. Users can have multiple levels, and content can require one or more levels.

// Get all levels
$all_levels = brm_get_all_levels();

// Get user's levels
$user_levels = brm_core()->get_user_levels( $user_id );

// Add/remove levels
brm_core()->add_user_level( $user_id, $level_id );
brm_core()->remove_user_level( $user_id, $level_id );

// Set all levels at once
brm_core()->set_user_levels( $user_id, [1, 2, 3] );

Content Access

Content can be protected by requiring specific levels. The access system checks if users have the required levels before allowing access.

// Check if user can access content
$has_access = brm_user_can_access_content( $user_id, $post_id );

// Get content protection settings
$protection = brm_get_content_protection( $post_id );

// Set required levels for content
brm_set_post_levels( $post_id, [1, 2] );
brm_add_post_level( $post_id, $level_id );
brm_remove_post_level( $post_id, $level_id );

Progress Tracking

BricksMembers tracks user progress through content. Completion status is stored per user and can be queried or modified via the API.

// Mark content as completed/incomplete
brm_mark_content_completed( $user_id, $post_id );
brm_mark_content_incomplete( $user_id, $post_id );

// Check completion status
$is_completed = brm_is_content_completed( $user_id, $post_id );
$completion_date = brm_get_completion_date( $user_id, $post_id );

// Get all completed content
$completed = brm_core()->get_user_completed_posts( $user_id );

Structure Navigation

Structures organize content hierarchically (e.g., Course → Module → Lesson). The API provides navigation functions to move between items.

// Get next/previous item in structure (returns WP_Post objects or null)
$next_post = brm_get_next_structure_item( $post_id );
$next_post_id = $next_post ? $next_post->ID : null;

$prev_post = brm_get_previous_structure_item( $post_id );
$prev_post_id = $prev_post ? $prev_post->ID : null;

// Get current position in structure
$position = brm_get_structure_current_position( $post_id );
// Returns: ['current_level' => int, 'order_position' => int, 'structure_id' => string]

// Navigation with boundaries
$next = brm_get_next_structure_item( $post_id, 'toplevel' );
$prev = brm_get_previous_structure_item( $post_id, 'parentlevel' );

Extensibility Points

BricksMembers uses WordPress actions for extensibility. You can hook into events without editing plugin files.

Actions

Actions fire when events occur, allowing you to execute custom code:

// When level is added to user
add_action( 'brm_user_level_added', function( $user_id, $level_id ) {
    // Your custom code here
}, 10, 2 );

// When content is completed
add_action( 'brm_post_completed', function( $user_id, $post_id ) {
    // Your custom code here
}, 10, 2 );

Filters

The core API does not expose filters for user levels or access checks. Use the provided actions and public functions instead.

Optional Modules

Some features are optional modules that can be enabled or disabled. Check if a module is active before using its functions:

// Check module status
$config = brm_get_module_config();

if ( $config['progress_tracking'] ) {
    // Progress tracking is enabled
}

if ( $config['drip_system'] ) {
    // Drip content is enabled
}

if ( $config['protected_downloads'] ) {
    // Protected downloads are enabled
}

// Drip content functions (if enabled)
if ( $config['drip_system'] ) {
    $is_unlocked = brm_drip_is_unlocked( $user_id, $post_id );
    $status = brm_drip_service_get_status( $user_id, $post_id );
}

// Protected downloads functions (if enabled)
if ( $config['protected_downloads'] ) {
    $can_access = brm_can_user_access_download( $download_id );
}

Best Practices

  • Use public functions: Always use brm_* functions rather than accessing internal classes directly
  • Check dependencies: Functions return safe defaults if dependencies aren’t available
  • Hook into events: Use actions and filters rather than modifying plugin files
  • Check module status: Verify modules are enabled before using module-specific functions
  • Follow WordPress standards: All functions follow WordPress coding conventions and security practices

Next Steps

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