include, or require, or require_once the file that contains the class and instantiate the class. So, your class myClass is in myclass.php in, say, your theme’s php folder…
include(get_bloginfo('template_directory').'/php/myclass.php');
$myclass = new myClass();
$myclass->do_stuff();
Thread Starter
shadd
(@shadd)
Thanks. I want to use that class in my plugin and my template. In such a case, what is the best place to put the file ? In the root wp dir ? In the plugins or template dir ? Or just have two copies (once in plugin folder and one in template folder) ?
It doesn’t matter that much where you put the file if you aren’t going to distribute the theme or the plugin so its kind-of a toss up really. If you do want to distribute the theme and the plugin independently you’ll need to put the file in, I guess, both directories and use include_once or require_once.
What does your plugin do? I ask because if it does something theme specific you might be able to write it into the theme and avoid this problem altogether.