Cancelled
Pull Request — dev/2.4.0 (#270)
by
unknown
05:29 queued 02:44
created

Upseller::load()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
nc 1
nop 0
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 2
rs 10
c 1
b 0
f 0
1
<?php namespace EmailLog\Addon;
2
3
use EmailLog\Core\Loadie;
4
5
defined( 'ABSPATH' ) || exit; // Exit if accessed directly.
6
7
/**
8
 * Upsells add-ons by displaying links to add-ons with context in different parts of admin interface.
9
 *
10
 * @since 2.4.0
11
 */
12
class Upseller implements Loadie {
13
14
	// phpcs:ignore Squiz.Commenting.FunctionComment.Missing
15
	public function load() {
16
		add_action( 'admin_init', [ 'PAnD', 'init' ] );
17
18
		add_action( 'el_before_logs_list_table', [ $this, 'upsell_auto_delete_logs_in_log_list_page' ] );
19
		add_action( 'el_after_db_size_notification_setting', [ $this, 'upsell_auto_delete_logs_in_settings_page' ] );
20
	}
21
22
	/**
23
	 * Renders Upsell message for Auto delete logs add-on in Log list page
24
	 * if the number of logs is greater than 5000.
25
	 *
26
	 * @param int $total_logs Total number of logs.
27
	 *
28
	 */
29
	public function upsell_auto_delete_logs_in_log_list_page( $total_logs ) {
30
		if ( $total_logs < 5000 ) {
31
			return;
32
		}
33
34
		if ( $this->is_addon_active( 'Auto Delete Logs' ) ) {
35
			return;
36
		}
37
38
		if ( ! class_exists( 'PAnD' ) || ! \PAnD::is_admin_notice_active( 'disable-DL-upsell-notice-5000' ) ) {
39
			return;
40
		}
41
		?>
42
43
		<div data-dismissible="disable-DL-upsell-notice-5000" class="notice notice-warning is-dismissible">
44
			<p>
45
				<?php
46
				/* translators: 1 Auto Delete Logs add-on name.  */
47
				printf(
48
					__( 'You have more than 5000 email logs in the database. You can use our %1s add-on to automatically delete logs as the DB size grows.', 'email-log' ),
49
					'<a href="https://wpemaillog.com/addons/auto-delete-logs/?utm_campaign=Upsell&utm_medium=wpadmin&utm_source=log-list&utm_content=dl">Auto Delete Logs</a>'
50
				);
51
				?>
52
			</p>
53
		</div>
54
55
		<?php
56
	}
57
58
	/**
59
	 * Renders Upsell message for Auto delete logs add-on in Settings page.
60
	 */
61
	public function upsell_auto_delete_logs_in_settings_page() {
62
		if ( $this->is_addon_active( 'Auto Delete Logs' ) ) {
63
			return;
64
		}
65
66
		?>
67
		<p>
68
			<em>
69
				<?php
70
				printf(
71
					__( 'You can also automatically delete logs if the database size increases using our <a href="https://wpemaillog.com/addons/auto-delete-logs/?utm_campaign=Upsell&utm_medium=wpadmin&utm_source=settings&utm_content=dl" target="_blank">Auto Delete Logs</a> add-on.', 'email-log' )
72
				);
73
				?>
74
			</em>
75
		</p>
76
		<?php
77
	}
78
79
	/**
80
	 * Is an add-on active?
81
	 *
82
	 * @param string $addon_name Add-on name.
83
	 *
84
	 * @return bool True if add-on is present and is installed, false otherwise.
85
	 */
86
	protected function is_addon_active( $addon_name ) {
87
		$licenser = email_log()->get_licenser();
88
89
		if ( $licenser->is_bundle_license_valid() ) {
90
			return true;
91
		}
92
93
		return $licenser->is_addon_active( $addon_name );
94
	}
95
}
96