|
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
|
|
|
|
|
30
|
|
|
if ( file_exists( $plugin_dir . 'tests/' ) ) { |
|
31
|
|
|
// if tests are present, then add them. |
|
32
|
|
|
$loader->add_namespace( 'EmailLog', $plugin_dir . 'tests/wp-tests' ); |
|
33
|
|
|
} |
|
34
|
|
|
|
|
35
|
|
|
$loader->add_file( $plugin_dir . 'include/Util/helper.php' ); |
|
36
|
|
|
$loader->add_file( $plugin_dir . 'include/Addon/addon-helper.php' ); |
|
37
|
|
|
|
|
38
|
|
|
$loader->register(); |
|
39
|
|
|
|
|
40
|
|
|
$email_log = new \EmailLog\Core\EmailLog( $plugin_file, $loader, new \EmailLog\Core\DB\TableManager() ); |
|
41
|
|
|
|
|
42
|
|
|
if ( \EmailLog\Util\is_admin_non_ajax_request() ) { |
|
43
|
|
|
// Loading licenser in frontend or ajax request is resulting in huge performance issues. |
|
44
|
|
|
$email_log->set_licenser( new \EmailLog\Addon\License\Licenser() ); |
|
45
|
|
|
|
|
46
|
|
|
$email_log->add_loadie( new \EmailLog\Addon\DependencyEnforcer() ); |
|
47
|
|
|
$email_log->add_loadie( new \EmailLog\Core\Request\OverridePluginAPI() ); |
|
48
|
|
|
} |
|
49
|
|
|
|
|
50
|
|
|
$email_log->add_loadie( new \EmailLog\Core\EmailLogger() ); |
|
51
|
|
|
$email_log->add_loadie( new \EmailLog\Core\UI\UILoader() ); |
|
52
|
|
|
|
|
53
|
|
|
$email_log->add_loadie( new \EmailLog\Core\Request\NonceChecker() ); |
|
54
|
|
|
$email_log->add_loadie( new \EmailLog\Core\Request\LogListAction() ); |
|
55
|
|
|
|
|
56
|
|
|
$capability_giver = new \EmailLog\Core\AdminCapabilityGiver(); |
|
57
|
|
|
$email_log->add_loadie( $capability_giver ); |
|
58
|
|
|
|
|
59
|
|
|
// `register_activation_hook` can't be called from inside any hook. |
|
60
|
|
|
register_activation_hook( $plugin_file, array( $email_log->table_manager, 'on_activate' ) ); |
|
61
|
|
|
register_activation_hook( $plugin_file, array( $capability_giver, 'add_cap_to_admin' ) ); |
|
62
|
|
|
|
|
63
|
|
|
// Ideally the plugin should be loaded in a later event like `init` or `wp_loaded`. |
|
64
|
|
|
// But some plugins like EDD are sending emails in `init` event itself, |
|
65
|
|
|
// which won't be logged if the plugin is loaded in `wp_loaded` or `init`. |
|
66
|
|
|
add_action( 'plugins_loaded', array( $email_log, 'load' ), 101 ); |
|
67
|
|
|
} |
|
68
|
|
|
|
|
69
|
|
|
/** |
|
70
|
|
|
* Return the global instance of Email Log plugin. |
|
71
|
|
|
* Eventually the EmailLog class might become singleton. |
|
72
|
|
|
* |
|
73
|
|
|
* @since 2.0 |
|
74
|
|
|
* |
|
75
|
|
|
* @global \EmailLog\Core\EmailLog $email_log |
|
76
|
|
|
* |
|
77
|
|
|
* @return \EmailLog\Core\EmailLog |
|
78
|
|
|
*/ |
|
79
|
|
|
function email_log() { |
|
80
|
|
|
global $email_log; |
|
81
|
|
|
|
|
82
|
|
|
return $email_log; |
|
83
|
|
|
} |
|
84
|
|
|
|