Filter uncanny-toolkit-pro

uo_ld_course_navigation_show_topic_quizzes

Filters whether to show quizzes within the course navigation for a specific topic and course.

add_filter( 'uo_ld_course_navigation_show_topic_quizzes', $callback, 10, 2 );

Description

Filters whether to display quizzes within the topic navigation in LearnDash. This hook allows developers to conditionally hide or show topic quizzes based on custom logic. It fires within the course navigation generation process.


Usage

add_filter( 'uo_ld_course_navigation_show_topic_quizzes', 'your_function_name', 10, 2 );

Parameters

$course_id (mixed)
This parameter indicates whether quizzes should be displayed within the course navigation.
$instance (mixed)
This parameter contains the ID of the current LearnDash course being displayed in the navigation.

Return Value

The filtered value.


Examples

/**
 * Conditionally hide quizzes within topics in the course navigation.
 *
 * This filter allows developers to disable the display of quizzes that are
 * part of a topic within the LearnDash course navigation structure.
 *
 * @param bool   $show_topic_quizzes The current value of whether to show topic quizzes.
 * @param int    $course_id          The ID of the current LearnDash course.
 * @param array  $instance           The course navigation instance array, potentially containing configuration settings.
 * @return bool                     False to hide topic quizzes, true to show them.
 */
add_filter( 'uo_ld_course_navigation_show_topic_quizzes', function( $show_topic_quizzes, $course_id, $instance ) {
	// Example: Hide topic quizzes if a specific custom field is set on the course.
	// Replace 'my_hide_topic_quizzes_field' with your actual custom field name.
	if ( get_post_meta( $course_id, 'my_hide_topic_quizzes_field', true ) === 'yes' ) {
		return false; // Hide topic quizzes
	}

	// You could also check other conditions, like user roles, specific lesson types, etc.
	// For example, to hide only for users who are not enrolled:
	// if ( ! sfwd_lms_has_access( $course_id ) ) {
	//     return false;
	// }

	return $show_topic_quizzes; // Return the original value if no conditions are met
}, 10, 3 );

Placement

This code should be placed in the functions.php file of your active theme, a custom plugin, or using a code snippets plugin.


Source Code

src/classes/learndash-course-navigation.php:372

</div>
			<?php
		}

		// Always show quizzes at every level.
		$instance['show_course_quizzes'] = apply_filters( 'uo_ld_course_navigation_show_course_quizzes', true, $course_id, $instance );
		$instance['show_lesson_quizzes'] = apply_filters( 'uo_ld_course_navigation_show_lesson_quizzes', true, $course_id, $instance );
		$instance['show_topic_quizzes']  = apply_filters( 'uo_ld_course_navigation_show_topic_quizzes', true, $course_id, $instance );
		?>
		<div class="ultp-lazy-course-navigation__content">
			<?php learndash_course_navigation( $course_id, $instance, $lesson_query_args ); ?>
		</div>
		<?php

		$content = ob_get_clean();


Scroll to Top