WordPress.org

Support

Support » Plugins and Hacks » Hacks » Plugin functions to use on other plugins

Plugin functions to use on other plugins

  • Hello,
    I have to wrote a plugin with a function that has to be recalled by another plugin (or maybe more than one).

    I have to insert this function in a particolar point of the plugin to make it visible to all plugins?
    How can I load my plugin before other plugins?

Viewing 3 replies - 1 through 3 (of 3 total)
  • ajmcfadyen

    @ajmcfadyen

    <?php require_once(‘path to file with function you need dot whatever’); ?>

    this should work:

    function()getMyFunction{
      require_once('something_epic.php');
    }
    add_action('init', 'getMyFunction');

    contents of something-epic.php:

    <?php
    yourFunction(){
        ...awesome-code!
      }

    More here: http://codex.wordpress.org/Function_Reference/add_action

    Thank you!

    If my_function is used by other plugins but only in the backend I have to use ‘admin_init’ instead, or ‘init’ is fine?

    Moderator bcworkz

    @bcworkz

    I hope you both don’t mind my jumping in.

    ‘init’ will work, but it’s not really ‘fine’. Using ‘init’ will cause your code to be needlessly loaded many many times. If everyone did this, it would drag down the whole system. ‘admin_init’ is much better for backend code, it is more likely to be loaded only when needed.

Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘Plugin functions to use on other plugins’ is closed to new replies.
Skip to toolbar