MyBB has various PHP classes - $mybb, $db for example. To use these in our own plugins and other functions, we need to include their global variable. If you're not so sure about this, let's take a look at the _is_installed function for our plugins:
function hello_is_installed() { global $db; if($db->table_exists("hello_world")) { return true; } return false; }
Here, we're using the $db variable. This lets us access various MyBB methods to interact with the database (such as insert, write, delete etc.). We can only do this if we include this variable, and to do that, we use global to use it in the function. For a full list of MyBB database methods, see the Database Methods page.
In the next example, we use the $mybb variable to find out if the current user is an Admin / Super Moderator.
function hello_only_show_this_to_admins_and_supermods() { global $mybb; if($mybb->usergroup['isadmin'] == 1 || $mybb->usergroup['issupermod'] == 1) { return true; } return false; }
We can use two or more variables, we just do this:
global $db, $mybb, $templates, $lang, $plugins;
That means we can use MyBB variables in our plugins instead of writing our own functions which do the same thing.
For a common list of available variables, see the Plugin Methods page. You can also change templates using your plugins and through MyBB code. To find out how, read the Changing Templates page.