MyBB Community Forums

Full Version: Including plugin hooks in task file
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm currently working on a plugin that writes a new post every two weeks with updated information for my members. The way I'm currently doing it is I have a query running when my task file runs, so I know that is a possibility. What I'm wanting to know is if we can hook into plugin files in task files. I'd like to keep my information as together as possible in the plugin file if possible, and I wasn't able to find a conclusive answer to this question by searching the boards.

Thanks!
Unfortunately, you can't hook directly in the tasks files in MyBB 1.6. The way they are built (without requiring any external file, therefore not initializing the $plugin object) doesn't let you do what you need.

Also, keep in mind that every /inc/tasks file is "unique" as only one function per file is executed when they need to be (and the execution relies on the file's name, eg.: a file called myexample.php executes only a task_myexample()).
Well that's unfortunate. Is that a feature that might be added in 1.8 or 2.0?

Thanks for the quick response.
I don't know, but you can suggest to add this in the next releases in the 1.8 Suggestions Forum.

Anyway, you can manually add a core edit to any task file you want with this code to init the $plugin object:

if(!is_object($plugins)) {
    require_once MYBB_ROOT . "inc/class_plugins.php";
    $plugins = new pluginSystem;
}

And then you can add whatever hook you want in that task. By the way, editing the core is not recommended.
(2013-12-15, 07:18 PM)Shade Wrote: [ -> ]And then you can add whatever hook you want in that task. By the way, editing the core is not recommended.

If I'm making my own task file anyway, it wouldn't exactly be a core edit. Wink Thanks for that bit of code, I might give it a try. I only need to run one query, so it might be easier to just hard code straight into the task file I'm creating.
IIRC a hook is supposed to be included in the task file. I thought it was already done..