Automattic / sensei

Sensei LMS - Online Courses, Quizzes, & Learning
https://senseilms.com
GNU General Public License v2.0
536 stars 197 forks source link

Allowing Visual Editor in quiz answer corrections #2268

Open AiramMontessori opened 5 years ago

AiramMontessori commented 5 years ago

Steps to Reproduce

  1. Submit a quiz
  2. Login as a teacher of the lesson and grade the quiz
  3. In the "grading comments" next to each question, you can only add plain text (with HTML tags). But every time you want to add a line break in your comments, you need to add a <br>, every time you need to add a link or an image, you need to add the appropriate HTML code. Not pratical when you have dozens of quiz to grade per day!

What I Expected

TinyMCE editor on these textarea

What Happened Instead

Just plain text area that prevent us from formatting our answers properly

PHP / WordPress / Sensei version

Sensei 1.10.1 (haven't seen this fix in the lastest releases)

Browser / OS version

Chrome

Screenshot / Video

Context / Source

The responsible line of code is the line 235 in includes/class-sensei-grading-user-quiz.php I've tried to replace

<textarea class="correct-answer" name="questions_feedback[<?php echo esc_attr( $question_id ); ?>]" placeholder="<?php _e( 'Add notes here...', 'woothemes-sensei' ) ?>"><?php echo $question_answer_notes; ?></textarea>

by

<?php $editor_id = "questions_feedback[". esc_attr( $question_id )."]"; $settings = array( $editor_id => 'post_text' ); wp_editor($question_answer_notes,$editor_id,$settings); ?>

But no luck, the wysiwig is not working as expected. I'm not a pro in Wordpress ;). Thanks!

AiramMontessori commented 5 years ago

Well I've made some futher test and actually if you replace the line 235 mentioned above by:

<?php $editor_id_tmp = "questions_feedback[". esc_attr( $question_id )."]"; $editor_id = esc_attr( $question_id ); $settings = array( 'textarea_name' => $editor_id_tmp ); wp_editor($question_answer_notes,$editor_id,$settings); ?>

The visual editor works fine with link and media addition. Credits goes to this post

Only things not working is the line breaks and paragraph breaks unfortenately as I think the filter being applied on the front-end output

echo apply_filters( 'sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id );

in class-sensei-question.php escapes those. Any way to disable this escaping and just show the proper HTML notes?

AiramMontessori commented 5 years ago

I'm doing a monolog here, but I've found the fix. I think it would be an easy fix for you to implement in the next main release as nobody can't be against this ;). It always easier to use a wysiwyg to format your comments.

To solve my line break issue I just replaced the line 663 in class-sensei-question.php

echo apply_filters( 'sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id );

by

echo wpautop(apply_filters( 'sensei_question_answer_notes', $answer_notes, $question_id, $lesson_id ));