ulgm_gm_assignments_student_name
Filters the student's first and last name displayed in the gradebook assignments.
add_filter( 'ulgm_gm_assignments_student_name', $callback, 10, 4 );
Description
Filters the student's first and last name for group assignments. Developers can modify the student's name displayed in reports. This hook fires during the generation of the group assignments report. Note that both `$first_name` and `$last_name` parameters are passed, and `$a_post` provides context about the assignment.
Usage
add_filter( 'ulgm_gm_assignments_student_name', 'your_function_name', 10, 4 );
Parameters
-
$first_name(mixed) - This parameter contains the student's first name.
-
$first_name(mixed) - This parameter contains the student's first name.
-
$last_name(mixed) - This parameter is a placeholder for a first name and is not intended to be used.
-
$a_post(mixed) - This parameter represents the last name of the author of the assignment post.
Return Value
The filtered value.
Examples
<?php
/**
* Example filter to modify the student's full name in group assignments report.
* This example will append "(Legacy Student)" to the student's name if they
* are associated with a legacy user role.
*
* @param string $student_name The default student name (first name + last name).
* @param string $first_name The student's first name.
* @param string $last_name The student's last name.
* @param int $user_id The ID of the user associated with the assignment.
*
* @return string The modified student name.
*/
function my_custom_ulgm_gm_assignments_student_name( $student_name, $first_name, $last_name, $user_id ) {
// Check if the user has a specific legacy role.
$user = get_userdata( $user_id );
if ( $user && in_array( 'legacy_student_role', (array) $user->roles ) ) {
return $student_name . ' (Legacy Student)';
}
// Return the original name if no modification is needed.
return $student_name;
}
add_filter( 'ulgm_gm_assignments_student_name', 'my_custom_ulgm_gm_assignments_student_name', 10, 4 );
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/reports/group-assignments.php:1112
$last_name = get_the_author_meta( 'last_name', $a_post->post_author );
$assignments[] = array(
'id' => $a_post->ID,
'title' => '<a title="' . $a_post->post_title . '" data-assignment-id="' . $a_post->ID . '" class="edit_assignment_single">' . __( 'View', 'uncanny-learndash-groups' ) . '</a><div class="row-actions">' . $row_action . '</div>',
'first_name' => $first_name,
'last_name' => $last_name,
'student' => apply_filters( 'ulgm_gm_assignments_student_name', $first_name . ' ' . $last_name, $first_name, $last_name, $a_post->post_author ),
'author' => '<a href="mailto:' . get_the_author_meta( 'email', $a_post->post_author ) . '" class="edit_assignment">' . get_the_author_meta( 'login', $a_post->post_author ) . '</a>',
'status' => $status,
'points' => $points,
'assignedCourse' => '<a href="' . get_permalink( $course ) . '">' . $course->post_title . '</a>',
'assignedlesson' => '<a href="' . get_permalink( $lesson ) . '">' . $lesson->post_title . '</a>',
'comments' => '<a target="_blank" href="' . get_permalink( $assignment_id ) . '#comments">' . get_comments_number( $assignment_id ) . '</a>',
'date' => $date_col,