LMS & eLearning

Snippet: Add a Custom Role With LearnDash Group Leader Capabilities

How LearnDash recognises a group leader by capability rather than role name, and a snippet that creates a custom role such as Mentor that gets group leader powers plus your own extras, with caveats.

Snippet: Add a Custom Role With LearnDash Group Leader Capabilities

LearnDash ships one role for people who manage learners, Group Leader, and plenty of sites want a differently named or differently powered version: a Mentor who leads groups and can also edit blog posts, a Franchise Manager who leads groups and manages WooCommerce orders, or simply a role called Instructor because that is the word your organisation uses. The good news is that LearnDash 4.18.0.1 does not look for the role name. It looks for a capability, and any role that carries it is treated as a group leader everywhere in the plugin. This snippet creates such a role safely.

What LearnDash actually checks

In includes/ld-groups.php, learndash_is_group_leader_user() returns the result of user_can( $user_id, LEARNDASH_GROUP_LEADER_CAPABILITY_CHECK ), and the constant defaults to the string group_leader. The role LearnDash creates with learndash_add_group_admin_role() is just a role named group_leader whose capabilities are read, group_leader, wpProQuiz_show_statistics, level_0 and level_1. The admin menu entry for Submitted Essays is gated on the group_leader capability as well. So a custom role with those same capabilities passes every group leader check, sees the group leader reports, and is offered in the Group Leaders selector on the group edit screen.

The snippet

Roles are stored in the database, so create the role once rather than on every request. A mu-plugin that checks for the role before adding it is the usual pattern:

<?php
/**
 * Plugin Name: Mentor role for LearnDash
 * Description: Adds a Mentor role with group leader powers and post editing.
 */

defined( 'ABSPATH' ) || exit;

add_action(
    'init',
    function () {
        if ( get_role( 'mentor' ) ) {
            return;
        }

        $leader = get_role( 'group_leader' );
        $caps   = $leader ? $leader->capabilities : array(
            'read'                      => true,
            'group_leader'              => true,
            'wpProQuiz_show_statistics' => true,
            'level_0'                   => true,
            'level_1'                   => true,
        );

        // Extras for this role.
        $caps['edit_posts']           = true;
        $caps['edit_published_posts'] = true;
        $caps['upload_files']         = true;

        add_role( 'mentor', __( 'Mentor', 'wwc' ), $caps );
    },
    20
);

Copying the capabilities from the existing Group Leader role, when it exists, means your role tracks whatever LearnDash currently grants, including anything the Group Leader User settings have added. The fallback array mirrors the plugin's own definition for sites where the role was removed.

Why priority 20 on init

LearnDash registers its own role during activation and repairs it on init if missing. Running after it guarantees get_role( 'group_leader' ) returns the real role rather than null on the first load after activation.

Removing the role cleanly

If you later retire the role, reassign its users first, then call remove_role( 'mentor' ) once. Users left with a removed role have no role at all and cannot log in usefully, so the order matters.

Group Leader User settings still apply

LearnDash LMS > Settings > Groups > Group Leader User controls what leaders may do: manage their groups, manage courses, and manage users, each at a basic or advanced level. Two things happen when you save that screen. The on and off switches are read at runtime through learndash_get_group_leader_manage_groups() and its siblings, which apply to anyone passing the capability check, so a Mentor is covered. The editing capabilities behind each level, such as edit_courses or edit_users, are written with add_cap() to the built-in group_leader role only. Your role gets whatever was on the built-in role when it was copied, so after changing those settings either recreate the Mentor role or add the new capabilities with get_role( 'mentor' )->add_cap(). Our group leader role guide lists what each level grants.

Administrators and the capability check

Administrators have every capability, including group_leader, and LearnDash handles that by checking for admin first in most places. Do not give a custom role manage_options alongside group_leader unless you intend it to be an administrator in all but name; the role helper reference explains which checks treat which roles as privileged.

Assigning leaders programmatically

Being a Mentor does not put anyone in charge of a group. Leaders are stored as user meta per group, and the group edit screen lists users who pass the capability check. To assign in code use ld_update_leader_group_access( $user_id, $group_id ), the same function the admin uses; the group functions in our capability filters guide cover the surrounding hooks.

Testing

  1. Activate the mu-plugin, then open Users > Add New and confirm Mentor appears in the role dropdown.
  2. Create a Mentor, edit a group, and confirm the user can be selected as a leader.
  3. Log in as the Mentor. The LearnDash menu should show the group leader pages and Submitted Essays, and Posts should be editable.
  4. Open a group report and confirm only the Mentor's groups are listed.

When to get help

One extra role is a fifteen-minute job. A permission model with several tiers, roles that enable features in other plugins, or a migration of existing leaders into new roles is where a LearnDash developer saves time, and it is standard work for our LearnDash services team.

Frequently asked questions

Does LearnDash require the role to be named group_leader?

No. It checks the group_leader capability through learndash_is_group_leader_user(), so any role carrying that capability is treated as a group leader.

Can I rename the Group Leader role instead?

You can change its display name with a translation or a role editor, but creating a separate role is safer because LearnDash recreates its own role if it is missing or altered.

Will the Group Leader User settings apply to my custom role?

The permission checks apply to anyone passing the capability test. Capabilities those settings add are granted to the built-in role only, so copy or add them to your role when settings change.

Why do I have to add the role on init rather than on every page load?

Roles persist in the options table. Adding on every request is wasteful, and add_role() returns null when the role exists, so the early return keeps it to one write.

Add WorldWin Coder to your preferred sources

Add worldwincoder.com as a preferred source on Google, or open this article in your AI assistant to use it as a source.

· Developers and project managers

Articles written and reviewed by the developers and project managers at WorldWin Coder, who build and maintain websites, web applications and mobile apps on WordPress, Moodle, PHP, Laravel, CodeIgniter and Flutter.

Free consultation

Need help with LearnDash?

Tell us what you are working on. A developer who does this every week reads your message and replies within one business day with next steps and a free quote.

  • Free consultation and quote
  • NDA on request
  • You own the source code
  • Reply within one business day

Tell us about your project

Add budget and timeline optional, helps us quote faster

This form is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

Keep reading

Have something to build, fix or move?

Tell us where you are. A developer reads every inquiry, and you get next steps and a free quote within one business day.