WordPress get plugin directory

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

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)