Filter tin-canny-learndash-reporting

uo_tincanny_reporting_exclude_roles

Filters the list of user roles to exclude from Tincanny reporting, allowing customization of who is included.

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

Description

Filters the array of user roles that should be excluded from Tincanny reporting data. Developers can add or remove roles from this array to prevent specific user roles from appearing in reports. This filter fires before the report data is generated.


Usage

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

Return Value

The filtered value.


Examples

/**
 * Exclude specific user roles from the Tincanny reporting data.
 *
 * This filter allows administrators to prevent certain user roles
 * from appearing in the Tincanny reports, such as support staff
 * or other roles that shouldn't be included in course completion metrics.
 *
 * @param array $excluded_roles An array of user role slugs to exclude.
 * @return array The updated array of excluded user roles.
 */
add_filter( 'uo_tincanny_reporting_exclude_roles', 'my_custom_tincanny_exclude_roles', 10, 1 );

function my_custom_tincanny_exclude_roles( $excluded_roles ) {
    // Add 'editor' and 'author' roles to the exclusion list if they are not already present.
    // This prevents users with these roles from appearing in Tincanny reports.
    if ( ! in_array( 'editor', $excluded_roles, true ) ) {
        $excluded_roles[] = 'editor';
    }
    if ( ! in_array( 'author', $excluded_roles, true ) ) {
        $excluded_roles[] = 'author';
    }

    // Example: Conditionally exclude a role based on a site option
    $exclude_specific_role = get_option( 'my_tincanny_exclude_custom_role', false );
    if ( $exclude_specific_role && ! in_array( 'contributor', $excluded_roles, true ) ) {
        $excluded_roles[] = 'contributor';
    }

    return $excluded_roles;
}

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/reporting/learndash/courses-users-report/build-report-data.php:133

// Truncate the reporting_api_user_id table
		Database::truncate_reporting_api_user_id_table();

		self::$leader_id = wp_get_current_user()->ID;

		// Ensure filters are applied at the right time
		self::$excluded_roles    = apply_filters( 'uo_tincanny_reporting_exclude_roles', array() );
		self::$excluded_user_ids = apply_filters( 'uo_tincanny_reporting_exclude_user_ids', array() );

		// Get list of all courses
		self::$course_list = Config::profile_function([ __CLASS__, 'get_course_list' ] );

		// Get lists of all groups
		self::$groups_list   = Config::profile_function([  'uncanny_learndash_reportingCourseData', 'get_groups_list' ], self::$leader_id, uotc_is_user_admin( self::$leader_id ) );


Scroll to Top