Last active
November 9, 2015 08:22
-
-
Save dwainm/9ad2c7b3ccc4288fa6c3 to your computer and use it in GitHub Desktop.
Add the code to your functions.php . This will create a notice with a button on the admin learning grading page. This will make sure the questions that you see in grading are the actual question submitted by the user. It is a work around for this bug: https://github.com/woothemes/sensei/issues/803
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php // do not include this fir line with php as it will break your site, it was only added for styling | |
add_action('admin_init','sensei_custom_code_reset_questions_asked'); | |
function sensei_custom_code_reset_questions_asked(){ | |
if( ! isset( $_POST['sensei_custom_code_reset_questions_asked'] ) | |
|| ! ( isset( $_POST['sensei_custom_code_reset_questions_asked_nonce'] ) | |
&& wp_verify_nonce( $_POST['sensei_custom_code_reset_questions_asked_nonce'], 'sensei_custom_code_reset_questions_asked_for_user' ) ) | |
){ | |
return; | |
} | |
$user_id = sanitize_text_field( $_POST['sensei_custom_code_reset_questions_asked_user_id'] ); | |
$quiz_id = sanitize_text_field( $_POST['sensei_custom_code_reset_questions_asked_quiz_id'] ); | |
$lesson_id = Sensei()->quiz->get_lesson_id( $quiz_id ); | |
$question_answers = Sensei()->quiz->get_user_answers( $lesson_id, $user_id ); | |
// setup new questions asked string based on the questions submitted for this user | |
$new_questions_asked_string = implode(',', array_keys( $question_answers ) ); | |
$user_lesson_status = WooThemes_Sensei_Utils::user_lesson_status( $lesson_id , $user_id ); | |
update_comment_meta( $user_lesson_status->comment_ID, 'questions_asked', $new_questions_asked_string ); | |
} | |
add_action('admin_notices','sensei_custom_code_reset_questions_asked_form'); | |
function sensei_custom_code_reset_questions_asked_form() { | |
$screen = get_current_screen(); | |
if( 'sensei_page_sensei_grading' != $screen->id | |
|| !isset( $_GET['user'] ) || empty( $_GET['user'] ) | |
|| !isset( $_GET['quiz_id'] ) || empty( $_GET['quiz_id'] ) ){ | |
return; | |
} | |
?> | |
<div class="notice"> | |
<form method="post" action="<?php Sensei_Utils::get_current_url() ?>"> | |
<p> | |
Click here to rest the questions asked string for this user to ensure that this grading page shows the answers the user submitted. | |
<?php wp_nonce_field('sensei_custom_code_reset_questions_asked_for_user','sensei_custom_code_reset_questions_asked_nonce'); ?> | |
<input type="hidden" name="sensei_custom_code_reset_questions_asked_user_id" value="<?php esc_attr_e( $_GET['user'] ) ?>" /> | |
<input type="hidden" name="sensei_custom_code_reset_questions_asked_quiz_id" value="<?php esc_attr_e( $_GET['quiz_id'] ) ?>" /> | |
<input value="Reset Questions" type="submit" class="button" name="sensei_custom_code_reset_questions_asked" /> | |
</p> | |
</form> | |
</div> | |
<?php | |
} // End admin_install_notice() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment