uo_course_timer_enabled
Filters whether the course timer is enabled for a specific course.
add_filter( 'uo_course_timer_enabled', $callback, 10, 1 );
Description
Filters whether the course timer is enabled. Use this hook to programmatically enable or disable the course timer for specific courses. It fires before the timer's status is determined. The `$course_id` parameter is available for conditional logic.
Usage
add_filter( 'uo_course_timer_enabled', 'your_function_name', 10, 1 );
Parameters
-
$course_id(mixed) - This parameter indicates whether the course timer is enabled by default.
Return Value
The filtered value.
Examples
/**
* Disable the course timer for specific courses.
*
* This function hooks into the 'uo_course_timer_enabled' filter and returns false
* if the current course ID is in a predefined array of courses where the timer
* should be disabled. Otherwise, it lets the original filter value pass through.
*
* @param bool $enabled The current status of the course timer (true by default).
* @param int $course_id The ID of the current course being checked.
* @return bool Whether the course timer should be enabled for this course.
*/
function my_custom_disable_course_timer( $enabled, $course_id ) {
// Array of course IDs where the timer should be disabled.
$courses_to_disable_timer = array( 123, 456, 789 );
// Check if the current course ID is in the exclusion list.
if ( in_array( $course_id, $courses_to_disable_timer, true ) ) {
return false; // Disable the timer for this course.
}
// Otherwise, keep the default enabled status.
return $enabled;
}
add_filter( 'uo_course_timer_enabled', 'my_custom_disable_course_timer', 10, 2 );
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/course-timer.php:915
public static function is_course_timer_enabled( $course_id ) {
return (bool) apply_filters( 'uo_course_timer_enabled', true, $course_id );
}