Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joelworsham/5f9481d628a449f94dbfe23329df8d0e to your computer and use it in GitHub Desktop.
Save joelworsham/5f9481d628a449f94dbfe23329df8d0e to your computer and use it in GitHub Desktop.
LearnDash Gradebook re-order grades example 2
<?php
function my_modify_gradebook_type_components( $components ) {
if ( ! $components ) {
return $components;
}
foreach ( $components as $type_id => &$component ) {
// Optional conditional based on the type id, name, or any other thing here.
// if ( $component['name'] != 'Specific Type' ) {
// continue;
// }
if ( ! $component['grades'] ) {
continue;
}
// Sort grades as desired. Multiple ways to do so.
// Alphabetically by "Name"
usort($component['grades'], function($a, $b) {
return strcmp($a['name'], $b['name']);
});
// Numerically by "Score"
usort($component['grades'], function($a, $b) {
return $a['score'] - $b['score'];
});
}
return $components;
}
add_filter( 'ld_gb_user_grade_components', 'my_modify_gradebook_type_components' );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment