Filter uncanny-learndash-groups

ulgm_gm_essay_student_name

Filters the student's first and last name and their essay content before it's processed.

add_filter( 'ulgm_gm_essay_student_name', $callback, 10, 4 );

Description

Filters the student's first and last name when displaying group essays. Modify student names before they are shown in the report. The hook passes the author's first name, last name, and the essay post object for context.


Usage

add_filter( 'ulgm_gm_essay_student_name', 'your_function_name', 10, 4 );

Parameters

$first_name (mixed)
This parameter is the student's first name.
$first_name (mixed)
This parameter contains the first name of the student associated with the essay.
$last_name (mixed)
This parameter is expected to contain the student's first name.
$essay (mixed)
This parameter contains the last name of the author who submitted the essay.

Return Value

The filtered value.


Examples

/**
 * Modify the student name output for the group essay report.
 *
 * This example demonstrates how to append a specific identifier (e.g., a role)
 * to the student's name if they have a particular user role assigned.
 */
add_filter( 'ulgm_gm_essay_student_name', function( $full_name, $first_name, $last_name, $user_id ) {
    // Get the user object.
    $user = get_user_by( 'id', $user_id );

    // Check if the user exists and has a specific role.
    if ( $user && in_array( 'student', (array) $user->roles ) ) {
        // Append a suffix to indicate they are a student.
        return $full_name . ' (Student)';
    }

    // Return the original full name if no special condition is met.
    return $full_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-essays.php:1255

$last_name  = get_the_author_meta( 'last_name', $essay->post_author );

				$essays[] = array(
					'id'             => $essay_id,
					'title'          => '<a data-essay-id="' . $essay_id . '" class="edit_essay edit_essay_single">' . $essay->post_title . '</a><div class="row-actions">' . $row_action . '</div>',
					'first_name'     => $first_name,
					'last_name'      => $last_name,
					'student'        => apply_filters( 'ulgm_gm_essay_student_name', $first_name . ' ' . $last_name, $first_name, $last_name, $essay->post_author ),
					'author'         => '<a href="mailto:' . get_the_author_meta( 'email', $essay->post_author ) . '" class="edit_essay">' . get_the_author_meta( 'login', $essay->post_author ) . '</a>',
					'status'         => $status,
					'points'         => $points,
					'question_text'  => $question_text,
					'content'        => $essay_content,
					'assignedCourse' => ! empty( $course ) ? '<a href="' . get_permalink( $course ) . '">' . $course->post_title . '</a>' : '',
					'assignedlesson' => ! empty( $lesson ) ? '<a href="' . get_permalink( $lesson ) . '">' . $lesson->post_title . '</a>' : '',

Scroll to Top