Created
December 7, 2015 22:38
-
-
Save wvega/da3c6f3a4efd63168231 to your computer and use it in GitHub Desktop.
Alternative implementation for _find_caller_plugin_file() (2nd Attempt).
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 | |
private function _find_caller_plugin_file() { | |
$bt = debug_backtrace(); | |
$backtrace_entries_count = count( $bt ); | |
$active_plugins = get_option( 'active_plugins' ); | |
$active_plugins_paths = array(); | |
$plugin_file = null; | |
foreach ( $active_plugins as $i => $relative_path ) { | |
$active_plugins_paths[ $i ] = realpath( WP_PLUGIN_DIR . '/' . $relative_path ); | |
} | |
for ( $i = 1; $i < $backtrace_entries_count; $i++ ) { | |
if ( ! in_array( $bt[ $i ]['file'], $active_plugins_paths ) ) { | |
continue; | |
} | |
$plugin_file = $bt[ $i ]['file']; | |
break; | |
} | |
return $plugin_file; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment