Where to put my global functions?

I currently have a global function in my functions.php file

ein_error_log($message)
{
      //push out $message to file... 
}

But I want to start using it in my MU-Plugin directory and it doesn’t know it exists. So I assume it’s because MU-Plugins folder is read before the theme folder in WordPress’s hierarchy, which makes sense.

But if the hierarchy is the case, how do I distinguish which MU-Plugin runs first to make sure all other MU-Plugin files can run dependent on said file?

— UPDATE–

I have my ein_error_log($message) method transferred into an mu-plugin file. I realized how silly it was to have mu-plugin files dependent on a method inside function.php file. But I still wanted the other mu-plugin files to also use this error logging method. This requires some mu-plugins to have a dependency. Its small, but important to me.

2 Answers
2

Thanks to https://salferrarello.com/functions-plugin-mu-plugin-wordpress/

I was able to confirm when Code Runs

All of the code across the different files of WordPress can be thought
of as one big list of instructions. The code is run line by line
starting at the beginning of this list through to the end of this
list. The order is essentially.

  1. the WordPress
  2. core code
  3. mu-plugins
  4. plugins
  5. functions.php
  6. the theme code for the specific template being displayed

But it doesn’t answer the order MU_plugins are run (alphabetical, order of importance?)

So my currently solution was to add

include('/my-functions.php');

to any MU-Plugin file that uses ‘../mu-plugin/my-functions.php’.
It works.

Leave a Comment