Last active
September 29, 2019 01:52
-
-
Save thartl/8e740d285bf8da5f415eaa73709e7b9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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