Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Blank lesson comment restriction #547

Merged
merged 4 commits into from
Sep 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions assets/react/front/course/_lesson.js
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand Down
13 changes: 10 additions & 3 deletions classes/Lesson.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 ),
);
Expand Down Expand Up @@ -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();
harunollyo marked this conversation as resolved.
Show resolved Hide resolved
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 ),
);
Expand Down
Loading