Filter uncanny-learndash-groups

learndash_essay_status_data

This filter is documented in includes/quiz/ld-quiz-essays.php */ Filters essay submission data for LearnDash quizzes, allowing modification before saving.

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

Description

This filter allows developers to modify essay status and awarded points data after an essay has been graded but before it's saved. It's applied within the group essay reporting context. Developers can hook into `learndash_essay_status_data` to programmatically adjust the status or points awarded for an essay, providing custom grading logic or integrations.


Usage

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

Parameters

$submitted_essay_data (mixed)

Return Value

The filtered value.


Examples

add_filter(
    'learndash_essay_status_data',
    'my_learndash_modify_essay_status_data',
    10,
    1
);

/**
 * Example function to modify the submitted essay data.
 *
 * This function demonstrates how to intercept and alter the data associated
 * with an essay submission after it has been graded. In this example, we'll
 * add a custom meta field to the essay data if the points awarded exceed a
 * certain threshold.
 *
 * @param array $submitted_essay_data The array of submitted essay data.
 *                                    Expected keys include 'status', 'points_awarded'.
 * @return array The modified submitted_essay_data array.
 */
function my_learndash_modify_essay_status_data( $submitted_essay_data ) {

    // Check if the essay has been graded and if points have been awarded.
    if ( isset( $submitted_essay_data['status'] ) && 'graded' === $submitted_essay_data['status'] && isset( $submitted_essay_data['points_awarded'] ) ) {

        $points_awarded = intval( $submitted_essay_data['points_awarded'] );
        $grading_threshold = 50; // Example threshold

        // If points awarded exceed the threshold, add a custom note.
        if ( $points_awarded > $grading_threshold ) {
            $submitted_essay_data['custom_feedback_note'] = 'Excellent work! This essay received a high score.';
        }
    }

    // Always return the modified data.
    return $submitted_essay_data;
}

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:1346
src/classes/reports/group-essays.php:1714

$submitted_essay_data['status'] = 'graded';

				// get the new assigned points.
				$submitted_essay_data['points_awarded'] = intval( $_REQUEST['essay_points'][ $essay_id ] );

				/** This filter is documented in includes/quiz/ld-quiz-essays.php */
				$submitted_essay_data = apply_filters( 'learndash_essay_status_data', $submitted_essay_data );
				learndash_update_submitted_essay_data( $quiz_id, $question_id, $essay_post, $submitted_essay_data );

				if ( ! is_null( $original_points_awarded ) && ! is_null( $submitted_essay_data['points_awarded'] ) ) {
					if ( $submitted_essay_data['points_awarded'] > $original_points_awarded ) {
						$points_awarded_difference = intval( $submitted_essay_data['points_awarded'] ) - intval( $original_points_awarded );
					} else {
						$points_awarded_difference = ( intval( $original_points_awarded ) - intval( $submitted_essay_data['points_awarded'] ) ) * - 1;


Scroll to Top