Filter uncanny-continuing-education-credits

uo_ceu_include_group_courses

Filters whether to include courses within a specific group in the core functionality.

add_filter( 'uo_ceu_include_group_courses', $callback, 10, 1 );

Description

Filters whether to include courses belonging to a specific group. Returning `false` prevents the display of group-specific courses. This is useful for customizing course visibility based on group membership or other criteria within the core plugin.


Usage

add_filter( 'uo_ceu_include_group_courses', 'your_function_name', 10, 1 );

Parameters

$group_id (mixed)
This boolean parameter determines whether courses associated with a specific group should be included.

Return Value

The filtered value.


Examples

/**
 * Example callback for the 'uo_ceu_include_group_courses' filter.
 *
 * This callback demonstrates how to conditionally exclude courses from a specific group
 * based on a custom meta field associated with the group.
 *
 * @param bool   $include_group_courses Whether to include courses for the current group.
 * @param int    $group_id            The ID of the current group.
 * @return bool                        The modified value indicating whether to include group courses.
 */
function my_custom_exclude_group_courses( $include_group_courses, $group_id ) {
	// Check if the group has a specific meta key indicating that its courses should NOT be included.
	// For example, a meta key like '_disable_course_reporting_for_group' set to 'yes'.
	$disable_reporting = get_metadata( 'group', $group_id, '_disable_course_reporting_for_group', true );

	if ( 'yes' === $disable_reporting ) {
		// If the meta key is set to 'yes', we explicitly return false to exclude these courses.
		return false;
	}

	// Otherwise, return the original value, allowing courses to be included.
	return $include_group_courses;
}

// Add the filter with a priority and specifying the number of arguments accepted by the callback.
add_filter( 'uo_ceu_include_group_courses', 'my_custom_exclude_group_courses', 10, 2 );

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:1283
src/classes/course-report.php:2007

public function maybe_set_group_filters() {
		if ( 0 !== absint( $this->group ) ) {
			$group_id = absint( $this->group );
			$this->set_group_users( $group_id );
			if ( true === apply_filters( 'uo_ceu_include_group_courses', true, $group_id ) ) {
				$this->set_group_courses( $group_id );
			}
		}
	}


Scroll to Top