0

I have two functions on my functions.php

Both functions are from a plugin and I'm trying to use this variable $answerIndex in the other action to do the if condition.

The issue is I'm trying with global variables but it's not working, am I doing something wrong?

add_action('quiz_completed', 'mi_ld_quiz_ert', 10, 2);
function mi_ld_quiz_ert( $quizdata, $current_user ) {
global $globalres;
    if($globalres== 0){
        do_action('ld_update_group_access', $current_user, 2, $remove = false ));
    }else{
        do_action('ld_update_group_access', $current_user, 14, $remove = false ));
    }
}

add_action('learndash_ques_single_answer_correct', 'my_ld_quiz_resp',5,5);
function my_ld_quiz_resp(  $answerIndex, $correctAnswer, $userResponse) {
  global $globalres;
  $globalres = $answerIndex; 
}

The action my_ld_quiz_resp runs first and then mi_ld_quiz_ert.

0

Try

$globalres = '';

add_action('quiz_completed', 'mi_ld_quiz_ert', 10, 2);
function mi_ld_quiz_ert( $quizdata, $current_user ) {
  global $globalres;
  if($globalres== 0){
    do_action('ld_update_group_access', $current_user, 2, $remove = false     ));
  }
  else{
    do_action('ld_update_group_access', $current_user, 14, $remove = false ));
   }
}

add_action('learndash_ques_single_answer_correct', 'my_ld_quiz_resp',5,5);
function my_ld_quiz_resp(  $answerIndex, $correctAnswer, $userResponse) {
  global $globalres;
  $globalres = $answerIndex; 
}
  • Why should the OP try your code? Can you explain what it does and where the OP was wrong? – Tunji Jan 25 '17 at 7:04
  • @MarkV-2 thank you, but I tried it and it didn't work. the variable $globalres is empty in the mi_ld_quiz_ert function. – user-needs-help Jan 25 '17 at 22:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.