Filter uncanny-learndash-groups

ulgm_permissions_callback_message

Filters the message displayed when a user lacks permission to manage groups.

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

Description

Filters the default permission denied message for group management. Developers can override this message to provide custom feedback to users who lack the necessary roles (administrator, group_leader, ulgm_group_management, super_admin) to manage Uncanny Groups. This hook fires when a user attempts to access group management features without sufficient privileges.


Usage

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

Return Value

The filtered value.


Examples

/**
 * Example of how to use the ulgm_permissions_callback_message filter.
 *
 * This example demonstrates how to modify the default permission denied message
 * for users attempting to manage groups without proper authorization.
 *
 * @param string $message The default permission denied message.
 * @return string The modified permission denied message.
 */
add_filter( 'ulgm_permissions_callback_message', 'my_custom_ulgm_permissions_message', 10, 1 );

function my_custom_ulgm_permissions_message( $message ) {
    // Check if the current user has a specific custom capability that might grant access
    // even if their role isn't explicitly listed in the allowed roles.
    if ( current_user_can( 'can_bypass_group_management_restrictions' ) ) {
        // If they have this special capability, let's allow them and return an empty message
        // or a more permissive one. For this example, we'll return an empty string
        // which might be handled by the calling function to proceed.
        return '';
    }

    // Otherwise, return a more specific error message that includes the user's current role(s)
    // to help them understand why they were denied.
    $current_user = wp_get_current_user();
    $user_roles = implode( ', ', $current_user->roles );

    return sprintf(
        __( 'Access Denied: Your role(s) (%s) do not have permission to manage groups. Please contact an administrator.', 'uncanny-learndash-groups' ),
        esc_html( $user_roles )
    );
}

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/group-management/group-management-interface.php:720

'administrator',
				'group_leader',
				'ulgm_group_management',
				'super_admin',
			)
		);
		if ( ! learndash_is_group_leader_user( $group_leader_id ) && empty( array_intersect( $allowed_roles, wp_get_current_user()->roles ) ) ) {
			$validation['message'] = apply_filters( 'ulgm_permissions_callback_message', __( 'You do not have permission to manage groups.', 'uncanny-learndash-groups' ) );

			return $validation;
		}

		$group_leader_groups = SharedFunctions::get_group_leader_groups( $group_leader_id );

		if ( empty( $group_leader_groups ) ) {


Scroll to Top