I can get the dir/url of a plugin’s file by using:
$plugin_dir_path = plugin_dir_path(__FILE__);
$plugin_dir_url = plugin_dir_url(__FILE__);
However, if the file calling the above codes are in a subdir such as ./includes, the the subdir will also be returned, like this:
/xxx/wp-content/plugins/file-converter/includes/
How to get the root dir of the plugin without the subdir? i.e. /xxx/wp-content/plugins/file-converter/
2
Answers
in my plugin, a create these hooks in the main file :
and then I can use them in all my files with this code :
There are many ways to handle that.
I noticed that WordPress plugins use constants to set those in the main plugin file, like:
Then you can use directly
FILE_CONVERTER_DIR_PATH
orFILE_CONVERTER_DIR_URL
constants from any included plugin PHP file, to retrieve the right directory path or directory URL.