uo_course_certificate_pdf_url
Fires after a course certificate PDF has been generated, providing its URL for further processing.
add_action( 'uo_course_certificate_pdf_url', $callback, 10, 4 );
Description
Fires after the course certificate PDF URL is generated. Developers can use this action hook to modify the PDF file URL or perform custom actions related to the certificate generation process before it's saved or displayed. It provides the full PDF URL, course ID, timestamp, and user ID.
Usage
add_action( 'uo_course_certificate_pdf_url', 'your_function_name', 10, 4 );
Parameters
-
$http_link_to_file(mixed) - This parameter contains the HTTP link to the generated PDF certificate file.
-
$course_id(mixed) - This parameter contains the full HTTP link to the generated PDF certificate file.
-
$current_time_stamp(mixed) - This parameter contains the ID of the course for which the certificate is being generated.
-
$user_id(mixed) - This parameter contains a timestamp representing the current time, likely used for generating unique file names or for tracking when the certificate was generated.
Examples
<?php
/**
* Example function to hook into 'uo_course_certificate_pdf_url' action.
* This function might log the generated certificate URL or perform other actions
* when a course certificate PDF URL is generated.
*/
add_action( 'uo_course_certificate_pdf_url', 'my_custom_course_certificate_logging', 10, 4 );
/**
* Logs the generated course certificate PDF URL.
*
* @param string $http_link_to_file The full HTTP link to the generated PDF certificate.
* @param int $course_id The ID of the course for which the certificate was generated.
* @param string $current_time_stamp The timestamp when the certificate was generated.
* @param int $user_id The ID of the user who completed the course.
*/
function my_custom_course_certificate_logging( $http_link_to_file, $course_id, $current_time_stamp, $user_id ) {
// Ensure the user is logged in to perform logging actions or check permissions.
if ( is_user_logged_in() ) {
// Get the user object for potential further information.
$user_info = get_user_by( 'id', $user_id );
// Log the event using WordPress's built-in logging mechanism (or a custom one).
// In a real-world scenario, you might use a more robust logging library.
error_log( sprintf(
'Course certificate generated for User ID: %d (%s), Course ID: %d. PDF URL: %s',
$user_id,
$user_info ? $user_info->user_login : 'N/A',
$course_id,
$http_link_to_file
) );
// Example: You could also add this URL to another meta field for quick access.
// Note: Be cautious with updating user meta here, as it might conflict
// with the plugin's own meta management. This is just an illustrative example.
// $existing_urls = get_user_meta( $user_id, 'generated_certificate_urls', true );
// if ( ! is_array( $existing_urls ) ) {
// $existing_urls = array();
// }
// $existing_urls[] = array(
// 'course_id' => $course_id,
// 'timestamp' => $current_time_stamp,
// 'pdf_url' => $http_link_to_file,
// );
// update_user_meta( $user_id, 'generated_certificate_urls', $existing_urls );
}
}
?>
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:332
*
* @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 );
} else {
$certs[][ self::$current_time_stamp ] = $http_link_to_file;