Parameter help with answer
#1
Question 
I have a problem. I'm trying to use a function that is tied to the handle "redirect". Obviously this is called from a lot of places.
I figured that I could determine where it came from if I could get the message value. So I could tell a user had edited a post if the message passed into the redirect function was equal to $l['redirect_postedited']. No problem.

But you can't get the $message value unless it was already defined global throughout the function calls. In this instance, the function stack is redirect->run_hooks->my_function. But it's not decalred global in run_hooks.

One thing I managed to do was use debug_backtrace(). It gives you an array of all the functions and arguments that were called to get to the current function.

Try the following

$plugins->add_hook("redirect", "temp_redirect");

function temp_redirect(){
   global $lang, $mybb, $message;
   if($message == $lang->redirect_postedited){
      echo "Edited post - Message retrieved from the redirect function";
   }
   $debug = debug_backtrace();
   $debug_message = $debug[3]['args'][1];
   if($debug_message == $lang->redirect_postedited){
      echo "Edited post - Message from the backtrace";
   }
}

If you put that in a plugin file and then try editing a post, you should only get one echoed message.
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)