Upgrading your MyBB 1.2 plugins for MyBB 1.4
The following is a small tutorial providing information on some changes between MyBB 1.2 and MyBB 1.4:

There are 4 new optional functions for use in MyBB 1.4's plugin architecture:

_install, _is_installed and _uninstall - which are all optional

There are also two new keys for use in the _info() function: "compatibility" and "guid" - Again these are both optional.

Here is the sample MyBB 1.4 hello world plugin for those of you who are visuals:

 * MyBB 1.4
 * Copyright © 2007 MyBB Group, All Rights Reserved
 * Website: http://www.mybboard.net
 * License: http://www.mybboard.net/about/license
 * $Id: hello.php 3306 2007-09-13 05:29:43Z Tikitiki $
// Disallow direct access to this file for security reasons
	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");
$plugins->add_hook("postbit", "hello_world_postbit");

function hello_info()
	 * Array of information about the plugin.
	 * name: The name of the plugin
	 * description: Description of what the plugin does
	 * website: The website the plugin is maintained at (Optional)
	 * author: The name of the author of the plugin
	 * authorsite: The URL to the website of the author (Optional)
	 * version: The version number of the plugin
	 * guid: Unique ID issued by the MyBB Mods site for version checking
	 * compatibility: A CSV list of MyBB versions supported. Ex, "121,123", "12*". Wildcards supported.
	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.net",
		"author"		=> "MyBB Group",
		"authorsite"		=> "http://www.mybboard.net",
		"version"		=> "1.0",
		"guid"			=> "",
		"compatibility"	=> "*"

 * _install():
 *   Called whenever a plugin is installed by clicking the "Install" button in the plugin manager.
 *   If no install routine exists, the install button is not shown and it assumed any work will be
 *   performed in the _activate() routine.
 * function hello_install()
 * {
 * }
 * _is_installed():
 *   Called on the plugin management page to establish if a plugin is already installed or not.
 *   This should return TRUE if the plugin is installed (by checking tables, fields etc) or FALSE
 *   if the plugin is not installed.
 * function hello_is_installed()
 * {
 *		global $db;
 *		if($db->table_exists("hello_world"))
 *		{
 *			return true;
 *		}
 *		return false;
 * }
 * _uninstall():
 *    Called whenever a plugin is to be uninstalled. This should remove ALL traces of the plugin
 *    from the installation (tables etc). If it does not exist, uninstall button is not shown.
 * function hello_uninstall()
 * {
 * }
 * _activate():
 *    Called whenever a plugin is activated via the Admin CP. This should essentially make a plugin
 *    "visible" by adding templates/template changes, language changes etc.
 * function hello_activate()
 * {
 * }
 * _deactivate():
 *    Called whenever a plugin is deactivated. This should essentially "hide" the plugin from view
 *    by removing templates/template changes etc. It should not, however, remove any information
 *    such as tables, fields etc - that should be handled by an _uninstall routine. When a plugin is
 *    uninstalled, this routine will also be called before _uninstall() if the plugin is active.
 * function hello_deactivate()
 * {
 * }

function hello_world($page)
	$page = str_replace("<div id=\"content\">", "<div id=\"content\"><p>Hello World!<br />This is a sample MyBB Plugin (which can be disabled!) that displays this message on all pages.</p>", $page);
	return $page;

function hello_world_postbit($post)
	$post['message'] = "<strong>Hello world!</strong><br /><br />{$post['message']}";

Here's what you will have to change for most plugins:

1) Remove TABLE_PREFIX. from $db->simple_select, $db->update_query, $db->insert_query, $db->delete_query, $db->table_exists, the second argument in $db->field_exists, $db->optimize_table, $db->analyze_table, $db->show_create_table, $db->show_fields_from, $db->is_fulltext, $db->supports_fulltext, $db->supports_fulltext_boolean, $db->create_fulltext_index, and $db->drop_index

$db->query will still use TABLE_PREFIX as we have no way of automatically detecting it in the query and it's more of a lower-level function on the DB Layers;

the table prefix can be changed via $db->set_table_prefix(arg1 prefix) (Note: it does NOT redefine TABLE_PREFIX; You will have to do that in your own code if you change it via $db->set_table_prefix)

