uo_dashboard_user_courses
Filters the list of user courses displayed on the dashboard, allowing for modifications before rendering.
add_filter( 'uo_dashboard_user_courses', $callback, 10, 2 );
Description
Filters the user's courses before they are displayed on the dashboard. Developers can modify the `$user_courses` array to customize which courses are shown, alter their order, or add/remove data. Fires after the user's courses have been retrieved.
Usage
add_filter( 'uo_dashboard_user_courses', 'your_function_name', 10, 2 );
Parameters
-
$user_courses(mixed) - - **$user_id** `mixed`
-
$atts(mixed)
Return Value
The filtered value.
Examples
/**
* Example function to modify the user courses displayed on the Uncanny Owl dashboard.
* This could be used to filter out specific courses or add custom course data.
*
* @param array $user_courses An array of user course data.
* @param int $user_id The ID of the current user.
* @param array $atts Attributes passed to the shortcode.
* @return array Modified array of user course data.
*/
add_filter( 'uo_dashboard_user_courses', function( $user_courses, $user_id, $atts ) {
// Example: If the user is an administrator, always show all courses,
// otherwise, filter out any courses that are not yet started.
if ( current_user_can( 'administrator' ) ) {
return $user_courses; // Admins see everything.
}
// If it's not an admin, filter out courses that haven't been started.
// Assuming $user_courses is an array where each element might have a 'status' key.
$filtered_courses = array_filter( $user_courses, function( $course_data ) {
// This is a hypothetical check. The actual structure of $course_data
// will depend on the LearnDash and Uncanny Owl plugin implementations.
// We're assuming a 'status' key that could be 'not_started', 'in_progress', etc.
if ( isset( $course_data['status'] ) && $course_data['status'] === 'not_started' ) {
return false; // Exclude courses that haven't been started.
}
return true; // Keep all other courses.
} );
// Ensure the keys are re-indexed if necessary after filtering.
return array_values( $filtered_courses );
}, 10, 3 ); // Priority 10, accepts 3 arguments.
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/learn-dash-my-courses.php:618
if ( $file_path === $uncanny_tempalate ) {
$support_deprecated_template = false;
}
/**
* @since 3.7.10
*/
$user_courses = apply_filters( 'uo_dashboard_user_courses', $user_courses, $user_id, $atts );
$courses = self::set_up_course_object( $user_courses, $user_id, $quiz_attempts, $support_deprecated_template );
if ( isset( $atts['expand_by_default'] ) && 'yes' === $atts['expand_by_default'] ) {
$expanded_on_load = true;
} else {
$expanded_on_load = false;
}