The Arcive of vBulletin Modifications Site. |
|
|
#1
|
|||
|
|||
|
I've searched everywhere and I can't find a definitive answer to my question. I'm having trouble getting a user defined php function to execute inside of a custom block.
Code:
$my_output = 'Bad';
if(!function_exists('good'))
{
function good()
{
$my_output = 'Good';
}
}
good();
return $my_output;
Also, do these same issues arise if I define the php code as a plugin? I haven't been able to get it to work that way either and I figured it would be better to define the code in the block anyways. |
|
#2
|
|||
|
|||
|
Where are you currently installing your custom code? Typically custom code is installed via the Product/Plugin system.
|
|
#3
|
|||
|
|||
|
You need to make sure $my_output is a global variable. You need a global statement inside the good() function, and you also may need one at the beginning of the plugin code, depending on the hook being used. So try something like:
Code:
global $my_output;
$my_output = 'Bad';
if(!function_exists('good'))
{
function good()
{
global $my_output;
$my_output = 'Good';
}
}
good();
return $my_output;
ETA: or you could use a reference parameter or return a value from good(), but probably your actual code is different than the example you posted, so maybe that won't work. |
|
#4
|
|||
|
|||
|
Thank you for the global suggestion I think that would solve part of the problem, but I don't think that was entirely the issue because I've tried returning straight from the function and it never executed.
I did solve my problem though, I just got rid of the function because it seems like too much of a hassle to try to work around. Was easier to just execute the code where needed. To answer the first question, in a forum block. It's not a large chunk of code, but I needed to do a call to the database and some manipulating. The function was just for output formatting so I just scrapped it. |
![]() |
|
|
| X vBulletin 3.8.12 by vBS Debug Information | |
|---|---|
|
|
More Information |
|
|
Template Usage:
Phrase Groups Available:
|
Included Files:
Hooks Called:
|