We've added some new functions such as:
$db->replace_query(arg1 table, arg2 replacements)
$db->fetch_size([arg1 table])
$db->drop_table(arg1 table, [arg2 hard drop, [arg3 table prefix]])
$db->free_result(arg1 query resource)

$db->write_query - Acts the SAME as $db->query except write queries are only executed on the master server. This is because we've implemented technologies to allow people to have multiple MySQL servers for huge setups (http://www.ncaabbs.com/forums/ for example)

I suggest to anyone who wishes to prepare their code for MyBB 1.4 they use the internal database wrapper functions as much as possible (i.e. $db->update_query) because now that we support SQLite 2, SQLite 3, and PostgreSQL using some MySQL syntax run directly into $db->query will not process correctly. However, using the wrapper functions such as $db->update_query, we can setup the queries for you in the correct syntax.

To explain $db->write_query more, it is used for queries that run INSERTS/UPDATES/DELETES/ALTER statements on the database which should only be run the the Master server because of the way MySQL Replication setups works. So if you want your plugin/modification to be used on a large forum like the NCAAbbs and want to prepare your code for MyBB 1.4 I highly suggest you use $db->write_query for any of those queries that are INSERTS/UPDATES/DELETES/ALTER and do not already take advantage of the $db->update_query, $db->insert_query, etc wrappers.

For those of you who have queries that cannot fit into the $db->update_query, $db->insert_query wrappers and uses $db->query or $db->write_query and have compatibility problems with either version of SQLite or PostgreSQL then you can take advantage of a new variable in the database class called $db->type;

Here is an example:
	case "pgsql":
	case "sqlite3":
	case "sqlite2":
		$query = $db->simple_select("modtools", "tid, name, type", "','||forums||',' LIKE '%,$fid,%' OR ','||forums||',' LIKE '%,-1,%'");
		$query = $db->simple_select("modtools", "tid, name, type", "CONCAT(',',forums,',') LIKE '%,$fid,%' OR CONCAT(',',forums,',') LIKE '%,-1,%'");

There are also some DB Engine specific functions to help work around some specific problems in their respective Server Query Languages which we will discuss at a later time

If your plugin was built to add a page within the MyBB 1.2 ACP or modify some ACP code on the fly then there is no point in trying to update it now since the amount of changes in the new ACP (after all... it's been rewritten) will require you to rewrite it anyway; Also, unfortunately, at this time we're not releasing any of the new ACP code or pictures or any of that. Note: You do NOT have to change anything related to settings as those still have the same database schema.

Getting away from the database changes, the rebuildsettings() function has been renamed to rebuild_settings() BUT rebuildsettings() still exists so plugins will still work for those mod authors who don't change that; But I highly recommend you do change it to rebuild_settings() as rebuildsettings() will likely be removed in the coming versions after MyBB 1.4.

Update 10/8/07:
Today I'm going to continue to discuss changes made to MyBB that will affect your plugins and how to correct it. All of the yes/no columns have been converted to 1/0 for better storage and search efficiency. So if you have for instance a setting in your plugin that is "yesno" or "onoff" you will now need to check it against 1/0. Please note that this change is still considered in development, and changes may be made at a later time.

There is still tons of more stuff that has been changed and could affect your plugin but we are not ready to release documentation on code changes between MyBB 1.2 and MyBB 1.4 and is beyond the scope of this tutorial.

I will update with more information on what has been changed as we come closer to release.

Hope this helps!

Nice tut but for the title don't you mean "Upgrading your MyBB 1.2 plugins for MyBB 1.4"
[Image: jag100sigaf5.jpg]
[Image: poptartFINALTINY.gif]
//starts learning =P
hello dear.. is that mean that, the plugins we are using now will not work as well in mybb 1.4 ?
Official Arabic Translator.
Most MyBB 1.2 mods WILL NOT work in MyBB 1.4 without being updated using the instructions outlined above.
[Image: sig.php]
The little boat gently drifted across the pond exactly the way a bowling ball wouldn't.
Sorry to point out the obvious... but how did you not expect to have to upgrade your plugins on a huge release update like MyBB 1.4?
Good to know, thanks Tiki. Smile
See my "Update 10/8/07" for some more information on how to upgrade your plugin.
Thanks for instructions.This will help.
->The best web chat International Chat
->My Mods & Plugins
When is 1.4 will be released?

Forum Jump:

Users browsing this thread: 1 Guest(s)