uo_quiz_completion_time
Fires when a quiz is completed, providing the completion time and related post data.
add_action( 'uo_quiz_completion_time', $callback, 10, 2 );
Description
Fires after a quiz is completed and before a certificate is generated or saved. Developers can use this hook to log completion times, perform custom actions based on completion, or modify time-related data before further processing. The current timestamp and quiz post ID are passed to the hook.
Usage
add_action( 'uo_quiz_completion_time', 'your_function_name', 10, 2 );
Parameters
-
$current_time_stamp(mixed) - This parameter holds the timestamp representing when the quiz was completed.
-
$post(mixed) - This parameter holds the timestamp representing when the quiz was completed.
Examples
add_action( 'uo_quiz_completion_time', function( $current_time_stamp, $post_id ) {
// This function is triggered when a quiz is completed and the completion time is recorded.
// It can be used to log the completion time for analytics, trigger further actions,
// or store additional data related to the quiz completion.
// Example: Log the quiz completion time to the WordPress debug log.
if ( WP_DEBUG === true ) {
error_log( sprintf(
'User completed quiz (Post ID: %d) at %s',
$post_id,
date( 'Y-m-d H:i:s', $current_time_stamp ) // Assuming $current_time_stamp is a Unix timestamp
) );
}
// Example: You could also use this to update a user meta field with the last quiz completion time.
// global $current_user;
// if ( $current_user && $current_user->ID ) {
// update_user_meta( $current_user->ID, 'last_quiz_completion_time_' . $post_id, $current_time_stamp );
// }
}, 10, 2 ); // Priority 10, accepts 2 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/generate-p-d-f-email.php:118
/* IF Print Certificate is allowed ( logic grabbed from Quiz Pro Print Certificate Part ) */
if ( 1 !== (int) $setup_parameters['print-certificate'] ) {
return $email_params;
}
self::$current_time_stamp = $current_time;
do_action( 'uo_quiz_completion_time', self::$current_time_stamp, $post->ID );
$certificate_post = $setup_parameters['certificate-post'];
$save_path = apply_filters( 'uo_quiz_certificate_save_path', WP_CONTENT_DIR . '/uploads/user-certificates/' );
$completion_time = self::$current_time_stamp;
$quiz_title = html_entity_decode( get_the_title( $post->ID ) );
/* Creating a fileName that is going to be stored on the server. Certificate-QUIZID-USERID-NONCE_String */
$file_name = sanitize_title( $current_user->ID . '-' . $quiz_title . '-' . wp_create_nonce( $completion_time ) );