uo_course_certificate_url
New filter added so that arguments can be passed. Adding arguments to previous filter above might break sites since there might be no argument supplied with override function Filters the URL for a course certificate, allowing customization of the link based on user, course, and certificate data.
add_filter( 'uo_course_certificate_url', $callback, 10, 3 );
Description
Fires after the certificate URL is generated, allowing modification of the URL, user, course ID, certificate post data, and timestamp. Use this filter to customize the certificate link before it's finalized, ensuring compatibility with existing setups that might not pass all arguments to older filters.
Usage
add_filter( 'uo_course_certificate_url', 'your_function_name', 10, 3 );
Parameters
-
$http_link(mixed) - - **$user** `mixed`
-
$course_id(mixed) - - **$certificate_post** `mixed`
-
$current_time_stamp(mixed)
Return Value
The filtered value.
Examples
/**
* Modify the course certificate URL to point to a custom storage location.
*
* This example demonstrates how to change the default URL for course certificates.
* It assumes certificates are stored in a custom directory within the WordPress uploads folder.
*
* @param string $http_link The original HTTP link to the certificate.
* @param WP_User $user The WP_User object of the user who completed the course.
* @param int $course_id The ID of the course.
* @param WP_Post $certificate_post The WP_Post object representing the certificate.
* @param int $current_time_stamp The timestamp when the certificate was generated.
* @return string The modified HTTP link to the certificate.
*/
add_filter( 'uo_course_certificate_url', function( $http_link, $user, $course_id, $certificate_post, $current_time_stamp ) {
// Define a base URL for custom certificate storage.
// This could be an external CDN, a different server, or a specific subdirectory.
$custom_base_url = trailingslashit( wp_upload_dir()['baseurl'] ) . 'course-certificates/';
// Construct the new URL based on user ID, course ID, and timestamp for uniqueness.
// Ensure user and course IDs are numeric to prevent potential injection issues.
if ( is_numeric( $user->ID ) && is_numeric( $course_id ) ) {
$modified_link = $custom_base_url . 'user-' . $user->ID . '/course-' . $course_id . '/' . $current_time_stamp . '/';
} else {
// Fallback to original link if user/course IDs are not valid.
$modified_link = $http_link;
}
return $modified_link;
}, 10, 5 );
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-completion-certificate.php:330
* to previous filter above might break sites since
* there might be no argument supplied with override function
*
* @since 3.6.4
* @author Saad
* @var $http_link
*/
$http_link = apply_filters( 'uo_course_certificate_url', $http_link, $user, $course_id, $certificate_post, self::$current_time_stamp );
$http_link_to_file = $http_link . $file_name . '.pdf';
do_action( 'uo_course_certificate_pdf_url', $http_link_to_file, $course_id, self::$current_time_stamp, $user_id );
$current_certs = get_user_meta( $user_id, $course_cert_meta, true );
if ( ! empty( $current_certs ) ) {
$current_certs[][ self::$current_time_stamp ] = $http_link_to_file;
update_user_meta( $user_id, $course_cert_meta, $current_certs );