MyBB Community Forums

Full Version: Combine 2 plugins into one
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
Just is it possible to combine 2 plugins with different functions into one?



Do I need to add function_1 function_2
Yes, it is possible. I don't see why you would though. If you developed both plugins, you should know how the hook system works and therefore be able to do it quite easily.
function validator (&$post) I would like to make 2 of these how to do that. Both plugins are using the same hooks
Just name the functions differently and use add_hook:

$plugins->add_hook('postbit_start', 'someFunction1');
function someFunction1(&$post)
{
    // Do stuff with $post
}

$plugins->add_hook('postbit_start', 'someFunction2');
function someFunction2(&$post)
{
    // Do other stuff with $post
}
Thank very much I was actually thinking about this +1
What about:

$plugins->add_hook('postbit_start', 'commonFunction');
function commonFunction(&$post)
{
    // Do stuff with $post as was in first plugin.

    // Do stuff with $post as was in second plugin.
}
I mean no disrespect but I prefer your version @effone
Remember that functions ideally shouldn't be massive behemoths that do many things. having multiple functions that do single, separate things is a more than valid practice.
^exactly

What you gain in efficiency you will lose when you attempt to extend or debug the system.

Some things like specific MyCode plugins would be better lumped together-- but like Euan said, they should be fairly simple plugins if they are joined at all.
So are you saying that is best to use 2 plugins instead of one?
Pages: 1 2