Log in

View Full Version : Plugin Coding Question: Function Syntax


ThePimp
03-28-2006, 03:11 PM
What is the proper syntax for calling a function in a plugin?

Here's my issue, I'm including a file that defines a function called newsfeed().

Here's my plugin code currently: (HOOK: global_complete)
ob_start();
include('magpierss/rss_parse.inc');
newsfeed("http://rss.cnn.com/rss/cnn_topstories.rss",5,"CNN HEADLINES");
$cnn=ob_get_contents();
ob_end_clean();

This is supposed to output an rss feed wherever I call $cnn.

However, what happens, is that the feed shows up at the very top of the page, not where I put the $cnn call.

Is there something I'm not doing properly?

Any help is appreciated.

Thanks in advance.

Krofh
03-28-2006, 04:15 PM
It could likely not be accessing the variable $cnn correctly... when you have a variable inside a function, you have to make it global, which I think works like so:

global $cnn; // define it outside of the function

function myfunction() {
global $cnn; // call it from outside so it knows
dostufff();
$cnn = something();
}

echo "$cnn";

Someone can correct me on this, because I'm not great with global variables, but I'm pretty sure that this is how they work.

ThePimp
03-28-2006, 04:51 PM
It could likely not be accessing the variable $cnn correctly... when you have a variable inside a function, you have to make it global, which I think works like so:

global $cnn; // define it outside of the function

function myfunction() {
global $cnn; // call it from outside so it knows
dostufff();
$cnn = something();
}

echo "$cnn";

Someone can correct me on this, because I'm not great with global variables, but I'm pretty sure that this is how they work.
The function is defined outside of the plugin system. I have to include the file in order to access the newsfeed() function.

So, really, all the plugin needs to do is:
include("functionfile.php");

newsfeed()

And that's it.

I got it to work, it just doesn't show up in the right place.

bump