integrating external php library into wordpress- the right way

If I were to load a custom library into wordpress, what would be the best place to add it?

Since there are a bunch of global vars defined at the top of the library, I would not want that to be done thru a hook where I’m forced to use a wrapper function whereby my library globals will be treated as local to that function.

My library starts with

ob_start()         //  I'm not sure how this would effect WP. So I'm not too big on this.
session_start();   //  I do need this though. 

This should make any wordpress page to be able to use PHP sessions, right? ( I’m assuming wordpress no internal code that kills/rejects session usage. )

If I put my library into a page such as mylibrary.php, how do I make sure that it gets included into wordpress ( all pages, cats, template files across themes ) and it will remain included even if I were to switch themes or deploy wordpress updates?

1 Answer
1

You might want to look into creating a MU (Must Use) plugin, see WordPress Codex. Within this file, you can include your library (using require) or you could just tweak your library file a bit and use it directly as the MU plugin. The session_start() and ob_start() functions worked for me with ever-so-brief testing, but your mileage may vary so test test test 🙂

Leave a Comment