uo_quiz_certificate_url
Fires after a quiz certificate is generated, allowing customization of its URL before display.
add_action( 'uo_quiz_certificate_url', $callback, 10, 6 );
Description
Fires after a quiz certificate PDF is generated, providing the HTTP URL to the file. Developers can modify this URL or perform actions related to the certificate's availability. Parameters include the generated file URL, quiz details, results, certificate ID, current user, and timestamp.
Usage
add_action( 'uo_quiz_certificate_url', 'your_function_name', 10, 6 );
Parameters
-
$http_link_to_file(mixed) - This parameter holds the generated HTTP link to the PDF certificate file.
-
$quiz_post(mixed) - This parameter contains the HTTP URL where the generated certificate PDF file can be accessed.
-
$quiz_results(mixed) - This parameter contains the WordPress post object for the quiz.
-
$certificate_id(mixed) - This parameter contains the user's results for the quiz, specifically the completion status.
-
$current_user(mixed) - This parameter contains the ID of the certificate that was generated.
-
$current_time(mixed) - This parameter contains the WordPress user object for the currently logged-in user.
Examples
/**
* Filters the URL of the generated quiz certificate.
*
* This function can be used to modify the default HTTP link to the generated
* PDF certificate, for example, to host it on a CDN or to add specific query
* parameters.
*
* @param string $http_link_to_file The default HTTP link to the PDF certificate.
* @param WP_Post $quiz_post The WordPress Post object for the quiz.
* @param array $quiz_results An array containing the user's quiz results.
* @param int $certificate_id The ID of the generated certificate.
* @param WP_User $current_user The current logged-in WordPress user object.
* @param string $current_time A string representing the current time.
*
* @return string The modified or original HTTP link to the certificate.
*/
add_action( 'uo_quiz_certificate_url', function ( $http_link_to_file, $quiz_post, $quiz_results, $certificate_id, $current_user, $current_time ) {
// Example: Append a timestamp to the URL for cache busting.
// In a real-world scenario, you might want to check if this is necessary
// based on plugin settings or other conditions.
$modified_url = $http_link_to_file . '?v=' . time();
// You could also perform more complex logic here, such as:
// - Checking if the certificate is hosted on a CDN and adjusting the URL.
// - Adding authentication tokens or other parameters if required by your setup.
// - Returning an empty string or a custom URL if the certificate generation failed
// and you want to indicate that it's not available.
return $modified_url;
}, 10, 6 );
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/generate-p-d-f-email.php:171
$quiz_results = $_post['results']['comp'];
$current_time = self::$current_time_stamp;
do_action( 'uo_quiz_certificate', $path_on_server, $quiz_post, $quiz_results, $certificate_id, $current_user, $current_time );
//$http_link_to_file = WP_CONTENT_URL . '/uploads/user-certificates/' . $file_name . '.pdf';
$http_link_to_file = apply_filters( 'uo_quiz_certificate_http_url', WP_CONTENT_URL . '/uploads/user-certificates/' . $file_name . '.pdf' );
do_action( 'uo_quiz_certificate_url', $http_link_to_file, $quiz_post, $quiz_results, $certificate_id, $current_user, $current_time );
$course_id = $setup_parameters['course-id'];
$meta_name = '_sfwd-quizzes-pdf-quiz-' . $course_id;
//Retrieve any existing certificates from USER
$certs = array();
$current_certs = get_user_meta( $current_user->ID, $meta_name, true );