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