WordPress.org

Ready to get started?Download WordPress

Forums

Plugin functions to use on other plugins (4 posts)

  1. shmk
    Member
    Posted 10 months ago #

    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?

  2. ajmcfadyen
    Member
    Posted 10 months ago #

    <?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

  3. shmk
    Member
    Posted 10 months 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
    Member
    Posted 10 months 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.

Reply

You must log in to post.

About this Topic