Completed
Push — master ( 186893...053e09 )
by Sudar
02:09
created

OverridePluginAPI::inject_addon_install_resource()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 20
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 13
nc 3
nop 3
dl 0
loc 20
rs 9.2
c 1
b 0
f 0
1
<?php namespace EmailLog\Core\Request;
2
3
use EmailLog\Addon\AddonList;
4
use EmailLog\Addon\API\EDDUpdater;
5
use EmailLog\Core\Loadie;
6
7
defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
8
9
/**
10
 * Override WordPress Plugin API.
11
 * This is already done by EDD_SL_Plugin_Updater for Active add-on
12
 * and this class does it for all in active or yet to be installed add-ons.
13
 *
14
 * @since 2.0.0
15
 */
16
class OverridePluginAPI implements Loadie {
17
18
	/**
19
	 * Setup actions.
20
	 *
21
	 * @inheritdoc
22
	 */
23
	public function load() {
24
		add_action( 'admin_init', array( $this, 'setup_updaters_for_inactive_addons' ) );
25
	}
26
27
	/**
28
	 * Setup updaters for all in-active addons.
29
	 */
30
	public function setup_updaters_for_inactive_addons() {
31
		$email_log = email_log();
32
		$inactive_addons = $email_log->get_licenser()->get_addon_list()->get_inactive_addons();
33
34
		foreach ( $inactive_addons as $inactive_addon ) {
35
			$license_key = $email_log->get_licenser()->get_addon_license_key( $inactive_addon->name );
36
37
			$updater = new EDDUpdater( $email_log->get_store_url(), $inactive_addon->file, array(
38
					'version'   => $inactive_addon->get_version(),
39
					'license'   => $license_key,
40
					'item_name' => $inactive_addon->name,
41
					'author'    => $inactive_addon->author,
42
				)
43
			);
44
45
			$email_log->get_licenser()->add_updater( $updater );
46
		}
47
	}
48
}
49