uo_show_course_certificate_link
Filters the course certificate link, allowing modification before it's displayed for a user.
add_filter( 'uo_show_course_certificate_link', $callback, 10, 2 );
Description
Allows developers to modify the course certificate link HTML. The filter receives the generated link, the current user, and the course object. Use this to customize the appearance or behavior of the certificate link displayed on the frontend.
Usage
add_filter( 'uo_show_course_certificate_link', 'your_function_name', 10, 2 );
Parameters
-
$certificate_link(mixed) - This parameter contains the HTML link to the course certificate, which can be modified by the filter.
-
$course(mixed) - This parameter represents the currently logged-in user object.
Return Value
The filtered value.
Examples
add_filter( 'uo_show_course_certificate_link', function( $certificate_link, $current_user, $course ) {
// Example: If the current user is an administrator, always display the certificate link.
// Otherwise, check if the user has completed the course to show the link.
if ( user_can( $current_user->ID, 'manage_options' ) ) {
return $certificate_link;
}
// Assuming 'learndash_course_completed' is a function that checks if a user has completed a course.
// This is a placeholder, replace with actual LeardDash or custom logic.
if ( function_exists( 'learndash_course_completed' ) && learndash_course_completed( $course->ID, $current_user->ID ) ) {
return $certificate_link;
}
// If the user is not an administrator and has not completed the course, hide the link.
return false;
}, 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/show-certificates-shortcode.php:194
} else {
$certificate_title = $course->post_title;
}
$certificate_link = esc_url( learndash_get_course_certificate_link( $course->ID ) );
if ( $certificate_link && '' !== $certificate_link ) {
$link = apply_filters( 'uo_show_course_certificate_link', sprintf( '<a target="_blank" href="%s">%s</a>', $certificate_link, esc_html( $certificate_title ) ), wp_get_current_user(), $course );
$certificate_list .= $link . '<br>';
}
}
}
}
/* GET Certificates for Quizzes*/