Skip to content

Instantly share code, notes, and snippets.

@rmccue
Created October 21, 2014 17:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rmccue/c3b68eb27eea38f92c1b to your computer and use it in GitHub Desktop.
Save rmccue/c3b68eb27eea38f92c1b to your computer and use it in GitHub Desktop.
<?php
function get_plugin_from_trace( $trace ) {
$file = null;
while ( $elem = array_shift( $trace ) ) {
if ( empty( $elem['file'] ) ) {
// We catch this later
continue;
}
// Is this from a Courier file?
if ( strpos( $elem['file'], COURIER_BASE ) === 0 ) {
continue;
}
$file = $elem['file'];
break;
}
if ( empty( $file ) ) {
throw new Exception( 'Plugin file could not be detected via trace' );
}
$available_plugins = get_plugins();
$plugins_dir = trailingslashit( WP_PLUGIN_DIR );
if ( strpos( $file, $plugins_dir ) === 0 ) {
$file = substr( $file, strlen( $plugins_dir ) );
}
if ( empty( $available_plugins[ $file ] ) ) {
throw new Exception( 'Invalid plugin file found via trace' );
}
if ( strpos( $file, '/' ) === false ) {
throw new Exception( 'Only plugins in directories can require files' );
}
// Hackity hackity hack
add_action( 'activate_' . $file, 'Courier\\Internal\\check_resolution', COURIER_RESOLUTION_PRIORITY );
$id = basename( dirname( $file ) );
return array( $id, $available_plugins[ $file ] );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment