skip to Main Content

WordPress Code Snippets


How to Add bbPress User Roles and Permissions

Managing user roles and permissions is essential for controlling access to specific areas of your bbPress forums. Here’s how you can customize user roles with a PHP code snippet:

Add Custom User Roles in bbPress

Use this code to create custom roles for your bbPress forum:

function add_bbpress_custom_roles() {
    add_role( 'bbpress_moderator', 'bbPress Moderator', array(
        'read'   => true,
        'edit_posts' => false,
        'delete_posts' => false,
    ));
}
add_action( 'init', 'add_bbpress_custom_roles' );

Modify Permissions for a Custom Role

You can also change permissions for existing roles:

function modify_bbpress_permissions() {
    $role = get_role( 'bbpress_moderator' );
    $role->add_cap( 'moderate' );
    $role->add_cap( 'bbp_moderate' );
}
add_action( 'init', 'modify_bbpress_permissions' );

I’m a WordPress developer with 10+ years of experience in WooCommerce and custom plugins. I combine technical expertise with design flair to help you create standout, user-friendly websites. Let’s transform your digital presence!

Best WordPress Hosting
Back To Top