Filter uncanny-continuing-education-credits

ucec_course_report_users

Filters the user options for the course report to modify or customize displayed users.

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

Description

Filters the array of user options displayed in the course report. Developers can modify this array to include, exclude, or alter the data associated with each user, such as their ID or display text, before the course report is generated.


Usage

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

Parameters

$options (mixed)
This parameter contains an array of options that can be modified to filter or modify the user list before it is processed by the `get_users` function.

Return Value

The filtered value.


Examples

/**
 * Example of how to modify the user options for the course report.
 * This function will add a specific user to the top of the list
 * if they exist, ensuring they are easily selectable.
 */
add_filter( 'ucec_course_report_users', function( $options ) {

	// Define the ID of the user we want to feature.
	$featured_user_id = 1; // Replace with the actual user ID you want to feature.

	// Check if the options array is not empty.
	if ( ! empty( $options ) ) {
		$featured_user_data = null;
		$other_users = array();

		// Iterate through the existing options to find the featured user
		// and separate them from other users.
		foreach ( $options as $option ) {
			if ( $option['value'] == $featured_user_id ) {
				$featured_user_data = $option;
			} else {
				$other_users[] = $option;
			}
		}

		// If the featured user was found, prepend them to the $options array.
		if ( $featured_user_data ) {
			array_unshift( $options, $featured_user_data );
		}

		// The $options array now contains the featured user at the beginning,
		// followed by all other users.
	}

	return $options;
}, 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/classes/backend-deficiency-report.php:289
src/classes/backend-course-report.php:167

static function get_users() {
		// Get list of all users
		$users = get_users();

		// Create array that will contain the optiosn
		$options = array();

		// Iterate users and create main array
		foreach ( $users as $user ) {
			// Get avatar
			$user->avatar = get_avatar_url( $user->ID );

			// Add option
			$options[] = array(
				'value' => $user->ID,
				'text'  => sprintf( '%s::%s', wp_strip_all_tags( $user->display_name ), wp_strip_all_tags( $user->user_email ) ),
			);
		}

		// Apply filters and return
		return apply_filters( 'ucec_course_report_users', $options );
	}

Scroll to Top