MyBB Community Forums

Full Version: well-written
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello. I have a request, I learn to write plugins for MyBB and I wonder what's wrong here?

<?php

f(!defined("IN_MYBB"))
{
    die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

// add hooks
$plugins->add_hook('index_start', 'mytest_function', 10, '');

// Stanard MyBB function with informations about plugin
function mytest_info()
{
    return array(
        "name"            => "Nagłówek do PS-Games",
        "description"    => "Dodaje aktywne zakładki jak w IPB",
        "website"        => "[email protected]",
        "author"        => "Inaro",
        "authorsite"    => "[email protected]",
        "version"        => "1.0",
        "guid"         => "",
        "compatibility"    => "16*"
    );
}

if($current_page2=="index" || $current_page2=="portal" || $current_page2=="games" || $current_page2=="game" || $current_page2=="search" || $current_page2=="services" || $current_page2=="announcements" && $mybb->input['aid']==1)
	{
		$currentitem[$current_page2]="current-item";
	}
	else
	{
		$currentitem["index"]="current-item";
	}
?>
(2011-10-31, 09:03 AM)Inaro Wrote: [ -> ]Hello. I have a request, I learn to write plugins for MyBB and I wonder what's wrong here?

<?php

f(!defined("IN_MYBB"))
{
    die("Direct initialization of this file is not allowed.<br /><br />Please make sure IN_MYBB is defined.");
}

// add hooks
$plugins->add_hook('index_start', 'mytest_function', 10, '');

// Stanard MyBB function with informations about plugin
function mytest_info()
{
    return array(
        "name"            => "Nagłówek do PS-Games",
        "description"    => "Dodaje aktywne zakładki jak w IPB",
        "website"        => "[email protected]",
        "author"        => "Inaro",
        "authorsite"    => "[email protected]",
        "version"        => "1.0",
        "guid"         => "",
        "compatibility"    => "16*"
    );
}

if($current_page2=="index" || $current_page2=="portal" || $current_page2=="games" || $current_page2=="game" || $current_page2=="search" || $current_page2=="services" || $current_page2=="announcements" && $mybb->input['aid']==1)
	{
		$currentitem[$current_page2]="current-item";
	}
	else
	{
		$currentitem["index"]="current-item";
	}
?>

f(!defined("IN_MYBB")) should be if(!defined("IN_MYBB"))
You need to define the function name the hook is using aswell. e.g. in your case, the function would be;

function mytest_function()
{
   global $mybb, $templates;

// Your code goes here
}

You can also use THIS_SCRIPT == "index.php" instead of $current_page2=="index" etc.