LLMS_User_Permissions::editable_roles( array $all_roles )

Determines what other user roles can be managed by a user role


Description Description

Allows LMS Managers to create instructors and other managers. Allows instructors to create & manage assistants.


Top ↑

Parameters Parameters

$all_roles

(array) (Required) All roles array.


Top ↑

Return Return

(array)


Top ↑

Source Source

File: includes/class.llms.user.permissions.php

	public function editable_roles( $all_roles ) {

		/**
		 * Prevent issues when other plugins call get_editable_roles() before `init`.
		 *
		 * @link https://github.com/gocodebox/lifterlms/issues/1727
		 */
		if ( ! function_exists( 'wp_get_current_user' ) ) {
			return $all_roles;
		}

		if ( is_multisite() && is_super_admin() ) {
			return $all_roles;
		}

		$user       = wp_get_current_user();
		$user_roles = $user->roles;

		if ( in_array( 'administrator', $user_roles, true ) ) {
			return $all_roles;
		}

		$editable_roles = self::get_editable_roles();

		if ( empty( array_intersect( $user_roles, array_keys( $editable_roles ) ) ) ) {
			return $all_roles;
		}

		$roles = array();
		foreach ( $user_roles as $user_role ) {
			if ( isset( $editable_roles[ $user_role ] ) ) {
				$roles = array_merge( $roles, $editable_roles[ $user_role ] );
			}
		}

		$roles = array_unique( $roles );

		foreach ( array_keys( $all_roles ) as $role ) {
			if ( ! in_array( $role, $roles, true ) ) {
				unset( $all_roles[ $role ] );
			}
		}

		return $all_roles;

	}


Top ↑

Changelog Changelog

Changelog
Version Description
4.10.0 Better handling of users with multiple roles.
3.37.14 Use strict comparison.
3.34.0 Moved the llms_editable_roles filter to the class method get_editable_roles().
3.13.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

You must log in before being able to contribute a note or feedback.