If you want to get current directory path within a file for that you can magic constants __FILE__
and __DIR__
with plugin_dir_path()
function as:
$dir_path = plugin_dir_path( __FILE__ );
CurrentDirectory Path:
/home/user/var/www/wordpress_site/wp-content/plugins/custom-plugin/
__FILE__
magic constant returns current directory path.
If you want to one level up from the current directory. You should use __DIR__
magic constant as:
Current Path:
/home/user/var/www/wordpress_site/wp-content/plugins/custom-plugin/
$dir = plugin_dir_path( __DIR__ );
One level up path:
/home/user/var/www/wordpress_site/wp-content/plugins/
__DIR__
magic constant returns one level up directory path.