0

I want to add some logging to my plugin, and for various reason want to create my own wrapper function around error_log(). And for reusability, I'd like to stick my wrapper function in a separate utility plugin.

Assuming that I have the utility plugin, and the my_error_log() function is there, how can I call it from anywhere in my other plugins? How can I be sure I can call it? Are plugins functions available across my WordPress code? Should I somehow ensure that my utility plugin is loaded first?

As I understand them, I don't think I can use a hook or action, as I want to call the error logging function from inside the code of my other plugins, for debugging purposes, as that code executes.

PS: Yes, I do realize this is rather a n00b question :-)

1 Answer 1

0

Assuming that I have the utility plugin, and the my_error_log() function is there, how can I call it from anywhere in my other plugins?

By calling it, there are no special steps

How can I be sure I can call it? Are plugins functions available across my WordPress code?

Yes, plugins are not sandboxed, everything is loaded into the same melting pot. WordPress is aware a plugin exists but it doesn't track/tag/sandbox code inside plugins. It's just a mechanism for loading arbitrary PHP.

Should I somehow ensure that my utility plugin is loaded first?

Yes, you should test if the functions/classes exist. How you would do that though is generic PHP that has nothing to do with WordPress though, e.g. if ( function_exists(... etc

1
  • Thanks Tom, that's very helpful!
    – florismk
    Dec 7, 2023 at 20:13

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.