Completed
Push — master ( 79d5e2...0841bd )
by Sudar
06:47
created

load-email-log.php ➔ load_email_log()   B

Complexity

Conditions 2
Paths 2

Size

Total Lines 31
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 16
nc 2
nop 1
dl 0
loc 31
rs 8.8571
c 0
b 0
f 0
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
11
/**
12
 * Load Email Log plugin.
13
 *
14
 * @since 2.0
15
 *
16
 * @param $plugin_file
17
 */
18
function load_email_log( $plugin_file ) {
19
	global $email_log;
20
21
	$plugin_dir = plugin_dir_path( $plugin_file );
22
23
	// setup autoloader.
24
	require_once 'include/EmailLogAutoloader.php';
25
26
	$loader = new \EmailLog\EmailLogAutoloader();
27
	$loader->add_namespace( 'EmailLog', $plugin_dir . 'include' );
28
29
	if ( file_exists( $plugin_dir . 'tests/' ) ) {
30
		// if tests are present, then add them.
31
		$loader->add_namespace( 'EmailLog', $plugin_dir . 'tests/wp-tests' );
32
	}
33
34
	$loader->add_file( $plugin_dir . 'include/Util/helper.php' );
35
36
	$loader->register();
37
38
	$email_log                = new \EmailLog\Core\EmailLog( $plugin_file );
39
	$email_log->table_manager = new \EmailLog\Core\DB\TableManager();
40
	$email_log->logger        = new \EmailLog\Core\EmailLogger();
41
	$email_log->ui_manager    = new \EmailLog\Core\UI\UIManager( $plugin_file );
42
43
	// `register_activation_hook` can't be called from inside any hook.
44
	register_activation_hook( $plugin_file, array( $email_log->table_manager, 'on_activate' ) );
45
46
	// Load the plugin
47
	add_action( 'wp_loaded', array( $email_log, 'load' ) );
48
}
49
50
/**
51
 * Return the global instance of Email Log plugin.
52
 * Eventually the EmailLog class might become singleton.
53
 *
54
 * @since 2.0
55
 *
56
 * @global \EmailLog\Core\EmailLog $email_log
57
 * @return \EmailLog\Core\EmailLog
58
 */
59
function email_log() {
60
	global $email_log;
61
62
	return $email_log;
63
}
64