WordPress.org

Forums

Plugin functions to use on other plugins (4 posts)

  1. shmk
    Member
    Posted 1 year 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 1 year 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 1 year 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 1 year 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