From eed930c51eaf7e6adb201ae37c8ca141f409647d Mon Sep 17 00:00:00 2001 From: Ren <18050944+renintw@users.noreply.github.com> Date: Mon, 23 Sep 2024 19:54:03 +0800 Subject: [PATCH] Fix quiz styles (#2881) * Update notice tips icon image * Add sensei-quiz-notices pattern * Fix success message on lesson without module * Using server-side rendering with the `render_block_` hook to replace the text on the lesson quiz notice. * Remove Awaiting grade text element * Update grade style on the lesson page * Using server-side rendering to customize the quiz actions. --- .../wporg-learn-2024/assets/icon-check.svg | 3 +- .../pub/wporg-learn-2024/inc/block-hooks.php | 88 ++++++++++++++++++- .../patterns/sensei-lesson-columns.php | 3 +- .../patterns/sensei-quiz-notices.php | 39 ++++++++ .../wporg-learn-2024/src/style/_sensei.scss | 77 ++++++++++++++-- .../templates/single-quiz.html | 4 +- 6 files changed, 202 insertions(+), 12 deletions(-) create mode 100644 wp-content/themes/pub/wporg-learn-2024/patterns/sensei-quiz-notices.php diff --git a/wp-content/themes/pub/wporg-learn-2024/assets/icon-check.svg b/wp-content/themes/pub/wporg-learn-2024/assets/icon-check.svg index c70f8a3e3..713b712e6 100644 --- a/wp-content/themes/pub/wporg-learn-2024/assets/icon-check.svg +++ b/wp-content/themes/pub/wporg-learn-2024/assets/icon-check.svg @@ -1,3 +1,4 @@ diff --git a/wp-content/themes/pub/wporg-learn-2024/inc/block-hooks.php b/wp-content/themes/pub/wporg-learn-2024/inc/block-hooks.php index cad3a7afb..6826af6bb 100644 --- a/wp-content/themes/pub/wporg-learn-2024/inc/block-hooks.php +++ b/wp-content/themes/pub/wporg-learn-2024/inc/block-hooks.php @@ -11,7 +11,9 @@ add_filter( 'render_block_data', __NAMESPACE__ . '\modify_header_template_part' ); add_filter( 'render_block_data', __NAMESPACE__ . '\modify_course_outline_lesson_block_attrs' ); -add_filter( 'render_block_sensei-lms/course-outline', __NAMESPACE__ . '\update_course_outline_block_add_aria', 10, 2 ); +add_filter( 'render_block_sensei-lms/course-outline', __NAMESPACE__ . '\update_course_outline_block_add_aria' ); +add_filter( 'render_block_sensei-lms/course-theme-notices', __NAMESPACE__ . '\update_lesson_quiz_notice_text' ); +add_filter( 'render_block_sensei-lms/quiz-actions', __NAMESPACE__ . '\update_quiz_actions' ); /** * Update header template based on current query. @@ -83,11 +85,10 @@ function modify_course_outline_lesson_block_attrs( $parsed_block ) { * individually, so they cannot be independently filtered. * * @param string $block_content The block content. - * @param array $block The full block, including name and attributes. * * @return string The updated icon HTML with aria data. */ -function update_course_outline_block_add_aria( $block_content, $block ) { +function update_course_outline_block_add_aria( $block_content ) { $html = new WP_HTML_Tag_Processor( $block_content ); $label = ''; @@ -106,3 +107,84 @@ function update_course_outline_block_add_aria( $block_content, $block ) { } return $html->get_updated_html(); } + +/** + * Replace the text for the lesson quiz notice. + * + * @param string $block_content The block content. + * + * @return string + */ +function update_lesson_quiz_notice_text( $block_content ) { + if ( is_singular( 'lesson' ) && is_quiz_ungraded() ) { + // Remove the text "Awaiting grade" in the quiz notice. + $block_content = str_replace( + '
%s
', + esc_html__( 'This is an ungraded quiz. Use it to check your comfort level with what you’ve learned.', 'wporg-learn' ) + ); + + $block_content = str_replace( + '