Filter uncanny-learndash-groups

ulgm_gm_allowed_roles

Filters the allowed roles for accessing group management features, allowing customization of user permissions.

add_filter( 'ulgm_gm_allowed_roles', $callback, 10, 1 );

Description

This filter hook, ulgm_gm_allowed_roles, allows developers to modify the array of WordPress roles that are permitted to access group management features. It fires when the allowed roles are being determined, enabling customization of role-based permissions for group management interfaces and reports. Developers can add or remove roles from the default list, which includes administrator, manage_options, group_leader, ulgm_group_management, and super_admin.


Usage

add_filter( 'ulgm_gm_allowed_roles', 'your_function_name', 10, 1 );

Return Value

The filtered value.


Examples

// Filter to add 'editor' role to the allowed roles for group management.
function my_custom_allowed_group_management_roles( $allowed_roles ) {
	// Check if the current user has the 'editor' role and add it to the allowed roles.
	if ( user_can( get_current_user_id(), 'editor' ) ) {
		$allowed_roles[] = 'editor';
	}
	return $allowed_roles;
}
add_filter( 'ulgm_gm_allowed_roles', 'my_custom_allowed_group_management_roles', 10, 1 );

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/classes/reports/learndash-progress-report.php:2189
src/classes/admin/class-admin-create-group.php:182
src/classes/reports/group-reports-interface.php:241
src/classes/reports/group-quiz-report.php:265
src/classes/group-management/class-edit-group-wizard.php:82
src/classes/reports/group-assignments.php:156
src/classes/group-management/group-management-interface.php:339
src/classes/group-management/group-management-interface.php:389
src/classes/group-management/group-management-interface.php:443
src/classes/group-management/group-management-interface.php:710
src/classes/reports/group-essays.php:152
src/classes/helpers/rest-api-end-points.php:1494

public static function current_user_has_allowed_role() {

		if ( ! is_user_logged_in() ) {
			return false;
		}

		$allowed_roles = apply_filters(
			'ulgm_gm_allowed_roles',
			array(
				'administrator',
				'manage_options',
				'group_leader',
				'ulgm_group_management',
				'super_admin',
			)
		);

		return ! empty( array_intersect( wp_get_current_user()->roles, $allowed_roles ) );
	}


Scroll to Top