Passed
Pull Request — dev/2.4.0 (#270)
by Sudar
23:58 queued 20:47
created

upsell_auto_delete_logs_in_settings_page()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 13
c 2
b 0
f 0
nc 2
nop 0
dl 0
loc 15
ccs 0
cts 11
cp 0
crap 6
rs 9.8333
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_more_fields_addon_in_log_list_page' ] );
19
20
		add_action( 'el_before_logs_list_table', [ $this, 'upsell_auto_delete_logs_in_log_list_page' ] );
21
		add_action( 'el_after_db_size_notification_setting', [ $this, 'upsell_auto_delete_logs_in_settings_page' ] );
22
	}
23
24
	/**
25
	 * Renders Upsell message for More Fields add-on in the log list page.
26
	 *
27
	 * @since 2.2.5
28
	 */
29
	public function upsell_more_fields_addon_in_log_list_page() {
30
		echo '<span id = "el-pro-msg">';
31
		_e( 'Additional fields are available through More Fields add-on. ', 'email-log' );
32
33
		if ( $this->is_bundle_license_valid() ) {
34
			echo '<a href="admin.php?page=email-log-addons">';
35
			_e( 'Install it', 'email-log' );
36
			echo '</a>';
37
		} else {
38
			echo '<a rel="noopener" target="_blank" href="https://wpemaillog.com/addons/more-fields/?utm_campaign=Upsell&utm_medium=wpadmin&utm_source=inline&utm_content=mf" style="color:red">';
39
			_e( 'Buy Now', 'email-log' );
40
			echo '</a>';
41
		}
42
43
		echo '</span>';
44
	}
45
46
	/**
47
	 * Renders Upsell message for Auto delete logs add-on in Log list page
48
	 * if the number of logs is greater than 5000.
49
	 *
50
	 * @param int $total_logs Total number of logs.
51
	 *
52
	 */
53
	public function upsell_auto_delete_logs_in_log_list_page( $total_logs ) {
54
		if ( $total_logs < 5000 ) {
55
			return;
56
		}
57
58
		if ( $this->is_addon_active( 'Auto Delete Logs' ) ) {
59
			return;
60
		}
61
62
		if ( ! class_exists( 'PAnD' ) || ! \PAnD::is_admin_notice_active( 'disable-DL-upsell-notice-5000' ) ) {
63
			return;
64
		}
65
		?>
66
67
		<div data-dismissible="disable-DL-upsell-notice-5000" class="notice notice-warning is-dismissible">
68
			<p>
69
				<?php
70
				/* translators: 1 Auto Delete Logs add-on name.  */
71
				printf(
72
					__( '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' ),
73
					'<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>'
74
				);
75
				?>
76
			</p>
77
		</div>
78
79
		<?php
80
	}
81
82
	/**
83
	 * Renders Upsell message for Auto delete logs add-on in Settings page.
84
	 */
85
	public function upsell_auto_delete_logs_in_settings_page() {
86
		if ( $this->is_addon_active( 'Auto Delete Logs' ) ) {
87
			return;
88
		}
89
90
		?>
91
		<p>
92
			<em>
93
				<?php
94
				printf(
95
					__( 'You can also automatically delete logs if the database size increases using our %1s add-on.', 'email-log' ),
96
					'<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>'
97
				);
98
				?>
99
			</em>
100
		</p>
101
		<?php
102
	}
103
104
	/**
105
	 * Is an add-on active?
106
	 *
107
	 * @param string $addon_name Add-on name.
108
	 *
109
	 * @return bool True if add-on is present and is installed, false otherwise.
110
	 */
111
	protected function is_addon_active( $addon_name ) {
112
		$licenser = email_log()->get_licenser();
113
114
		if ( $licenser->is_bundle_license_valid() ) {
115
			return true;
116
		}
117
118
		return $licenser->is_addon_active( $addon_name );
119
	}
120
121
	/**
122
	 * Has valid bundle license?
123
	 *
124
	 * @return bool True if bundle license is valid, false otherwise.
125
	 */
126
	protected function is_bundle_license_valid() {
127
		$licenser = email_log()->get_licenser();
128
129
		if ( $licenser->is_bundle_license_valid() ) {
130
			return true;
131
		}
132
133
		return false;
134
	}
135
}
136