Passed
Push — 106-feature/store-attachment-n... ( 67d8e5...acae6a )
by Maria Daniel Deepak
07:00 queued 03:41
created

load_email_log_addon()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 3
Bugs 0 Features 2
Metric Value
cc 2
eloc 9
nc 2
nop 2
dl 0
loc 17
ccs 0
cts 10
cp 0
crap 6
rs 9.9666
c 3
b 0
f 2
1
<?php
2
/**
3
 * Add-on helper functions.
4
 * These functions are not using namespace since they may be used from a PHP 5.2 file.
5
 *
6
 * @since 2.0
7
 */
8
defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
9
10
/**
11
 * Load an Email Log add-on.
12
 *
13
 * @since 2.0.0
14
 *
15
 * @param string $addon_class Add-on class name.
16
 * @param string $addon_file  Add-on File.
17
 *
18
 * @return \EmailLog\Addon\EmailLogAddon Instance of the add-on.
19
 */
20
function load_email_log_addon( $addon_class, $addon_file ) {
21
	$email_log = email_log();
22
23
	$addon_dir = plugin_dir_path( $addon_file );
24
	$email_log->loader->add_namespace( 'EmailLog', $addon_dir . 'include' );
25
26
	$addon_updater = null;
27
28
	if ( \EmailLog\Util\is_admin_non_ajax_request() ) {
29
		$addon_updater = new \EmailLog\Addon\AddonUpdater( $addon_file );
30
	}
31
32
	$addon = new $addon_class( $addon_file, $addon_updater );
33
34
	add_action( 'el_loaded', array( $addon, 'load' ) );
35
36
	return $addon;
37
}
38