Is there any function that would return the full path of my plugin in WordPress?
Example is
path/wp-contents/plugins/myplugin
I have tried plugin_dir_path(__FILE__)
but returns the current dir.
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).
A plug-in subfolder can contain a single or a combination of several files (such as configuration files, JSP or ASP.NET files, etc.) that contain software code specific to the customization.
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! }
Alternative
The other valid alternative is to compute the path from the URL which is more complex/confusing. I would not use this code:
$plugins_url = plugins_url(); $base_url = get_option( 'siteurl' ); $plugins_dir = str_replace( $base_url, ABSPATH, $plugins_url ); // Now $plugins_dir is same as the WP_PLUGIN_DIR constant. $my_plugin = $plugins_dir . '/my-plugin';
My opinion in this case is: Use the constant WP_PLUGIN_DIR
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