| 1 |
<?php |
| 2 |
/** |
| 3 |
* Load Email Log plugin. |
| 4 |
* |
| 5 |
* We need this load code in a separate file since it requires namespace |
| 6 |
* and using namespace in PHP 5.2 will generate a fatal error. |
| 7 |
* |
| 8 |
* @since 2.0 |
| 9 |
*/ |
| 10 |
defined( 'ABSPATH' ) || exit; // Exit if accessed directly. |
| 11 |
|
| 12 |
/** |
| 13 |
* Load Email Log plugin. |
| 14 |
* |
| 15 |
* @since 2.0 |
| 16 |
* |
| 17 |
* @param string $plugin_file Main plugin file. |
| 18 |
*/ |
| 19 |
function load_email_log( $plugin_file ) { |
| 20 |
global $email_log; |
| 21 |
|
| 22 |
$plugin_dir = plugin_dir_path( $plugin_file ); |
| 23 |
|
| 24 |
// setup autoloader. |
| 25 |
require_once 'include/EmailLogAutoloader.php'; |
| 26 |
|
| 27 |
$loader = new \EmailLog\EmailLogAutoloader(); |
| 28 |
$loader->add_namespace( 'EmailLog', $plugin_dir . 'include' ); |
| 29 |
$loader->add_namespace( 'Sudar\\WPSystemInfo', $plugin_dir . 'vendor/sudar/wp-system-info/src/' ); |
| 30 |
|
| 31 |
if ( file_exists( $plugin_dir . 'tests/' ) ) { |
| 32 |
// if tests are present, then add them. |
| 33 |
$loader->add_namespace( 'EmailLog', $plugin_dir . 'tests/wp-tests' ); |
| 34 |
} |
| 35 |
|
| 36 |
$loader->add_file( $plugin_dir . 'include/Util/helper.php' ); |
| 37 |
$loader->add_file( $plugin_dir . 'include/Addon/addon-helper.php' ); |
| 38 |
|
| 39 |
$loader->register(); |
| 40 |
|
| 41 |
$email_log = new \EmailLog\Core\EmailLog( $plugin_file, $loader, new \EmailLog\Core\DB\TableManager() ); |
| 42 |
|
| 43 |
$email_log->add_loadie( new \EmailLog\Core\EmailLogger() ); |
| 44 |
|
| 45 |
$email_log->add_loadie( new \EmailLog\Core\UI\UILoader(), true ); |
| 46 |
|
| 47 |
$email_log->add_loadie( new \EmailLog\Core\Request\NonceChecker() ); |
| 48 |
$email_log->add_loadie( new \EmailLog\Core\Request\LogListAction() ); |
| 49 |
|
| 50 |
$capability_giver = new \EmailLog\Core\AdminCapabilityGiver(); |
| 51 |
$email_log->add_loadie( $capability_giver ); |
| 52 |
|
| 53 |
// `register_activation_hook` can't be called from inside any hook. |
| 54 |
register_activation_hook( $plugin_file, array( $email_log->table_manager, 'on_activate' ) ); |
| 55 |
register_activation_hook( $plugin_file, array( $capability_giver, 'add_cap_to_admin' ) ); |
| 56 |
|
| 57 |
// Ideally the plugin should be loaded in a later event like `init` or `wp_loaded`. |
| 58 |
// But some plugins like EDD are sending emails in `init` event itself, |
| 59 |
// which won't be logged if the plugin is loaded in `wp_loaded` or `init`. |
| 60 |
add_action( 'plugins_loaded', array( $email_log, 'load' ), 101 ); |
| 61 |
} |
| 62 |
|
| 63 |
/** |
| 64 |
* Return the global instance of Email Log plugin. |
| 65 |
* Eventually the EmailLog class might become singleton. |
| 66 |
* |
| 67 |
* @since 2.0 |
| 68 |
* |
| 69 |
* @global \EmailLog\Core\EmailLog $email_log |
| 70 |
* |
| 71 |
* @return \EmailLog\Core\EmailLog |
| 72 |
*/ |
| 73 |
function email_log() { |
| 74 |
global $email_log; |
| 75 |
|
| 76 |
return $email_log; |
| 77 |
} |
| 78 |
|