Created
October 18, 2016 18:45
-
-
Save joelworsham/5f9481d628a449f94dbfe23329df8d0e to your computer and use it in GitHub Desktop.
LearnDash Gradebook re-order grades example 2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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