Advertisement
Guest User

Untitled

a guest
Oct 16th, 2019
105
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.84 KB | None | 0 0
  1. add_action('wp_footer',function (){
  2.  
  3. ?>
  4. <script>
  5. function check_quiz_marks(){
  6. var qid = jQuery('.course_timeline ul li.active a').data('unit');
  7. jQuery.ajax({
  8. type: "POST",
  9. url: ajaxurl,
  10. dataType: 'json',
  11. data: { action: 'check_quiz_marks',
  12. security: $('#hash').val(),
  13. quiz_id:qid,
  14. },
  15. cache: false,
  16. success: function (json) {
  17. console.log(json);
  18. if(json && json.status){
  19. var value= parseInt($('.course_progressbar').attr('data-value'));
  20. if(value >= 100){
  21. $('input[name="submit_course"]').trigger('click');
  22. }else{
  23.  
  24. $('input[name="submit_course"]').addClass('hide');
  25. }
  26. }
  27. }
  28. });
  29. }
  30. jQuery(document).ready(function($){
  31. $('.unit_content').on('unit_traverse',function(){
  32. check_quiz_marks();
  33. console.log('unit_content');
  34. });
  35. $('.course_progressbar').on('increment',function(){
  36. check_quiz_marks();
  37. console.log('course_progressbar');
  38. });
  39. console.log('ahava me');
  40. check_quiz_marks();
  41. });
  42. </script>
  43. <?php
  44.  
  45. },10);
  46. add_action('wp_ajax_check_quiz_marks',function (){
  47. $quiz_id= $_POST['quiz_id'];
  48. if ( !isset($_POST['security']) || !wp_verify_nonce($_POST['security'],'security') || !is_numeric($quiz_id)){
  49. _e('Security check Failed. Contact Administrator.','vibe');
  50. die();
  51. }
  52. $user_id = get_current_user_id();
  53. $passing_marks = get_post_meta($quiz_id,'vibe_quiz_passing_score',true);
  54. $marks = get_post_meta($quiz_id,$user_id,true);
  55. if($marks > $passing_marks){
  56. echo json_encode(array(
  57. 'status' => 1,
  58. ));
  59. }else{
  60. echo json_encode(array(
  61. 'status' => 0,
  62. ));
  63. }
  64. die();
  65. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement