Filter uncanny-continuing-education-credits

uo_ceu_learndash_group_enrolled_courses

Filters the list of enrolled courses for a LearnDash group when a user is being enrolled.

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

Description

Filters the list of enrolled courses for a LearnDash group before they are processed. Use this hook to modify the array of course IDs, perhaps to exclude certain courses or add custom ones, before they are used in CEU reporting. The original LearnDash group enrollment is the source.


Usage

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

Parameters

$courses (mixed)
This parameter contains an array of course IDs that are enrolled in the specified LearnDash group.
$group_id (mixed)
This parameter contains an array of course IDs that are currently enrolled in the specified LearnDash group.

Return Value

The filtered value.


Examples

/**
 * Example of modifying the list of courses enrolled in a LearnDash group.
 *
 * This function demonstrates how to use the 'uo_ceu_learndash_group_enrolled_courses'
 * filter to add or remove courses from the list of courses enrolled in a specific
 * LearnDash group. For instance, you might want to exclude courses that are
 * automatically enrolled as part of a bundle.
 *
 * @param array $courses    The array of course IDs enrolled in the group.
 * @param int   $group_id   The ID of the LearnDash group.
 * @return array The modified array of course IDs.
 */
add_filter( 'uo_ceu_learndash_group_enrolled_courses', function( $courses, $group_id ) {

    // If it's a specific group, let's say group ID 123, and we want to exclude
    // course ID 456 from the enrolled list for demonstration purposes.
    if ( absint( $group_id ) === 123 ) {
        $course_to_exclude = 456;
        // Check if the course to exclude is in the current list and remove it.
        if ( ( $key = array_search( $course_to_exclude, $courses, true ) ) !== false ) {
            unset( $courses[ $key ] );
        }
    }

    // You could also add courses here if needed, but usually this filter
    // is for exclusion or modification of existing ones.

    // Return the modified (or unmodified) array of course IDs.
    return $courses;

}, 10, 2 ); // Priority 10, accepts 2 arguments ($courses, $group_id)

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/course-report.php:1309

public function set_group_courses( $group_id ) {
		$courses             = learndash_group_enrolled_courses( $group_id );
		$courses             = apply_filters( 'uo_ceu_learndash_group_enrolled_courses', $courses, $group_id );
		$courses             = ! empty( $courses ) ? array_map( 'absint', $courses ) : array();
		$this->group_courses = $courses;
	}


Scroll to Top