I need access to my Theme’s version number a number of times on each Admin Page view.
Right now I’m using get_theme_data
which in turn parses the Theme’s style.css
file via get_file_data
, so style.css
gets parsed multiple times.
Is there a built-in caching mechanism for this data? Or should I just build a thin in-process caching wrapper around get_theme_data
?
Thanks!
In the mean time, keep using your method. But as @helenhousandi linked in a comment, WordPress 3.4 will be introducing a new
WP_Theme
object that will make this much easier.Right now, you’re using
get_theme_data()
to return an array with the theme’s version. No, it’s not cached … but you could likely cache it yourself in a transient if you’re accessing it a lot.But in WP 3.4,
get_theme_data()
will be deprecated and will instead serve as a wrapper for the newWP_Theme
API (meaning the above code will still work, but will trigger a deprecation notice).So instead, you could use this:
The new object has some level of caching built in. I encourage you to read the discussion surrounding the new changes and to follow the Codex for when it’s officially documented as well.