MyBB Community Forums

Full Version: How to avoid editing files?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hello, I am developing a little mod. I have edited some files to do the extra stuff I need. But the other mods don't require the user to edit files. I know how hooks system works but how can I replace a function? I have edited some functions and I want to use my functions when mod is active. Can you please tell how can I do that?
Let's say you want to replace function x() (for example) and in your plugin the altered function is called pluginname_x(). If your plugin is not activated the file is not included, so the function doesn't exists. This mean you can check whether or not the function exists in the original function and call it if it exists:
function x()
{
    if(function_exists('pluginname_x'))
    {
          return pluginname_x();
    }
    // ...
Thanks for the reply! Big Grin

First of all I done a big mistake saying I want to replace a function with a function. I want to replace a piece of code with a function. I am sure you are right but I can't exactly understand what are you saying... My english and my explanations aren't good enough... Sad

For example I want to replace
if($mybb->settings['showbirthdays'] != 0) //(lines 168-223 on file index.php)
with my own $showbirthdays_new function I have on file my_mod_stuff.php

I am adding a hook at "index_start" and then I want to say to the MyBB:
1) to ignore lines 168-223 and
2) include $showbirthdays_new function.

I wish I explain it a bit better. Smile
You could use this plugin: http://mods.mybb.com/view/patches
It allows you to manage core modifications.
Thanks! It does exactly what I need but if it's for personal use. Can I done this without that plugin, because if I am gonna release my mod, I don't won't everyone to have to use this plugin... I am trying to do this with a single activate button... Is it possible?
If it's really not possible to alter the functionality you want using hooks, you can include instructions to do the core modifications.

What exactly do you want to do? If you don't want to discuss this publicly, you can always PM me and I will see if there is any alternative way to do it without doing a core mod.