Filter uncanny-learndash-groups

ulgm_rest_api_should_include_lesson_topic_essays_data

Filters whether lesson topic essay data should be included in the REST API response.

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

Description

Filters whether to include lesson topic essay data in the REST API response. Developers can use this hook to conditionally exclude essay data based on lesson or course IDs, for example, to improve performance or for specific data privacy requirements.


Usage

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

Parameters

$lesson_id (mixed)
This parameter is a boolean value that determines whether lesson topic essay data should be included in the REST API response.
$course_id (mixed)
This parameter represents the ID of the lesson for which essay data is being considered.

Return Value

The filtered value.


Examples

/**
 * Conditionally include lesson and topic essay data in the REST API response.
 *
 * This filter allows developers to control whether essay data associated with
 * lessons and topics within a course is included in the REST API output.
 * By default, it's set to true, meaning the data will be included.
 *
 * @param bool   $include_essay_data Whether to include the essay data. Default true.
 * @param int    $lesson_id          The ID of the current lesson being processed.
 * @param int    $course_id          The ID of the current course being processed.
 *
 * @return bool The modified value indicating whether to include the essay data.
 */
add_filter( 'ulgm_rest_api_should_include_lesson_topic_essays_data', function( $include_essay_data, $lesson_id, $course_id ) {

	// Example: Only include essay data for specific courses.
	$allowed_course_ids = array( 123, 456 ); // Replace with actual course IDs

	if ( in_array( $course_id, $allowed_course_ids ) ) {
		return true; // Include essay data for these courses
	}

	// Example: Exclude essay data for lessons that are part of a specific group.
	// This assumes you have a way to determine if a lesson belongs to a group
	// and want to conditionally exclude essays for those.
	// For demonstration, let's assume a function get_lesson_group_id($lesson_id) exists.
	// $lesson_group_id = get_lesson_group_id( $lesson_id );
	// if ( $lesson_group_id === 789 ) { // Replace 789 with a specific group ID
	//     return false; // Exclude essay data for lessons in this group
	// }

	// If no specific conditions met, return the original value.
	return $include_essay_data;

}, 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/reports/group-essays.php:700
src/classes/reports/group-essays.php:1132

$group_quiz_ids                               = array_merge( $group_quiz_ids, $quiz_ids );
								$lesson_relations[ $course_id ][ $lesson_id ] = $quiz_ids;
							}
							if ( $include_topics ) {
								$topic_ids = learndash_course_get_children_of_step( $course_id, $lesson_id, 'sfwd-topic' );
								if ( ! empty( $topic_ids ) ) {
									// Collect topic quiz IDs that have been filtered out.
									$omit_topic_quizzes = false === apply_filters( 'ulgm_rest_api_should_include_lesson_topic_essays_data', true, $lesson_id, $course_id );
									if ( $omit_topic_quizzes ) {
										$omited_topic_quizzes[ $course_id . '-' . $lesson_id ] = array();
									}

									foreach ( $topic_ids as $topic_id ) {
										$quiz_ids = learndash_course_get_children_of_step( $course_id, $topic_id, 'sfwd-quiz' );
										if ( ! empty( $quiz_ids ) ) {

Scroll to Top