I wrote a simple function to get the contents in a folder (called templates) in my wordpress plugin, but am having problems getting the path to work (thus the function always dies). My question is: Is there a wordpress function or something that will give me the path to my plugin as required for the opendir function to work?
function get_templates(){
$path = '[path to my plugin]/templates';
$dir_handle = @opendir($path) or die("Cannot open the damn file $path");
while ($file = readdir($dir_handle)) {
if(substr($file,-3) == "php" )
continue;
$TheLinkedFile = $path."/".$file;
if(file_exists($TheLinkedFile)) {
echo $TheLinkedFile.'<br>';
} else {
echo "nothing";
}
}
closedir($dir_handle);
}