So as the time comes closer to the MyBB release, I guess it’s time to tell you guys that we will have broken a lot of older code modifications and plugins due to the extensive changes in MyBB 1.2. Each and every template has also changed to conform to our new standards.
This is a short guide on how to ensure your code modifications and plugins are ready for MyBB and what changes will be required for your modifications to work with 1.2 as well as other code based changes.
Function Calls
One of the major changes is that most of the functions within MyBB have renamed to make more sense and make them more understandable when reading the code.
Example changes include:
- outputpage becomes output_page
- getparentlist becomes get_parent_list
- nopermission becomes error_no_permission
- ismod becomes is_moderator
- updateforumcount becomes update_forum_count
Generally, underscores are used to break the function name up so it becomes readable. Most functions are prefixed with a verb such as output, update, get, do, format, or build. You’ll need to check functions.php closer to the release for the new names of functions.
The other change in regards to function calls is that several are now deprecated and no longer exist within MyBB. postify, domecode, domycode are examples of these functions which no longer exist and have been replaced in some way, shape or form (The post parser is now a class)
Accessing Internal MyBB Variables
The $settings and $mybbuser variables became deprecated in MyBB 1.0, however we left in support for them due to the vast number of modifications still using them.
MyBB 1.2 no longer contains these references, and only supports accessing them through the MyBB class variable ($mybb). For example:
- $settings becomes $mybb->settings
- $mybbuser becomes $mybb->user
Get and Post Variables
Introduced with 1.0 along with the MyBB core class was a standardised way of accessing input (Get and Post) variables as well as having common variables such as thread ID (tid) and pid (post ID) automatically filtered for bad input. We also had in place code which would not kill global variables such as $tid, $pid assigned from Get or Post input when register_globals was turned on within PHP and the KILL_GLOBALS constant was not defined.
Up until 1.2, if you still followed old coding conventions with register_globals turned on, this would have worked. You are now required to either use $_GET, $_POST or preferably $mybb->input to fetch incoming data.
Variables within Templates
We were sloppy in MyBB with variables (specifically arrays) in templates. We still used $example[hi] instead of $example['hi'] because our template parser (using eval) did not support this. MyBB 1.2 now uses, by default, variables enclosed within curly braces such as {$example['hi']}. The same applies for class variables.
Database Querying
MyBB 1.0 introduced $db->update_query and $db->insert_query methods for inserting data into a table within a database. We’ve further extended the database abstraction layer by adding a few more methods:
- fetch_field - Fetch one specific field from a row being queried
- simple_select - Used to perform a simple select query (with no joins) on a table
- delete_query - Used to perform a delete query on a table in a database
- escape_string - Replaces addslashes, escapes data before being used in a query
- get_version - Returns the version number of the database server being used
That is just a handful of some of the new methods available in the release. You should make proper use of them when necessary to ensure your queries are cross compatible with different database engines. This release also includes a MySQLi database abstraction layer which is used in preference over MySQL if your server supports it.
Good Clean Code and Coding Standards
The MyBB coding standards have basically been rewritten to conform to stricter policies making code easier to read and write.
- Code should be commented so that a user can understand what is happening
- Functions should be descriptively named, contain underscores to break words and contain PHPDoc headers
- Queries are now split on to multiple lines allowing you to quickly identify what is selected, from where, where joins are and the conditions/limits of the query
Full coding standards will be released along side the MyBB 1.2 release.
This is just a small overview of what has changed with MyBB 1.2. It is by no means a comprehensive guide and things will probably still change before the release.
I’ve probably managed to scare a few people off now by stating that most modifications will not work without further code changes, but MyBB 1.2 brings in many, many and even more advantages and features than any other MyBB release and you should be looking forward to it. It is a huge step for us, and probably you too.