MyBB Community Forums

Full Version: Plugin "var" Help Required.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm having a problem with a plugin not recognising the normal url variables.

IE:
{$theme['imgdir']}

Can / Would, someone point me to a plugin that uses theme images rather than the /images, Hard-Coded path which uses the default images.

I've tried:

require_once
"global.php";

But I'm missing something. Sad

Also I would rather look at a plugin that uses the MyBB variables, to expand my understanding of how the whole thing is put together.

If there isn't one, then any help would be more than appreciated. Smile
Did you add the variable $theme to the globals in the function?
function blah() {
    global $theme;
    ...
}
Michael, Toungue

That's all Double-Dutch to me at the moment... Wink

That's why I would like to study an existing plugin that uses image varaibles.

I don't want to be a pain and start asking thinks like:

Where do I add this or that??

What do I do next.. ??

I can relate to the code structure of the plugins; all I want to do is to not bother too many people with too many questions on this.

If I can't work out the basics from examples, then I'll be a pain in the butt... Toungue
In each of your plugin hooks where you wish to access the theme variables, right under the function declaration, add the line Michael suggested:
global $theme

An example would be:
<?php
/**
 * MyBB 1.2
 * Copyright © 2006 MyBB Group, All Rights Reserved
 *
 * Website: http://www.mybboard.com
 * License: http://www.mybboard.com/eula.html
 *
 * $Id: hello.php 2262 2006-09-26 08:00:35Z chris $
 */

// 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("pre_output_page", "hello_world");

function hello_info()
{
	return array(
		"name"			=> "Hello World!",
		"description"	=> "A sample plugin that prints hello world and changes the content of each post to 'Hello world!'",
		"website"		=> "http://www.mybboard.com",
		"author"		=> "MyBB Group",
		"authorsite"	=> "http://www.mybboard.com",
		"version"		=> "1.0",
	);
}

function hello_activate()
{
}

function hello_deactivate()
{
}

function hello_world($page)
{
	global $theme;
	$page = str_replace("<div id=\"content\">", "<div id=\"content\"><p>Hello World!<br />Your theme image directory is {$theme['imgdir']}</p>", $page);
	return $page;
}

?>

Once you've added the global line it means you can also reference to the $theme array in any templates which are called from within the plugin hook.

Regards,
Chris
Whooo Hoooo............. Thanks Chris,

That's what I call a perfect example, and from that I can see how the whole thing starts to fit together.. I think... Smile

Me also thinks Michael thinks that I'm more experienced when I'm not very experienced at all.. But I do appreciate the response, only I honestly didn't know what to do with it. Wink

But now that I see the whole array, it all makes sense.. Smile