Plugin functions to use on other plugins (4 posts)

  1. shmk
    Posted 2 years ago #

    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?

  2. ajmcfadyen
    Posted 2 years ago #

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

    this should work:

    add_action('init', 'getMyFunction');

    contents of something-epic.php:


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

  3. shmk
    Posted 2 years ago #

    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?

  4. bcworkz
    Posted 2 years ago #

    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.

Topic Closed

This topic has been closed to new replies.

About this Topic