MyBB Community Forums

Full Version: MyBB Plugin Help
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi,

For the life of me, I can't seem to get the following plugin to work.

<?php
// Disallow direct access to this file for security reasons
if(!defined("IN_MYBB"))
{
	die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

$plugins->add_hook("index_start", "bar_run");

function bar_info()
{
	return array(
		"name"		=> "Plugin Name",
		"description"	=> "Plugin Description",
		"website"		=> "",
		"author"		=> "Dutchcoffee",
		"authorsite" 	=> "",
		"version"		=> "1.0",
		"guid" 		=> "",
		"compatibility"      => "*"
	);
}

/*function bar_activate()
{

}*/

function bar_run()
{
    global $mybb, $db, $templates, $bar;
	
	$templatelist = "bar";
    
	eval("\$bar = \"".$templates->get("bar")."\";");
} 
?>

Simply, what it does is selects the "bar" (global) template, and evals it inside the footer template as {$bar}. But, for some reason, I can't get it to do that.
Try adding:
return $bar;

if not, then try re-arranging:
put $bar = eval(...);
First off, if you want to use $templatelist you need to do it outside any functions, otherwsie it's not going to do anything.

Secondly, you'll need to use global_start not index_start if you want this in the footer, otherwise it's only going to show on the index (unless you do actually only want it there).

Returning something wouldn't do anything as this function is just called, you would need to return something if you were doing $bar = bar_run(); or something, the code as it is should work, it's setting the value of $bar.

It works for me when I change the hook to global_start, put $bar in the template and make a global template called bar.
plus $templatelist needs to be a ".=" and not just "="
(2010-09-12, 10:27 AM)MattRogowski Wrote: [ -> ]First off, if you want to use $templatelist you need to do it outside any functions, otherwsie it's not going to do anything.

Secondly, you'll need to use global_start not index_start if you want this in the footer, otherwise it's only going to show on the index (unless you do actually only want it there).

Returning something wouldn't do anything as this function is just called, you would need to return something if you were doing $bar = bar_run(); or something, the code as it is should work, it's setting the value of $bar.

It works for me when I change the hook to global_start, put $bar in the template and make a global template called bar.

Awesome, that worked perfectly Smile