Making WordPress.org


Ignore:
Timestamp:
09/23/2024 11:56:37 AM (15 months ago)
Author:
renyot
Message:

Learn: Sync with git WordPress/learn@6304a40

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sites/trunk/wordpress.org/public_html/wp-content/themes/pub/wporg-learn-2024/inc/block-hooks.php

    r13990 r14071  
    1212add_filter( 'render_block_data', __NAMESPACE__ . '\modify_header_template_part' );
    1313add_filter( 'render_block_data', __NAMESPACE__ . '\modify_course_outline_lesson_block_attrs' );
    14 add_filter( 'render_block_sensei-lms/course-outline', __NAMESPACE__ . '\update_course_outline_block_add_aria', 10, 2 );
     14add_filter( 'render_block_sensei-lms/course-outline', __NAMESPACE__ . '\update_course_outline_block_add_aria' );
     15add_filter( 'render_block_sensei-lms/course-theme-notices', __NAMESPACE__ . '\update_lesson_quiz_notice_text' );
     16add_filter( 'render_block_sensei-lms/quiz-actions', __NAMESPACE__ . '\update_quiz_actions' );
    1517
    1618/**
     
    8486 *
    8587 * @param string $block_content The block content.
    86  * @param array  $block         The full block, including name and attributes.
    8788 *
    8889 * @return string The updated icon HTML with aria data.
    8990 */
    90 function update_course_outline_block_add_aria( $block_content, $block ) {
     91function update_course_outline_block_add_aria( $block_content ) {
    9192    $html = new WP_HTML_Tag_Processor( $block_content );
    9293
     
    107108    return $html->get_updated_html();
    108109}
     110
     111/**
     112 * Replace the text for the lesson quiz notice.
     113 *
     114 * @param string $block_content The block content.
     115 *
     116 * @return string
     117 */
     118function update_lesson_quiz_notice_text( $block_content ) {
     119    if ( is_singular( 'lesson' ) && is_quiz_ungraded() ) {
     120        // Remove the text "Awaiting grade" in the quiz notice.
     121        $block_content = str_replace(
     122            '<div class="sensei-course-theme-lesson-quiz-notice__text">Awaiting grade</div>',
     123            '',
     124            $block_content
     125        );
     126
     127        // Add a new paragraph between the notice content and actions.
     128        $new_p_tag = sprintf(
     129            '<p class="sensei-course-theme-lesson-quiz-notice__description">%s</p>',
     130            esc_html__( 'This is an ungraded quiz. Use it to check your comfort level with what you’ve learned.', 'wporg-learn' )
     131        );
     132
     133        $block_content = str_replace(
     134            '<div class="sensei-course-theme-lesson-quiz-notice__actions">',
     135            $new_p_tag . '<div class="sensei-course-theme-lesson-quiz-notice__actions">',
     136            $block_content
     137        );
     138    }
     139
     140    return $block_content;
     141}
     142
     143/**
     144 * Customize the quiz actions.
     145 *
     146 * @param string $block_content The block content.
     147 *
     148 * @return string
     149 */
     150function update_quiz_actions( $block_content ) {
     151    if ( is_singular( 'quiz' ) && is_quiz_ungraded() ) {
     152        $lesson_id = Sensei()->quiz->get_lesson_id();
     153        $lesson_link = get_permalink( $lesson_id );
     154
     155        // Add a new button to go back to the lesson.
     156        $new_button_block = do_blocks( '
     157            <!-- wp:button {"className":"has-text-align-center is-style-fill","fontSize":"normal","fontFamily":"inter"} -->
     158            <div class="wp-block-button has-custom-font-size has-text-align-center is-style-fill has-inter-font-family has-normal-font-size">
     159                <a class="wp-block-button__link wp-element-button" style="font-weight:600;line-height:1;outline:unset" href="' . esc_attr( $lesson_link ) . '">' . esc_html__( 'Back to lesson', 'wporg-learn' ) . '</a>
     160            </div>
     161            <!-- /wp:button -->
     162        ');
     163
     164        $block_content = str_replace(
     165            '<div class="sensei-quiz-actions-secondary">',
     166            $new_button_block . '<div class="sensei-quiz-actions-secondary">',
     167            $block_content
     168        );
     169    }
     170
     171    return $block_content;
     172}
     173
     174/**
     175 * Check if the quiz is ungraded.
     176 *
     177 * @return bool
     178 */
     179function is_quiz_ungraded() {
     180    $lesson_id = Sensei_Utils::get_current_lesson();
     181    $quiz_id   = Sensei()->lesson->lesson_quizzes( $lesson_id );
     182    $user_id   = get_current_user_id();
     183    $quiz_progress = Sensei()->quiz_progress_repository->get( $quiz_id, $user_id );
     184
     185    if ( 'ungraded' === $quiz_progress->get_status() ) {
     186        return true;
     187    }
     188
     189    return false;
     190}
Note: See TracChangeset for help on using the changeset viewer.