Alert: This function’s access is marked private. This means it is not intended for use by plugin or theme developers, only in other core functions. It is listed here for completeness.

LLMS_Roles::update_caps( WP_Role $role, string $type = 'add', string[] $exclude_groups = array() )

Update the capabilities for a given role


Parameters Parameters

$role

(WP_Role) (Required) Role object.

$type

(string) (Optional) Update type [add|remove].

Default value: 'add'

$exclude_groups

(string[]) (Optional) Array of groups to exclude.

Default value: array()


Top ↑

Return Return

(void)


Top ↑

Source Source

File: includes/class.llms.roles.php

	private static function update_caps( $role, $type = 'add', $exclude_groups = array() ) {

		$role_caps = self::get_all_caps( $role->name );
		$role_caps = empty( $exclude_groups ) ? $role_caps : array_diff_key( $role_caps, array_flip( $exclude_groups ) );

		foreach ( $role_caps as $group => $caps ) {

			foreach ( array_keys( $caps ) as $cap ) {

				if ( 'add' === $type ) {
					$role->add_cap( $cap );
				} elseif ( 'remove' === $type ) {
					$role->remove_cap( $cap );
				}
			}
		}

	}


Top ↑

Changelog Changelog

Changelog
Version Description
4.5.1 Added $exclude_group parameter that allows excluding groups of caps from the update.
3.13.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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