Hi ahmedtalaat,
unfortunately, HD Quiz does not have any built in member functions, so this is not something that HD Quiz does natively.
There is also a “pro” version of HD Quiz Save Results addon in development that will have this functionality, but release of that is ~ a month away.
However, you can always code your won solution in if you need this sooner than later. The latest version includes hooks that will allow you or any developer to extend HD Quiz to the way you want.
You take a look at this older thread to get an idea on the logic of what you need, but use the new hooks.
You can use the new hdq_before
and hdq_submit
hooks to run the needed functions.
Example: please note that I have not tested this… and it’s just an example to help you or anyone else who finds this thread.
<?php
// This tells HDQuiz to send quiz data to a function called
// "hdq_save_result_to_user_profile_action"
function hdq_save_result_to_user_profile($quizOptions)
{
array_push($quizOptions->hdq_submit, "hdq_save_result_to_user_profile_action");
return $quizOptions;
}
add_action('hdq_submit', 'hdq_save_result_to_user_profile');
// This is the function that recieves the quiz data
function hdq_save_result_to_user_profile_action($data)
{
// if the user it not logged in, do not continue
if (!is_user_logged_in()) {
die();
}
// santize the score for security
function hdq_a_i_validate_score($score)
{
return intval($score);
}
// get quiz results and meta
$result = new stdClass();
$quizID = intval($_POST['data']["quizID"]);
$result->quizID = $quizID;
$score = array_map('hdq_a_i_validate_score', $_POST['data']["score"]);
$result->score = $score;
// get quiz meta
$hdq_quiz_options = hdq_get_quiz_options($quizID);
$passPercent = intval($hdq_quiz_options["passPercent"]);
$result->passPercent = $passPercent;
// get quiz term info
$term = get_term($quizID, "quiz");
$quizName = $term->name;
$result->quizName = $quizName;
// get current logged in user info
$current_user = wp_get_current_user();
// follow my previously posted thread to continue...
}
add_action('wp_ajax_hdq_save_result_to_user_profile_action', 'hdq_save_result_to_user_profile_action');
add_action('wp_ajax_nopriv_hdq_save_result_to_user_profile_action', 'hdq_save_result_to_user_profile_action');