LLMS_Admin_Users_Table::modify_views( array $views )

Modify the list of role “view” filter links at the top of the user table.


Description Description

An instructor can only manage instructors and instructor’s assistants so we’ll remove these links from the list and additionally modify the count on the "All" filter to reflect the total number of users who are visible to the current instructor.


Top ↑

Parameters Parameters

$views

(array) (Required) Associative array of views where the key is the role name and the value is the HTML for the view link.


Top ↑

Return Return

(array)


Top ↑

Source Source

File: includes/admin/class-llms-admin-users-table.php

	public function modify_views( $views ) {

		if ( LLMS_User_Permissions::is_current_user_instructor() ) {

			$users = count_users();

			// Allow the instructor to see roles they're allowed to edit.
			$all_roles = LLMS_User_Permissions::get_editable_roles();
			$roles     = array_merge( array( 'all', 'instructor' ), $all_roles['instructor'] );

			$all = 0;

			foreach ( array_keys( $views ) as $view ) {
				if ( ! in_array( $view, $roles, true ) ) {
					// Unset any views they're not allowed to edit.
					unset( $views[ $view ] );
				} elseif ( ! empty( $users['avail_roles'][ $view ] ) ) {
					// Add roles they're allowed to view to the new all count.
					$all += $users['avail_roles'][ $view ];
				}
			}

			// Replace the count on the "All" link with our updated count.
			$format       = '<span class="count">(%s)</span>';
			$views['all'] = str_replace( sprintf( $format, $users['total_users'] ), sprintf( $format, $all ), $views['all'] );

		}

		return $views;
	}


Top ↑

Changelog Changelog

Changelog
Version Description
3.34.0 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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