Skip to content

Instantly share code, notes, and snippets.

@thartl
Last active September 29, 2019 01:52
Show Gist options
  • Save thartl/8e740d285bf8da5f415eaa73709e7b9e to your computer and use it in GitHub Desktop.
Save thartl/8e740d285bf8da5f415eaa73709e7b9e to your computer and use it in GitHub Desktop.
<?php
if ( ! function_exists( 'plugin_basename_main_file' ) ) {
/**
* Gets plugin folder and main file.
* Example result: Core-Functionality/core-functionality.php
*
* `plugin_basename()` returns main plugin file only when called from that file.
* This function works from within any plugin file.
*
* @return string
*/
function plugin_basename_main_file() {
$current_path = plugin_basename( __FILE__ );
$plugin_folder = substr( $current_path, 0, strpos( $current_path, '/' ) );
$plugin_file = key( get_plugins( '/' . $plugin_folder ) );
return $plugin_folder . '/' . $plugin_file;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment