llms_current_user_can( string $cap, int $obj_id = null )
Checks LifterLMS user capabilities against an object
Description Description
Parameters Parameters
- $cap
-
(string) (Required) capability name
- $obj_id
-
(int) (Optional) WP_Post or WP_User ID
Default value: null
Return Return
(boolean)
Source Source
File: includes/functions/llms.functions.person.php
function llms_current_user_can( $cap, $obj_id = null ) { $caps = LLMS_Roles::get_all_core_caps(); $grant = false; if ( in_array( $cap, $caps ) ) { // if the user has the cap, maybe do some additional checks if ( current_user_can( $cap ) ) { switch ( $cap ) { case 'view_lifterlms_reports': // can view others reports so its okay if ( current_user_can( 'view_others_lifterlms_reports' ) ) { $grant = true; // can only view their own reports check if the student is their instructor } elseif ( $obj_id ) { $instructor = llms_get_instructor(); $student = llms_get_student( $obj_id ); if ( $instructor && $student ) { foreach ( $instructor->get_posts( array( 'posts_per_page' => -1, ), 'ids' ) as $id ) { if ( $student->get_enrollment_status( $id ) ) { $grant = true; break; } } } } break; // no other checks needed default: $grant = true; } } }// End if(). return apply_filters( 'llms_current_user_can_' . $cap, $grant, $obj_id ); }
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
Version | Description |
---|---|
3.13.0 | Introduced. |
User Contributed Notes User Contributed Notes
Permalink: