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

Fix emails with special characters being displayed incorrectly in the subject line #7546

Merged
merged 5 commits into from
Mar 18, 2024
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
4 changes: 4 additions & 0 deletions changelog/fix-encoded-email-subject
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: fixed

Email subject with special characters not being displayed correctly
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public function completed_course_mail_to_student( $status = 'in-progress', $stud
'student:id' => $student_id,
'student:displayname' => $student->display_name,
'course:id' => $course_id,
'course:name' => get_the_title( $course_id ),
'course:name' => html_entity_decode( get_the_title( $course_id ) ),
'completed:url' => esc_url(
\Sensei_Course::get_course_completed_page_url( $course_id ) ?? get_permalink( $course_id )
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public function course_new_teacher_assigned_email( $teacher_id, $course_id ) {
[
$recipient => [
'teacher:displayname' => $teacher->display_name,
'course:name' => get_the_title( $course_id ),
'course:name' => html_entity_decode( get_the_title( $course_id ) ),
'editcourse:url' => esc_url( $edit_link ),
],
]
Expand Down
2 changes: 1 addition & 1 deletion includes/internal/emails/generators/class-quiz-graded.php
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ public function quiz_graded_mail_to_student( $user_id, $quiz_id, $grade, $passma
$recipient => [
'grade:validation' => $pass_or_fail,
'course:name' => get_the_title( $course->ID ),
'lesson:name' => get_the_title( $lesson->ID ),
'lesson:name' => html_entity_decode( get_the_title( $lesson->ID ) ),
'grade:percentage' => $grade . '%',
'quiz:url' => $quiz_url,
],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ public function student_completed_course_mail_to_teacher( $status = 'in-progress
'student:id' => $student_id,
'student:displayname' => $student->display_name,
'course:id' => $course_id,
'course:name' => get_the_title( $course_id ),
'course:name' => html_entity_decode( get_the_title( $course_id ) ),
'grade:percentage' => $grade,
'manage:students' => $manage_url,
];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public function student_completed_lesson_mail_to_teacher( $student_id, $lesson_i
'course:id' => (int) $course_id,
'course:name' => get_the_title( $course_id ),
'lesson:id' => (int) $lesson_id,
'lesson:name' => get_the_title( $lesson_id ),
'lesson:name' => html_entity_decode( get_the_title( $lesson_id ) ),
'manage:students' => $manage_url,
];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ public function message_reply_mail_to_student( $comment, $message ) {
'teacher:displayname' => esc_html( $teacher->display_name ),
'course:name' => esc_html( get_the_title( $course_id ) ),
'message:displaymessage' => esc_html( $comment->comment_content ),
'subject:displaysubject' => esc_html( $message->post_title ),
'subject:displaysubject' => html_entity_decode( esc_html( $message->post_title ) ),
'reply:url' => esc_url( get_comment_link( $comment ) ),
],
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@
'student:displayname' => esc_html( $student->display_name ),
'course:name' => esc_html( get_the_title( $course->ID ) ),
'message:displaymessage' => esc_html( $message->post_content ),
'subject:displaysubject' => esc_html( $message->post_title ),
'subject:displaysubject' => html_entity_decode( esc_html( $message->post_title ) ),

Check warning on line 82 in includes/internal/emails/generators/class-student-sends-message.php

View check run for this annotation

Codecov / codecov/patch

includes/internal/emails/generators/class-student-sends-message.php#L82

Added line #L82 was not covered by tests
'reply:url' => esc_url( get_permalink( absint( $message_id ) ) ),
],
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public function message_reply_mail_to_teacher( $comment, $message ) {
'student:displayname' => esc_html( $commenter->display_name ),
'course:name' => esc_html( get_the_title( $course->ID ) ),
'message:displaymessage' => esc_html( $comment->comment_content ),
'subject:displaysubject' => esc_html( $message->post_title ),
'subject:displaysubject' => html_entity_decode( esc_html( $message->post_title ) ),
'reply:url' => esc_url( get_comment_link( $comment ) ),
],
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public function testGenerateEmail_WhenStudentEnrolledAndCompletedTheCourse_Calls
);
$course = $this->factory->course->create_and_get(
[
'post_title' => 'Test Course',
'post_title' => 'Course with Special Characters…?”',
]
);
$completed_url = \Sensei_Course::get_course_completed_page_url( $course->ID );
Expand Down Expand Up @@ -91,7 +91,7 @@ function ( $email_name, $replacements ) use ( &$email_data ) {
self::assertEquals( 'course_completed', $email_data['name'] );
self::assertArrayHasKey( '[email protected]', $email_data['data'] );
self::assertEquals( 'Test Student', $email_data['data']['[email protected]']['student:displayname'] );
self::assertEquals( 'Test Course', $email_data['data']['[email protected]']['course:name'] );
self::assertEquals( 'Course with Special Characters…?”', $email_data['data']['[email protected]']['course:name'] );
self::assertArrayHasKey( 'completed:url', $email_data['data']['[email protected]'] );
self::assertNotEmpty( $email_data['data']['[email protected]']['completed:url'] );
}
Expand Down Expand Up @@ -195,5 +195,4 @@ function ( $email_name, $replacements ) use ( &$email_data ) {
/* Assert. */
self::assertEmpty( $email_data['name'] );
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public function testWelcomeToCourseForStudent_WhenCalled_CallsSenseiEmailSendFil
);
$course_id = $factory->course->create(
[
'post_title' => 'Test Course',
'post_title' => 'Course with Special Characters…?”',
'post_author' => $teacher_id,
]
);
Expand Down Expand Up @@ -123,7 +123,7 @@ public function testWelcomeToCourseForStudent_WhenCalled_CallsSenseiEmailSendFil
'student:id' => $student_id,
'student:displayname' => 'Test Student',
'course:id' => $course_id,
'course:name' => 'Test Course',
'course:name' => 'Course with Special Characters…?”',
'course:url' => esc_url(
get_permalink( $course_id )
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public function testSendNewCourseEmail_WhenTeacherAssignedToNewCourseEventFires_
);
$course = $this->factory->course->create_and_get(
[
'post_title' => 'Test Course',
'post_title' => 'Course with Special Characters…?”',
'post_author' => $teacher_id,
]
);
Expand Down Expand Up @@ -85,7 +85,7 @@ function ( $email_name, $replacements ) use ( &$email_data ) {
self::assertEquals( 'new_course_assigned', $email_data['name'] );
self::assertArrayHasKey( '[email protected]', $email_data['data'] );
self::assertEquals( $user_name, $email_data['data']['[email protected]']['teacher:displayname'] );
self::assertEquals( 'Test Course', $email_data['data']['[email protected]']['course:name'] );
self::assertEquals( 'Course with Special Characters…?”', $email_data['data']['[email protected]']['course:name'] );
self::assertArrayHasKey( 'editcourse:url', $email_data['data']['[email protected]'] );
self::assertEquals( $edit_link, $email_data['data']['[email protected]']['editcourse:url'] );
}
Expand All @@ -101,7 +101,7 @@ public function testSendNewCourseEmail_WhenTeacherAssignedToNewCourseEventFires_
);
$course = $this->factory->course->create_and_get(
[
'post_title' => 'Test Course',
'post_title' => 'Course with Special Characters…?”',
'post_author' => $teacher_id,
]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public function testGenerateEmail_WhenCalledByStudentCompletedCourseEvent_CallsE
);
$course = $this->factory->course->create_and_get(
[
'post_title' => 'Test Course',
'post_title' => 'Course with Special Characters…?”',
'post_author' => $teacher_id,
]
);
Expand Down Expand Up @@ -92,7 +92,7 @@ function ( $email_name, $replacements ) use ( &$email_data ) {
self::assertEquals( 'student_completes_course', $email_data['name'] );
self::assertArrayHasKey( '[email protected]', $email_data['data'] );
self::assertEquals( 'Test Student', $email_data['data']['[email protected]']['student:displayname'] );
self::assertEquals( 'Test Course', $email_data['data']['[email protected]']['course:name'] );
self::assertEquals( 'Course with Special Characters…?”', $email_data['data']['[email protected]']['course:name'] );
self::assertArrayHasKey( 'manage:students', $email_data['data']['[email protected]'] );
self::assertNotEmpty( $email_data['data']['[email protected]']['manage:students'] );
}
Expand All @@ -116,7 +116,7 @@ public function testGenerateEmail_WhenCalledByStudentCompletedCourseEventAndTeac
);
$course = $this->factory->course->create_and_get(
[
'post_title' => 'Test Course',
'post_title' => 'Course with Special Characters…?”',
'post_author' => $teacher1_id,
]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ public function testStudentCompletedLessonMailToTeacher_LessonCompleted_CallsSen
);
$lesson_id = $factory->lesson->create(
[
'post_title' => 'Test Lesson',
'post_title' => 'Lesson with Special Characters…?”',
'meta_input' => [
'_lesson_course' => $course_id,
],
Expand Down Expand Up @@ -193,7 +193,7 @@ public function testStudentCompletedLessonMailToTeacher_LessonCompleted_CallsSen
'course:id' => $course_id,
'course:name' => 'Test Course',
'lesson:id' => $lesson_id,
'lesson:name' => 'Test Lesson',
'lesson:name' => 'Lesson with Special Characters…?”',
'manage:students' => esc_url(
admin_url( "admin.php?page=sensei_learners&course_id={$course_id}&lesson_id={$lesson_id}&view=learners" )
),
Expand Down Expand Up @@ -233,7 +233,7 @@ public function testStudentCompletedLessonMailToTeacher_LessonCompletedAndTeache
);
$lesson_id = $factory->lesson->create(
[
'post_title' => 'Test Lesson',
'post_title' => 'Lesson with Special Characters…?”',
'meta_input' => [
'_lesson_course' => $course_id,
],
Expand Down Expand Up @@ -277,7 +277,7 @@ public function testStudentCompletedLessonMailToTeacher_LessonCompletedAndTeache
'course:id' => $course_id,
'course:name' => 'Test Course',
'lesson:id' => $lesson_id,
'lesson:name' => 'Test Lesson',
'lesson:name' => 'Lesson with Special Characters…?”',
'manage:students' => esc_url(
admin_url( "admin.php?page=sensei_learners&course_id={$course_id}&lesson_id={$lesson_id}&view=learners" )
),
Expand All @@ -288,7 +288,7 @@ public function testStudentCompletedLessonMailToTeacher_LessonCompletedAndTeache
'course:id' => $course_id,
'course:name' => 'Test Course',
'lesson:id' => $lesson_id,
'lesson:name' => 'Test Lesson',
'lesson:name' => 'Lesson with Special Characters…?”',
'manage:students' => esc_url(
admin_url( "admin.php?page=sensei_learners&course_id={$course_id}&lesson_id={$lesson_id}&view=learners" )
),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public function testTeacherRepliesMail_WhenCalled_CallsEmailSendingActionWithRig
'comment_post_ID' => $course_id,
'user_id' => $this->teacher_id,
'comment_type' => 'comment',
'comment_content' => 'Test reply',
'comment_content' => '“Message Reply with Special Characters…?”',
'comment_approved' => 1,
]
);
Expand Down Expand Up @@ -171,7 +171,7 @@ public function testTeacherRepliesMail_WhenMessageSentFromLesson_CallsEmailSendi
'comment_post_ID' => $lesson_id,
'user_id' => $this->teacher_id,
'comment_type' => 'comment',
'comment_content' => 'Test reply',
'comment_content' => '“Message Reply with Special Characters…?”',
'comment_approved' => 1,
]
);
Expand Down Expand Up @@ -235,7 +235,7 @@ public function testTeacherRepliesMail_WhenMessageSentFromQuiz_CallsEmailSending
'comment_post_ID' => $quiz_id,
'user_id' => $this->teacher_id,
'comment_type' => 'comment',
'comment_content' => 'Test reply',
'comment_content' => '“Message Reply with Special Characters…?”',
'comment_approved' => 1,
]
);
Expand Down Expand Up @@ -297,7 +297,7 @@ public function testReplyMail_WhenCalled_DoesNotSendMailToStudentWhenStudentRepl
'comment_post_ID' => $course_id,
'user_id' => $this->student_id,
'comment_type' => 'comment',
'comment_content' => 'Test reply',
'comment_content' => '“Message Reply with Special Characters…?”',
'comment_approved' => 1,
]
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public function testStudentSendsNewMessage_WhenEventFires_CallsEmailSendingActio
$message = $this->factory->post->create_and_get(
[
'post_type' => 'sensei_message',
'post_title' => 'Test message',
'post_title' => '“Message with Special Characters…?”',
'post_status' => 'publish',
'post_author' => $student_id,
'meta_input' => [
Expand Down Expand Up @@ -131,7 +131,7 @@ public function testStudentSendsNewMessage_WhenCalled_DoesNotSendMailIfAnyOfTheU
$message = $this->factory->post->create_and_get(
[
'post_type' => 'sensei_message',
'post_title' => 'Test message',
'post_title' => '“Message with Special Characters…?”',
'post_status' => 'publish',
'post_author' => $student_id,
'meta_input' => [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public function testGenerateEmail_WhenCalledByStudentStartCourseEvent_CallsEmail
);
$course = $this->factory->course->create_and_get(
[
'post_title' => 'Test Course',
'post_title' => 'Course with Special Characters…?”',
'post_author' => $teacher_id,
]
);
Expand Down Expand Up @@ -89,7 +89,7 @@ function ( $email_name, $replacements ) use ( &$email_data ) {
self::assertEquals( 'student_starts_course', $email_data['name'] );
self::assertArrayHasKey( '[email protected]', $email_data['data'] );
self::assertEquals( 'Test Student', $email_data['data']['[email protected]']['student:displayname'] );
self::assertEquals( 'Test Course', $email_data['data']['[email protected]']['course:name'] );
self::assertEquals( 'Course with Special Characters…?”', $email_data['data']['[email protected]']['course:name'] );
self::assertEquals( $manage_url, $email_data['data']['[email protected]']['manage:students'] );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public function testStudentRepliesMail_WhenCalled_CallsEmailSendingActionWithRig
'comment_post_ID' => $course_id,
'user_id' => $student_id,
'comment_type' => 'comment',
'comment_content' => 'Test reply',
'comment_content' => '“Message Reply with Special Characters…?”',
'comment_approved' => 1,
]
);
Expand Down Expand Up @@ -170,7 +170,7 @@ public function testReplyMail_WhenCalled_DoesNotSendMailToTeacherWhenTeacherRepl
'comment_post_ID' => $course_id,
'user_id' => $teacher_id,
'comment_type' => 'comment',
'comment_content' => 'Test reply',
'comment_content' => '“Message Reply with Special Characters…?”',
'comment_approved' => 1,
]
);
Expand Down
Loading