Extending & Customizing BricksMembers
BricksMembers is built for extensibility. Use WordPress hooks, filters, and the plugin’s API to customize behavior without modifying core files.
Custom Access Logic
The access API is not filterable. Implement custom rules by wrapping brm_user_can_access_content() in your own logic or by using redirects/actions.
Custom User Levels
User levels are not filterable; use the public functions (add/remove/set) to control access.
Reacting to Events
Use the structured event system to react to access, progress, and level changes.
Subscribe to Events
Use \BaselMedia\BricksMembers\Utilities\ExtensionRegistry::subscribe() to receive rich event objects with full context:
use BaselMedia\BricksMembers\Utilities\ExtensionRegistry;
use BaselMedia\BricksMembers\Core\Event;
// Subscribe to access_granted with full context
ExtensionRegistry::subscribe(
Event::ACCESS_GRANTED,
function( Event $event ): void {
$user_id = $event->get_user_id();
$level_id = $event->get_resource_id();
$trigger = $event->get_trigger(); // admin, webhook, woocommerce, etc.
$reason = $event->get_reason();
$corr_id = $event->get_correlation_id(); // For tracing
// Only send email for WooCommerce purchases
if ( Event::TRIGGER_WOOCOMMERCE === $trigger ) {
send_purchase_confirmation( $user_id, $level_id );
}
}
);
Override Redirect Behavior
Control when redirects occur for protected content using brm_should_apply_redirect:
// Don't redirect on preview
add_filter( 'brm_should_apply_redirect', function( $should_redirect, $post_id, $user_id ) {
if ( is_preview() ) {
return false;
}
return $should_redirect;
}, 10, 3 );
Custom Batch Sizes
Adjust batch processing sizes for user backfill via brm_unlocks_user_worker_posts_per_page if needed:
add_filter( 'brm_unlocks_user_worker_posts_per_page', function( $posts_per_page ) {
return 150; // Reduce or increase for your hosting
} );
Custom Dynamic Tags
Add custom dynamic tags for use in Bricks Builder:
// Register custom dynamic tag
add_filter( 'bricks/dynamic_tags_list', function( $tags ) {
$tags[] = [
'name' => 'brm_custom',
'label' => 'Custom BRM Tag',
'group' => 'BricksMembers',
'callback' => 'render_custom_brm_tag'
];
return $tags;
} );
function render_custom_brm_tag( $post_id, $args ) {
$user_id = get_current_user_id();
if ( ! $user_id ) {
return '';
}
// Use BricksMembers API
$levels = brm_core()->get_user_levels( $user_id );
$level_names = array_map( function( $level_id ) {
$level = brm_get_level_by_id( $level_id );
return $level ? $level->name : '';
}, $levels );
return implode( ', ', array_filter( $level_names ) );
}
Best Practices
- Use hooks, don’t modify core: Always extend via filters/actions
- Check dependencies: Verify functions exist before calling
- Respect priorities: Use appropriate hook priorities (10 = default, 20+ = after plugin)
- Return values: Always return filtered values, even if unchanged
- Test thoroughly: Test your customizations with different scenarios
- Use API functions: Always use
brm_*functions rather than accessing internals