Action tin-canny-learndash-reporting

tincanny_reporting_before_courses_overview_report

Fires before the course overview report is displayed, allowing for modifications.

add_action( 'tincanny_reporting_before_courses_overview_report', $callback, 10, 1 );

Description

Fires before the courses overview report data is generated. This hook allows developers to modify user data or inject custom logic before the report is built. It's ideal for filtering users or adding pre-processing steps to the reporting process.


Usage

add_action( 'tincanny_reporting_before_courses_overview_report', 'your_function_name', 10, 1 );

Examples

add_action(
	'tincanny_reporting_before_courses_overview_report',
	function() {
		// Example: Add a custom filter to exclude users with specific roles before the report generation.
		// This could be useful for excluding administrators or other non-learner roles.

		global $wpdb;
		$exclude_roles = array( 'administrator', 'editor' ); // Roles to exclude
		$user_ids_to_exclude = array();

		foreach ( $exclude_roles as $role ) {
			$users_in_role = get_users( array( 'role' => $role, 'fields' => 'ids' ) );
			if ( ! empty( $users_in_role ) ) {
				$user_ids_to_exclude = array_merge( $user_ids_to_exclude, $users_in_role );
			}
		}

		// If there are user IDs to exclude, add them to the list of filtered user IDs.
		// This assumes that `self::$filtered_user_ids` is accessible and intended to be modified.
		// In a real scenario, you might need to pass this data differently or use a filter hook that allows modification of the actual data.
		// For demonstration purposes, we'll simulate adding to a hypothetical global/static variable.

		if ( ! empty( $user_ids_to_exclude ) ) {
			// Assuming `self::$filtered_user_ids` is a static property of the class where this hook is used.
			// In a real plugin, you might need to access this differently.
			// A more robust approach would be to have a filter hook that returns the filtered user IDs.
			if ( isset( $GLOBALS['TincannyReporting']['filtered_user_ids'] ) && is_array( $GLOBALS['TincannyReporting']['filtered_user_ids'] ) ) {
				$GLOBALS['TincannyReporting']['filtered_user_ids'] = array_unique( array_merge( $GLOBALS['TincannyReporting']['filtered_user_ids'], $user_ids_to_exclude ) );
			} else {
				// Initialize if not set, though this might not be the intended behavior.
				$GLOBALS['TincannyReporting']['filtered_user_ids'] = $user_ids_to_exclude;
			}
		}

	},
	10, // Priority: 10 is the default
	0  // Accepted args: 0 means this callback function doesn't accept any arguments passed by the hook.
);

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

Config::profile_function( [ __CLASS__, 'exclude_user_ids' ] );

		// Store user IDs in the DB for future queries
		self::$injected_user_ids = self::inject_group_leader_id();

		Database::insert_in_tbl_reporting_api_user_ids( self::$injected_user_ids );

		do_action( 'tincanny_reporting_before_courses_overview_report' );

		Config::profile_function( [ __CLASS__, 'get_all_user_data_rearranged' ] );
		Config::profile_function( [ __CLASS__, 'filter_user_ids' ] );

		foreach ( self::$all_user_ids as $user_id ) {
			if ( ! empty( self::$filtered_user_ids ) && in_array( $user_id, self::$filtered_user_ids, true ) ) {
				continue;


Scroll to Top