I need to get the current plugin directory like:
[wordpress_install_dir]/wp-content/plugins/plugin_name
(If getcwd()
is called from the plugin, it returns [wordpress_install_dir]
, the root of installation.)
I would suggest to use a WordPress internal constant to solve this case: $my_plugin = WP_PLUGIN_DIR . '/my-plugin'; if ( is_dir( $my_plugin ) ) { // plugin directory found! }
Your browser's C: drive plugins directory folder should be under your username and associated with the browser. For example, the Chrome plugins directory folder could be located at “C:\Users\UserName\AppData\Local\Google\Chrome\Application\Plugins” (without quotation marks).
Use the WordPress core function that's designed specifically for that purpose:
<?php plugin_dir_path( __FILE__ ); ?>
See the Codex documentation here.
You also have
<?php plugin_dir_url( __FILE__ ); ?>
if what you're looking for is a URI as opposed to a server path.
See the Codex documentation here.
IMO, it's always best to use the highest-level method that's available in core, and this is it. It makes your code more future-proof.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With