uo_ceu_historical_quiz_recorded
Fires after a user's historical quiz attempt is recorded in the system.
add_action( 'uo_ceu_historical_quiz_recorded', $callback, 10, 1 );
Description
Fires after a user's historical quiz data has been successfully recorded. Developers can use this hook to perform custom actions, such as logging or further processing of quiz completion details, or integrating with other systems. The `$insert_data` parameter contains the recorded quiz information.
Usage
add_action( 'uo_ceu_historical_quiz_recorded', 'your_function_name', 10, 1 );
Parameters
-
$insert_data(mixed) - This parameter contains the data that is being inserted into the historical quiz records.
Examples
// Example function to hook into the 'uo_ceu_historical_quiz_recorded' action
function my_custom_ceu_recording_handler( $insert_data ) {
// This function will be executed whenever a historical quiz is recorded by the plugin.
// $insert_data will contain an array of the data that was inserted into the historical quiz table.
// Example: Log the recorded quiz data for debugging purposes.
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
error_log( 'UO CEU Historical Quiz Recorded:' );
error_log( print_r( $insert_data, true ) );
}
// Example: Award a custom badge or achievement if the user passed a specific quiz.
$user_id = $insert_data['user_id'];
$quiz_id = $insert_data['quiz_id'];
$passed = $insert_data['passed'];
// Replace with your actual badge awarding logic.
if ( $passed && $quiz_id === 123 ) { // Assuming quiz ID 123 is a specific one you want to track.
// award_custom_badge_to_user( $user_id, 'historical_quiz_master' );
error_log( "User ID {$user_id} passed historical quiz ID {$quiz_id} and earned a badge." );
}
// Example: Update a user meta field with the date of their latest historical quiz completion.
if ( ! empty( $insert_data['date_completed'] ) ) {
update_user_meta( $user_id, 'latest_historical_quiz_completion', $insert_data['date_completed'] );
}
}
// Hook the custom function to the action
add_action( 'uo_ceu_historical_quiz_recorded', 'my_custom_ceu_recording_handler', 10, 1 );
// 'uo_ceu_historical_quiz_recorded' is the action hook.
// 'my_custom_ceu_recording_handler' is the name of our callback function.
// 10 is the priority (default is 10). Lower numbers execute earlier.
// 1 is the number of arguments our function accepts. The hook passes $insert_data.
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/ceu-store-historical-data.php:184
src/classes/ceu-migrate-user-records.php:359
public function learndash_quiz_completed_func( $quiz_data, $user ) {
$statistic_ref_id = $quiz_data['statistic_ref_id'];
$quiz = $quiz_data['quiz'];
$course = $quiz_data['course'];
$lesson = $quiz_data['lesson'];
$topic = $quiz_data['topic'];
$pass = $quiz_data['pass'];
$score = $quiz_data['score'];
$count = $quiz_data['count'];
$time = $quiz_data['time'];
$store = $quiz_data;
unset( $store['quiz'] );
unset( $store['course'] );
unset( $store['lesson'] );
unset( $store['topic'] );
unset( $store['questions'] );
$course_id = is_object( $course ) ? $course->ID : $course;
$since = ld_course_access_from( $course_id, $user->ID );
if ( empty( $since ) ) {
$since = learndash_user_group_enrolled_to_course_from( $user->ID, $course_id );
}
$lesson_id = is_object( $lesson ) ? $lesson->ID : $lesson;
$topic_id = is_object( $topic ) ? $topic->ID : $topic;
$quiz_id = is_object( $quiz ) ? $quiz->ID : $quiz;
$insert_data = array(
'user_id' => $user->ID,
'statistic_ref_id' => $statistic_ref_id,
'course_id' => $course_id,
'lesson_id' => ! empty( $lesson_id ) ? $lesson_id : 0,
'topic_id' => ! empty( $topic_id ) ? $topic_id : 0,
'quiz_id' => ! empty( $quiz_id ) ? $quiz_id : 0,
'passed' => $pass,
'score' => $score,
'count' => $count,
'data' => maybe_serialize( $store ),
'certificate' => '',
'date_enrolled' => $since,
'date_completed' => $time,
);
global $wpdb;
$wpdb->insert(
$wpdb->prefix . self::$historical_quiz_table,
$insert_data,
array(
'%d',
'%d',
'%d',
'%d',
'%d',
'%d',
'%d',
'%d',
'%d',
'%s',
'%s',
'%s',
'%s',
)
);
self::copy_stat_records( $statistic_ref_id );
do_action( 'uo_ceu_historical_quiz_recorded', $insert_data );
}