There’re the functions get_theme_data();
& get_plugin_data();
– which both use get_file_data();
that needs a specific file as $input
.
I got a set of classes that may be used by a plugin or a theme, without a specific location. Everything works, but I don’t know how i would determine what the main plugin or theme file is – I mean the one containing the comment header that holds the information (Version, Author, etc.) about the Theme/Plugin.
You can get theme’s main file using following:
To get the plugin’s main file you need to know the plugin name. And then you can use following function:
For example to get the plugin main file for Akismet.
How do get the comment header data of a theme OR plugin…
… that holds a specific class.
The following shows how you can drop a class inside any plugin or theme and still be able to get any theme or plugin data from the comment header. This is useful for updating settings/db-options for example.
You don’t know:
Notes:
Usage Example:
In a recent project I did, I used the following to get the main plugin file & data of my plugin from another file within my plugin, without having to hardcode anything:
This will return the following:
You can use this in whichever file within your plugin and it should work just fine and you shouldn’t need to worry about any of the files being renamed, paths changed, etc.
To get the “path to main plugin file with plugin data” used by various functions such as
is_plugin_active()
andis_plugin_active_for_network()
, from a file that is not the the main plugin file, use the following code: