I’d like to scan a plugin’s directory for files with specific extensions, like php, css and js.
I know there is scandir()
function in WP_Theme
class that’s perfect for this work. The problem is that it’s declared private
so I can’t use it outside of the class.
Any advice what’s the best way to do this? Is there another native WP function that can be used instead?
Many thanks,
Dasha
You can use PHP5 RecursiveDirectoryIterator with RecursiveIteratorIterator
As of WP 3.4 there is a public
get_files()
method. You can create aWP_Theme
instance with the plugin dir set as theme root.There isn’t very much documentation on it in the WP-Codex Page, so having a look at the source code might be more instructive.
Thank you everyone for the inputs and advice.
I’ve decided to copy over the
WP_Theme::scandir()
function itself. I understand what’s going on there and there is no other native WP function to scan directories for files with specific extensions (with an option scanning sub-folders).P.S. I could not figure out how to link to WP code. Here is the copy of the
WP_Theme::scandir()
as of 13 Jan 2014