Skip to content

Instantly share code, notes, and snippets.

@wpmudev-sls
Created October 24, 2018 09:52
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 wpmudev-sls/af6fb3188b8065d4a595ffea11fafe11 to your computer and use it in GitHub Desktop.
Save wpmudev-sls/af6fb3188b8065d4a595ffea11fafe11 to your computer and use it in GitHub Desktop.
CoursePress - Adds custom 50, 100 buttons to quickly set grade
<?php
/**
* Plugin Name: CoursePress - Adds custom 50, 100 buttons to quickly set grade
* Description: Adds custom 50, 100 buttons to quickly set grade
* Author: Ariful Islam @ WPMUDEV
* Author URI: https://premium.wpmudev.org/profile/itsarifulislam
* License: GPLv2 or later
*/
add_action( 'admin_head', function() {
?>
<style>
.cp-easy-grade-actions {
margin: 10px 0px 5px;
}
</style>
<script>
(function($){
// Set the quick access grades
var easyGrads = [1, 50, 100];
$(window).load(function(){
// Build the buttons HTML
var template = '<div class="cp-easy-grade-actions">';
template += easyGrads.map(function(grade){
return '<button class="button-primary">'+grade+'</button>';
});
template += '</div>';
// Append buttons to the boxes
$('.cp-edit-grade-box').each(function(){
$(this).find('.description').before(template);
});
// Attach events to the quick grade buttons
$('.cp-easy-grade-actions button').on('click', function(e) {
e.preventDefault();
$(this).closest('.cp-edit-grade-box').find('.module-grade').val( Number($(this).text()) ).change();
});
});
})(jQuery);
</script>
<?php
}, 999999 );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment