How to get the current plugin name?

I need to get the current plugin name using a define like this

define(PLUGIN_NAME, plugin_basename(dirname(__FILE__)));

Regrettably, that code doesn’t work because the php file is nested inside a subdirectory (includes) of my plugin directory and it returns

my-plugin/includes 

Is there any function from WordPress API to accomplish this task?
Thanks in advance.

3 Answers
3

Within the plugin’s main PHP file:

$plugin_data = get_plugin_data( __FILE__ );
$plugin_name = $plugin_data['Name'];

Leave a Comment