I am making a simple PHP library for my own personal toolbox which involves caching variables on the server.
If the library is being run on a WP site it will use the Transient API instead of the APC extension to cache the data.
As it stands, my litmus test to see if it’s a WP environment is to check if get_the_permalink() function exists and to see if the constant WP_CONTENT_DIR has been defined.
I feel this is a bit hacky and would like to know if there is a better way to go about this.
If you’re only really after using the Transients API, why not take look to see if that is available?
if (function_exists('set_transient')) {
$function = new ReflectionFunction('set_transient');
$phpdoc = $function->getDocComment();
if (strpos($phpdoc, '@package WordPress') && strpos($phpdoc, '@subpackage Transient')) {
// Do something to record that Transients API is available
echo $phpdoc;
}
}