Filter uncanny-toolkit-pro

uo_transcript_current_user

Filters the current user object before it's used for transcript-related actions, allowing modification of user data.

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

Description

Filters the current user object before it's used to display their transcript. Developers can modify the user object to display transcripts for different users or apply custom logic based on user properties. The hook passes the WordPress user object.


Usage

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

Parameters

$user (mixed)
This parameter contains the user object of the currently logged-in user.

Return Value

The filtered value.


Examples

/**
 * Modify the user object passed to the transcript generation for specific purposes.
 * For instance, you might want to anonymize the user's name if the transcript
 * is being generated for a public-facing view, or append specific user meta.
 *
 * @param object|int|WP_User $user The user object or user ID.
 * @return object|int|WP_User The modified user object or user ID.
 */
add_filter( 'uo_transcript_current_user', function( $user ) {
	// If we're in a context where we don't want to display the actual user's name,
	// we could potentially replace it with a generic placeholder.
	// This is a hypothetical example. In a real scenario, you'd have specific logic
	// to determine *when* this anonymization should occur (e.g., based on a setting, a role, etc.).

	// Example: Check if the current user is an administrator and if we are displaying
	// a transcript for a different user (though the hook context here is less clear
	// about *which* user's transcript is being generated, we assume it's the one
	// the filter is intended to represent).
	if ( current_user_can( 'administrator' ) ) {
		// In a real case, you might want to check if $user is an object and has properties.
		// For demonstration, let's assume $user might be a WP_User object or an ID.
		if ( is_numeric( $user ) ) {
			$user_obj = get_user_by( 'id', $user );
		} elseif ( $user instanceof WP_User ) {
			$user_obj = $user;
		} else {
			// If it's neither an ID nor a WP_User object, or if it's invalid, return as is.
			return $user;
		}

		// Hypothetically, if we wanted to anonymize for administrators viewing another user's transcript:
		// if ( ! empty( $user_obj ) ) {
		//     $user_obj->user_firstname = 'Learner';
		//     $user_obj->user_lastname = 'Anonymous';
		// }
		// return $user_obj;

		// Or, perhaps you want to append specific user meta to the object for use elsewhere.
		// For example, let's say you have a custom field 'course_completion_level'.
		if ( ! empty( $user_obj ) ) {
			$completion_level = get_user_meta( $user_obj->ID, 'course_completion_level', true );
			if ( $completion_level ) {
				// Add custom data to the user object.
				// Note: Directly adding properties to a WP_User object might not be
				// the cleanest way; consider returning an array or a custom object
				// if the original function expects specific properties.
				// For this example, we'll add it as a property for demonstration.
				$user_obj->custom_completion_level = $completion_level;
			}
		}
		return $user_obj;
	}

	// If the condition isn't met, return the original user object/ID unchanged.
	return $user;
}, 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/learn-dash-transcript.php:512

* @param array $data
	 *
	 * @return string
	 */
	private static function generate_transcript( $data, $request, $user ) {
		global $post;
		
		$current_user = apply_filters( 'uo_transcript_current_user', $user );

		if ( isset( $current_user->user_firstname )
		     && isset( $current_user->user_lastname )
		     && ! empty( $current_user->user_firstname )
		     && ! empty( $current_user->user_lastname ) ) {

			$learner_name = $current_user->user_firstname . ' ' . $current_user->user_lastname;

Scroll to Top