Filter tin-canny-learndash-reporting

uo_tincanny_reporting_exclude_user_ids

Filters which user IDs should be excluded from Tincanny reporting data.

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

Description

Filter user IDs to exclude from Tincanny reporting data. Use this hook to prevent specific user accounts from appearing in course completion and activity reports.


Usage

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

Return Value

The filtered value.


Examples

/**
 * Excludes specific user IDs from the Tincanny reporting data.
 *
 * This filter allows administrators to prevent certain users' data from
 * appearing in Tincanny reports, for example, if they are testing the system
 * or are service accounts.
 *
 * @param array $excluded_user_ids An array of user IDs to exclude.
 * @return array The modified array of excluded user IDs.
 */
add_filter( 'uo_tincanny_reporting_exclude_user_ids', function ( $excluded_user_ids ) {

    // Add a specific test user ID to the exclusion list.
    $test_user_id = 123; // Replace with an actual test user ID.
    if ( ! in_array( $test_user_id, $excluded_user_ids ) ) {
        $excluded_user_ids[] = $test_user_id;
    }

    // Add the current user ID if they are an administrator (as an example of conditional exclusion).
    // This might be useful if admins don't want their own activity to appear in general reports.
    if ( current_user_can( 'manage_options' ) ) {
        $current_user_id = get_current_user_id();
        if ( ! in_array( $current_user_id, $excluded_user_ids ) ) {
            $excluded_user_ids[] = $current_user_id;
        }
    }

    return $excluded_user_ids;
}, 10, 1 );

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:134

// 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 ) );
		self::$leader_groups = isset( CourseData::$group_leader_groups[ self::$leader_id ] ) ? CourseData::$group_leader_groups[ self::$leader_id ] : array();


Scroll to Top