diff --git a/assets/react/front/course/_lesson.js b/assets/react/front/course/_lesson.js index 30e89d594..edc2977de 100644 --- a/assets/react/front/course/_lesson.js +++ b/assets/react/front/course/_lesson.js @@ -9,10 +9,18 @@ window.jQuery(document).ready($=>{ $(document).on('click', '.tutor-single-course-lesson-comments button[type="submit"]', function(e){ e.preventDefault(); + const {__} = wp.i18n; let btn = $(this); let form = btn.closest('form'); let data = form.serialize(); + let comment = form.find('textarea[name="comment"]').val(); + + if ( comment.trim().length === 0 ) { + tutor_toast(__('Warning', 'tutor'), __('Blank comment is not allowed.', 'tutor'), 'error'); + return; + } + $.ajax({ url: _tutorobject.ajaxurl, type: 'POST', diff --git a/classes/Lesson.php b/classes/Lesson.php index c2f203ddf..9940a4413 100644 --- a/classes/Lesson.php +++ b/classes/Lesson.php @@ -93,9 +93,10 @@ public function __construct() { */ public function tutor_single_course_lesson_load_more() { tutor_utils()->checking_nonce(); - if ( 'tutor_create_lesson_comment' === Input::post( 'action' ) ) { + $comment = Input::post( 'comment', '', Input::TYPE_KSES_POST ); + if ( 'tutor_create_lesson_comment' === Input::post( 'action' ) && strlen( $comment ) > 0 ) { $comment_data = array( - 'comment_content' => Input::post( 'comment', '', Input::TYPE_KSES_POST ), + 'comment_content' => $comment, 'comment_post_ID' => Input::post( 'comment_post_ID', 0, Input::TYPE_INT ), 'comment_parent' => Input::post( 'comment_parent', 0, Input::TYPE_INT ), ); @@ -563,8 +564,14 @@ public function tutor_lesson_completed_after( $content_id ) { */ public function reply_lesson_comment() { tutor_utils()->checking_nonce(); + $comment = Input::post( 'comment', '', Input::TYPE_KSES_POST ); + if ( 0 === strlen( $comment ) ) { + wp_send_json_error(); + return; + } + $comment_data = array( - 'comment_content' => Input::post( 'comment', '', Input::TYPE_KSES_POST ), + 'comment_content' => $comment, 'comment_post_ID' => Input::post( 'comment_post_ID', 0, Input::TYPE_INT ), 'comment_parent' => Input::post( 'comment_parent', 0, Input::TYPE_INT ), );