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_User_Permissions::handle_cap_view_grades( bool[] $allcaps, array $args )

Modify a users ability to view_grades


Description Description

Users can view the grades (quiz results) if one of the following conditions is met:

  • Users can view their own grades.
  • Admins and LMS Managers can view anyone’s grade.
  • Any user who has been explicitly granted the view_grades cap can view anyone’s grade (via custom code).
  • Any instructor/assistant who can edit_post for the course the quiz belongs to can view grades of the students within that course.

Top ↑

Parameters Parameters

$allcaps

(bool[]) (Required) Array of key/value pairs where keys represent a capability name and boolean values represent whether the user has that capability.

$args

(array) (Required) Arguments that accompany the requested capability check.

  • (string) Requested capability: 'view_grades'.
  • '1'
    (int) Current User ID.
  • '2'
    (int) Requested User ID.
  • '3'
    (int) WP_Post ID of the quiz.


Top ↑

Return Return

(array)


Top ↑

Source Source

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

	private function handle_cap_view_grades( $allcaps, $args ) {

		// Logged out user or missing required args.
		if ( empty( $args[1] ) || empty( $args[2] ) || empty( $args[3] ) ) {
			return $allcaps;
		}

		list( $requested_cap, $current_user_id, $requested_user_id, $post_id ) = $args;

		// Administrators and LMS managers explicitly have the cap so we don't need to perform any further checks.
		if ( ! empty( $allcaps[ $requested_cap ] ) ) {
			return $allcaps;
		}

		// Users can view their own grades.
		if ( $current_user_id === $requested_user_id ) {
			$allcaps[ $requested_cap ] = true;
		} elseif ( current_user_can( 'edit_post', $post_id ) ) {
			$instructor = llms_get_instructor( $current_user_id );
			if ( $instructor && $instructor->has_student( $requested_user_id ) ) {
				$allcaps[ $requested_cap ] = true;
			}
		}

		return $allcaps;

	}


Top ↑

Changelog Changelog

Changelog
Version Description
4.21.2 Introduced.

Top ↑

User Contributed Notes User Contributed Notes

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