Support » Fixing WordPress » How to call plugin from another plugin ?

Viewing 2 replies - 1 through 2 (of 2 total)
  • That’s actually trickier than it sounds.

    The obvious way is just to call the function. Simple, sometimes it even works. Few problems with it though:
    a) If one plugin is activated and the other is not, you get an error.
    b) Plugin load order is not guaranteed, so if you are trying to call it at plugin init instead of later from a template call or something, the plugin you’re looking for may not have loaded yet.

    You can solve problem A by checking for the function you want before doing anything else.

    Plugin A:
    function call_me(ishmael)
    // do stuff

    Plugin B:
    function caller_func()
    if (!function_exists('call_me')) return;

    This ensures that the function is there, and if it’s not, you can take action accordingly.

    Problem B is solved slightly differently. If you need to check for another plugin at initialization, all you have to do is to make your function initialize after all the plugins load.

    function init_my_plugin()
    // do init stuff

    This way, you can be assured that all plugins are loaded when you do your init routines. And obviously, you’d want the init routine to check for the other plugin’s functions before using them too. Some plugins provide action hooks themselves in their init routines, so you can hook into them directly if you’re heavily dependant on them. WP-Cron does this sort of thing, I think. So does the Sidebar Widgets plugin.

    And that’s basically how you do it.

    thx alot .. i`ll test that!

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘How to call plugin from another plugin ?’ is closed to new replies.