I am making my own mini OOP wrapper for working with wordpress themes. I have a main $settings variable that contains all of the information like definitions, scripts, menus etc..

I then pass this variable or its members to helper functions that interact with the API. This all worked fine for my setup helper that did things like register scripts and menus but now I am working on presentation functions that I will call from inside the template (header, footer etc..) and want my helper functions to access the $settings variable but it is out of scope and I am not sure what the best way to bring it into scope is.

I am not developing anything for general release and am targeting PHP 5.4. I have put all my functional code inside of namespaces so there isn't any naming clashes with plugins.

I've only been doing PHP for a couple of weeks so I am not sure what approach to take. Should I add the variable to the global array? Can inject variables some other way into page lifecycle to make them accessible? Should I serialize the variable to a flat file and then read it back?

I am sure there is simple way but it eludes me due to inexperience. Thanks for any advice.

  • Have you seen Best way of passing PHP variable between partials? – fuxia Apr 22 '15 at 16:53
  • I saw some wordpress MVC frameworks but didn't use them as I was worried I might over complicate things while I am still new to wordpress. I don't think its a good idea for me to try and build my own routing system just yet as I haven't really looked into the wordpress lifecycle properly yet. Is there a particular WP MVC framework that you recommend? – Guerrilla Apr 22 '15 at 17:25
  • Nope, everything I have seen is crap. – fuxia Apr 22 '15 at 21:59

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.