Log in

View Full Version : Callback Function and $GLOBAL variable


Farcaster
02-15-2008, 09:02 AM
I am writing a modification that adds a custom bbcode tag.

So, I have this that is being eval'd on the bbcode_create hook:


if (!function_exists('handle_bbcode_roll'))
{

function handle_bbcode_roll(&$parser, $text, $option)
{

// MOVED FROM IF (class_exists...
$GLOBALS['dicehistory'] .= "$text";

if (class_exists('vB_BbCodeParser_Wysiwyg') AND is_a($parser, 'vB_BbCodeParser_Wysiwyg'))
{
return $text;
} else {


return "<div><span class=\"die_description\">* $text *</span></div>";
}
}
}

$this->tag_list['option']['roll'] = array(
'callback' => 'handle_external',
'strip_empty' => false,
'stop_parse' => true,
'disable_smilies' => true,
'disable_wordwrap' => true,
'strip_space_after' => 1,
'external_callback' => 'handle_bbcode_roll'
);

Later in the postdata_presave, I am trying to access this $GLOBALS['dicehistory'], and I am getting nothing at all. It seems that I cannot access the global array from within the callback function. Can anyone tell me why this is and how I can pass something back to be accessed during postdata_presave? (Forget that this particular example is pretty meaningless.. I do have a reason for wanting to do this)

Marco van Herwaarden
02-15-2008, 09:08 AM
Okay let's take this step by step.

First are you sure that this part of the code is executed, or does it only execute the first part of the if (ie. have a valid 'vB_BbCodeParser_Wysiwyg')

Farcaster
02-15-2008, 03:55 PM
It was parsing the tag as I expected, but just to test, I moved the $GLOBALS['dicehistory'] outside of the IF statement (modified PHP above to reflect). It had no effect. The variable is still empty when I try to access it either in the postdata_presave or even bbcode_parse_complete.

And thank you for trying to help! I appreciate it.