LLMS_Grades::get_grade( WP_Post|int $post_id, LLMS_Student $student, bool $use_cache = true )
Main grade getter function
Description Description
Uses caching by default and can bypass cache when requested
Parameters Parameters
- $post_id
-
(WP_Post|int) (Required) An instance of WP_Post or a WP Post ID.
- $student
-
(LLMS_Student) (Required) A LLMS_Student object.
- $use_cache
-
(bool) (Optional) when true, retrieves from cache if available
Default value: true
Return Return
(float|null)
Source Source
File: includes/class-llms-grades.php
public function get_grade( $post_id, $student, $use_cache = true ) {
$post = llms_get_post( $post_id );
$student = llms_get_student( $student );
$grade = $use_cache ? $this->get_grade_from_cache( $post, $student ) : false;
// Grade not found in cache or we're not using the cache.
if ( false === $grade ) {
$grade = $this->calculate_grade( $post, $student );
// Store in the cache.
wp_cache_set(
sprintf( '%d_grade', $post->get( 'id' ) ),
$grade,
sprintf( 'student_%d', $student->get( 'id' ) )
);
}
return apply_filters( 'llms_get_grade', $grade, $post, $student );
}
Expand full source code Collapse full source code View on GitHub
Changelog Changelog
| Version | Description |
|---|---|
| 4.4.4 | Don't pass the $use_cache parameter to the calculate_grade() method. |
| 3.24.0 | Introduced. |