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 | |
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