Skip to content

Instantly share code, notes, and snippets.

@wvega
Created December 7, 2015 22:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save wvega/da3c6f3a4efd63168231 to your computer and use it in GitHub Desktop.
Save wvega/da3c6f3a4efd63168231 to your computer and use it in GitHub Desktop.
Alternative implementation for _find_caller_plugin_file() (2nd Attempt).
<?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