MyBB Community Forums

Full Version: Plugin functions and templates
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi, I'm trying to create a plugin for myBB, but now I ran into a few problems.

1) How can I modify a saved post message from within a plugin function before it's being displayed? Like a parser for example.

2) I would like to ask the user something after he pushed the Post Reply button? And depending on his answer, I would like to continue with saving the message to the database or go back to edit his post.

Can somebody point me into the right direction? I would really appreciate your help ...
1) In a plugin, you can use this hook:
$plugins->add_hook("parse_message", "modify_message");
and then use this function:
function modify_message($message)
{
	//HERE YOU CAN DO WHATEVER YOU WANT WITH THE MESSAGE for example
	//$message = preg_replace("#three#i","3", $message);
	return $message;
}
2) You can change the template of the new reply page and make it so that when you click the Post Reply button, a javascript confirm message appears. If the answer to the question is yes, they should click OK, else they have to click Cancel. When it's yes, you can let the script continue and save the reply. Example Javascript Alert and Confirm
Thanks for the reply on the first question. It's very usefull Big Grin
Smethead Wrote:2) You can change the template of the new reply page and make it so that when you click the Post Reply button, a javascript confirm message appears. If the answer to the question is yes, they should click OK, else they have to click Cancel. When it's yes, you can let the script continue and save the reply. Example Javascript Alert and Confirm
This would be a solution, but the question should not always appear. Only after a database check. I already tried it with printing the script tags with php. That works but then I get an error that he couldn't change the header information (= location)
Anyone?

And also another question: how can I read an admin setting? Now I wrote a function to search the settings table, but I guess mybb has a thing for this ... And also how to read out a users settings?
Aries-Belgium Wrote:Anyone?

And also another question: how can I read an admin setting? Now I wrote a function to search the settings table, but I guess mybb has a thing for this ... And also how to read out a users settings?
I can't help you with the button thing.

But the settings are these:
$mybb->settings['name_of_the_setting'] //for board settings
$mybb->user['name_of_the_setting'] //for user settings
$mybb->usergroup['name_of_the_setting'] //for usergroup settings

The name of the setting can be found either by looking in the database in the settings, users and usergroups table, or by editing a setting in AdminCP.
if you use this inside a function, then you need to add this at the top of your function:
global $mybb;
Okay, thanks. Big Grin