MyBB Community Forums

Full Version: Plugin development question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So I'm trying to develop some simple plugin which will hook into for example inc/functions.php. 

Now I want to target for example error(); function and replace it or include a new one

How should I do that? Or into forumdisplay.php to target.

What are the proper ways to target specific file and location
I’m confused. Are you trying to write your own custom error message?
(2019-06-06, 11:56 AM)codedude Wrote: [ -> ]So I'm trying to develop some simple plugin which will hook into for example inc/functions.php. 

Now I want to target for example error(); function and replace it or include a new one

How should I do that? Or into forumdisplay.php to target.

What are the proper ways to target specific file and location

It seems like you have a basic misunderstanding of the plugin system.

In short, the plugin system allows you to write a PHP file, with specific functions that provide information to the MyBB forum system, allowing the admin to activate/deactivate the plugin, and perhaps install/uninstall it depending on the plugin's needs.

The other main component of a plugin are hooks. Hooks aren't arbitrary. In other words, you can't just decide that you want to hook into the code anywhere that you want. There are specific points which you can add your own functionality to MyBB.

Replacing the built-in error() function isn't doable with plugin hooks. For that, you would need a core edit.
(2019-06-06, 08:39 PM)Wildcard Wrote: [ -> ]
(2019-06-06, 11:56 AM)codedude Wrote: [ -> ]So I'm trying to develop some simple plugin which will hook into for example inc/functions.php. 

Now I want to target for example error(); function and replace it or include a new one

How should I do that? Or into forumdisplay.php to target.

What are the proper ways to target specific file and location

It seems like you have a basic misunderstanding of the plugin system.

In short, the plugin system allows you to write a PHP file, with specific functions that provide information to the MyBB forum system, allowing the admin to activate/deactivate the plugin,  and perhaps install/uninstall it depending on the plugin's needs.

The other main component of a plugin are hooks. Hooks aren't arbitrary. In other words, you can just decide that you want to hook into the code anywhere that you want. There are  specific points which you can add your own functionality to MyBB.

Replacing the built-in error() function isn't doable with plugin hooks. For that, you would need a core edit.

Yes i wanted to write my own error2() function which would be executed globally or maybe on specific page for example forumdisplay.php
I don't have a lot of information, but it sounds like you need to hook into one of the forumdisplay_ hooks, depending on which errors you are trying to catch.

This is how I would go about it.

Using whatever code editor, open forumdisplay.php and search for $plugins->run_hooks. Each time you find that string in the code establishes a hook that you can utilize in your plugin. Now, find the section in the code where the error could occur that you want to catch, and find the hook that runs before the error is output, or if there isn't one, you will have to hook in at the beginning of that section and try to intercept the error condition independently.

Keep in mind that the sytem isn't limitless. In other words, you can't accomplish any and all customizations through this process.