learndash_updated_essay_scoring
This filter is documented in includes/quiz/ld-quiz-essays.php */ Filters essay scoring data after a quiz essay is updated to allow modification of the results.
add_filter( 'learndash_updated_essay_scoring', $callback, 10, 1 );
Description
Fires after an essay's scoring has been updated. Developers can use this filter to modify the returned scoring data, which includes the updated question score, points awarded difference, and total score difference. This hook is useful for custom reporting or altering scoring logic.
Usage
add_filter( 'learndash_updated_essay_scoring', 'your_function_name', 10, 1 );
Parameters
-
$updated_scoring_data(mixed)
Return Value
The filtered value.
Examples
<?php
/**
* Example of how to use the 'learndash_updated_essay_scoring' filter.
*
* This example demonstrates how to modify the scoring data after an essay question
* has been updated and scored. It checks if the points awarded have increased
* and, if so, might trigger additional actions or modify the data further.
*
* @param array $updated_scoring_data An array containing updated scoring information.
* Expected keys: 'updated_question_score',
* 'points_awarded_difference', 'score_difference'.
* @return array The modified or original scoring data.
*/
function my_learndash_modify_essay_scoring( $updated_scoring_data ) {
// Check if the points awarded have actually increased.
if ( isset( $updated_scoring_data['points_awarded_difference'] ) && $updated_scoring_data['points_awarded_difference'] > 0 ) {
// For demonstration, let's log a message when scores are increased.
// In a real scenario, you might want to notify an administrator,
// update another related piece of data, or perform some custom logic.
error_log( sprintf(
'Learndash Essay Scoring: Points awarded increased by %s. New score: %s.',
$updated_scoring_data['points_awarded_difference'],
$updated_scoring_data['updated_question_score']
) );
// You could also modify the data further if needed.
// For example, if you wanted to add a bonus point for significant increases:
// if ( $updated_scoring_data['points_awarded_difference'] >= 5 ) {
// $updated_scoring_data['updated_question_score'] += 1;
// $updated_scoring_data['points_awarded_difference'] += 1;
// // Recalculate other differences if necessary based on your logic
// }
}
// Always return the potentially modified data.
return $updated_scoring_data;
}
add_filter( 'learndash_updated_essay_scoring', 'my_learndash_modify_essay_scoring', 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/reports/group-essays.php:1363
src/classes/reports/group-essays.php:1736
$updated_scoring_data = array(
'updated_question_score' => $submitted_essay_data['points_awarded'],
'points_awarded_difference' => $points_awarded_difference,
'score_difference' => $quiz_score_difference,
);
/** This filter is documented in includes/quiz/ld-quiz-essays.php */
$updated_scoring_data = apply_filters( 'learndash_updated_essay_scoring', $updated_scoring_data );
learndash_update_quiz_data( $quiz_id, $question_id, $updated_scoring_data, $essay_post );
/** This action is documented in includes/quiz/ld-quiz-essays.php */
do_action( 'learndash_essay_all_quiz_data_updated', $quiz_id, $question_id, $updated_scoring_data, $essay_post );
}
}
}