MyBB Documentation

Plugin Hooks - Post Parser

The 1.6 Documentation is no longer maintained and some information may be outdated.

The MyBB 1.6 series reached end of life on October 1, 2015.

This means there will be no more security or maintenance releases for these series and forums running these versions of MyBB may be at risk of unfixed security issues. All administrators are strongly encouraged to upgrade their forums to the latest release of MyBB as soon as possible.

Contents

The post parser hooks allow you to modify a posts contents before it's output. It's most common uses include filtering words, MyCode and changing the posts contents.

The parse_message_start hook is run before any processing of the message occurs. When the hook is run, it passes the message contents as the first parameter of the function, and the new message contents will be set to the return value. An array of parsing options can be accessed through the global $options, which is an array of the following:

  • allow_html
  • allow_smilies
  • allow_mycode
  • nl2br
  • filter_badwords
  • me_username
  • shorten_urls
  • highlight

The parse_message hook is run after most of the parsing has been done, but before newlines have been parsed. When the hook is run, it passes the message contents as the first parameter of the function, and the new message contents will be set to the return value. It is useful to parse anything else after the rest of the parsing has occurred. As with parse_message_start, an array of parsing options can be accessed through the global $options.

The parse_message_end hook is run right before the message has been returned. When the hook is run, it passes the message contents as the first parameter of the function, and the new message contents will be set to the return value. It can be used to modify the final message.

Similar to parse_message_end, the text_parse_message hook is run right before the message has been returned, but in the text_parse_message function. The text_parse_message function turns the message into plaintext, removing any MyCode tags. An array of parsing options can be accessed through the global $options, which is an array of the following:

  • filter_badwords
  • me_username

Here is an example of how you would add a [b] (bold) MyCode using the parse_message hook:

$plugins->add_hook("parse_message", "bold_mycode_example");

function bold_mycode_example($message) {
global $options;

if($options['allow_mycode'])
{
$message = preg_replace('#\[b\](.*?)\[/b\]#i', "<strong>$1</strong>", $message);
}

return $message;
}

Edit this page on GitHub