uo_course_completion_time
Filters the course completion time before it is saved, allowing customization of how this value is determined.
add_filter( 'uo_course_completion_time', $callback, 10, 3 );
Description
Filters the course completion time for a specific user and course. Developers can modify the timestamp indicating when a user completed a course. This hook fires after retrieving the default completion time from user meta, allowing for custom logic or external data integration.
Usage
add_filter( 'uo_course_completion_time', 'your_function_name', 10, 3 );
Parameters
-
$completion_date(mixed) - This parameter contains the date and time when the course was completed.
-
$current_course(mixed) - The completion date of the course.
-
$current_user(mixed) - This parameter represents the current course object being processed.
Return Value
The filtered value.
Examples
/**
* Example: Adjust course completion time for specific courses.
*
* This filter allows you to modify the recorded completion time for a course.
* For example, you might want to manually set the completion time for older
* courses or courses imported from another system.
*
* @param mixed $current_time The current completion time (often from user meta).
* @param int $course_id The ID of the course.
* @param int $user_id The ID of the user.
* @return mixed The adjusted completion time.
*/
function my_custom_course_completion_time( $current_time, $course_id, $user_id ) {
// Example: For course ID 123, if the current completion time is empty,
// set it to a specific date (e.g., the start of the current year)
// as a fallback for legacy data.
if ( 123 === $course_id ) {
if ( empty( $current_time ) ) {
// Using mktime to get a timestamp for January 1st of the current year.
$fallback_timestamp = mktime( 0, 0, 0, 1, 1, date( 'Y' ) );
return $fallback_timestamp;
}
}
// For all other courses, return the original time without modification.
return $current_time;
}
add_filter( 'uo_course_completion_time', 'my_custom_course_completion_time', 10, 3 );
Placement
This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.
Source Code
src/classes/award-certificate.php:228
//Fallback
if ( empty( $completion_date ) ) {
$current_time = $this->ceu_crud->get_usermeta( $current_user->ID, 'course_completed_' . $current_course->ID, true );
$completion_date = ! empty( $current_time ) ? $current_time : time();
}
if ( null !== $current_course ) {
$completion_date = apply_filters( 'uo_course_completion_time', $completion_date, $current_course->ID, $current_user->ID );
}
// Store course completion CEU data
if ( $is_manual_creation && null === $current_course ) {
$course_slug = str_replace( '_', '-', sanitize_title( $current_course_title ) );
$insert = array(