Created
October 24, 2018 09:52
-
-
Save wpmudev-sls/af6fb3188b8065d4a595ffea11fafe11 to your computer and use it in GitHub Desktop.
CoursePress - Adds custom 50, 100 buttons to quickly set grade
This file contains 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 | |
/** | |
* 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