Notifications_Service.php
12.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
<?php
namespace Wpo\Services;
use \Wpo\Core\Plugin_Helpers;
use \Wpo\Core\Url_Helpers;
use \Wpo\Core\WordPress_Helpers;
use \Wpo\Core\Wpmu_Helpers;
use \Wpo\Services\Log_Service;
use \Wpo\Services\Options_Service;
// Prevent public access to this script
defined('ABSPATH') or die();
if (!class_exists('\Wpo\Services\Notifications_Service')) {
class Notifications_Service
{
/**
* Shows admin notices when the plugin is not configured correctly
*
* @since 2.3
*
* @return void
*/
public static function show_admin_notices()
{
if (!is_admin() && !is_network_admin()) {
return;
}
if (is_super_admin() && (!is_multisite() || Options_Service::mu_use_subsite_options() || (!Options_Service::mu_use_subsite_options() && is_network_admin()))) {
if (false === Options_Service::get_global_boolean_var('hide_error_notice')) {
$cached_errors = Wpmu_Helpers::mu_get_transient('wpo365_errors');
if (is_array($cached_errors)) {
$title = __('WPO365 health status', 'wpo365-login');
$dismiss_button = sprintf(
'</p><p><a class="button button-primary" href="#" onclick="javascript:window.location.href = window.location.href.replace(\'page=wpo365-wizard\', \'page=wpo365-wizard&wpo365_errors_dismissed=true\')">%s</a>',
__('Dismiss', 'wpo365-login')
);
$footer = '- Marco van Wieren | Downloads by van Wieren | <a href="https://www.wpo365.com/">https://www.wpo365.com/</a>';
$notice_type = 'error';
$hide_image = true;
if (isset($_GET['page']) && WordPress_Helpers::trim($_GET['page']) == 'wpo365-wizard') {
$wpo365_errors = '';
array_map(function ($log_item) use (&$wpo365_errors) {
$wpo365_errors .= '<li><strong>[' . date('Y-m-d H:i:s', esc_html($log_item['time'])) . ']</strong> ' . wp_kses($log_item['body'], WordPress_Helpers::get_allowed_html()) . '</li>';
}, $cached_errors);
$message = sprintf(
__('The %s plugin detected the following three errors that you should address:%s%s%s%s%s', 'wpo365-login'),
'<strong>WPO365 | LOGIN</strong>',
'<p></p><ul style="list-style: initial; padding-left: 20px;">' . wp_kses($wpo365_errors, WordPress_Helpers::get_allowed_html()) . '</ul><p>',
__('Please take the time to review those errors. Once errors have been addressed you can safely dismiss this notice for now or hide this notification on the plugin\'s Debug configuration page to hide this notice permanently.', 'wpo365-login'),
$dismiss_button,
'</p><p>',
sprintf(
__('Please check the %s for help or alternatively %s whenever you are unable to resolve the error reported.', 'wpo365-login'),
sprintf(
'<a href="https://docs.wpo365.com/" target="_blank">%s</a>',
__('online documentation', 'wpo365-login')
),
sprintf(
'<a href="https://www.wpo365.com/contact/" target="_blank">%s</a>',
__('contact WPO365 support', 'wpo365-login')
)
)
);
} else {
$message = sprintf(
__('The %s plugin detected errors that you should address. Please %s to review and address these errors.', 'wpo365-login'),
'<strong>WPO365 | LOGIN</strong>',
sprintf(
'<a href="admin.php?page=wpo365-wizard">%s</a>',
__('click here', 'wpo365-login')
)
);
}
ob_start();
include($GLOBALS['WPO_CONFIG']['plugin_dir'] . '/templates/admin-notifications.php');
$content = ob_get_clean();
echo '' . wp_kses($content, WordPress_Helpers::get_allowed_html());
}
}
if ($GLOBALS['WPO_CONFIG']['plugin'] == 'wpo365-login/wpo365-login.php') {
if (isset($_GET['page']) && WordPress_Helpers::trim($_GET['page']) == 'wpo365-wizard' && false === Options_Service::get_global_boolean_var('no_sso') && false === Options_Service::is_wpo365_configured()) {
$title = __('Getting started', 'wpo365-login');
$message = sprintf(
__('Check out our %s documentation to start integrating your WordPress website with %s. For example:%s', 'wpo365-login'),
sprintf(
'<a href="https://docs.wpo365.com/article/154-aad-single-sign-for-wordpress-using-auth-code-flow" target="_blank">%s</a>',
__('Getting started'),
'wpo365-login'
),
'<strong>Microsoft 365 / Azure AD</strong>',
sprintf(
'<ul style="list-style: initial; padding-left: 20px;"><li><a href="https://docs.wpo365.com/article/154-aad-single-sign-for-wordpress-using-auth-code-flow" target="_blank">%s</a></li><li><a href="https://docs.wpo365.com/article/100-single-sign-on-with-saml-2-0-for-wordpress" target="_blank">%s</a></li><li><a href="https://docs.wpo365.com/article/108-sending-wordpress-emails-using-microsoft-graph" target="_blank">%s</a></li></ul>',
__('OpenID based Single Sign-on', 'wpo365-login'),
__('SAML 2.0 based Single Sign-on', 'wpo365-login'),
__('Sending WordPress mail using Microsoft Graph', 'wpo365-login')
)
);
$footer = '- Marco van Wieren | Downloads by van Wieren | <a href="https://www.wpo365.com/">https://www.wpo365.com/</a>';
$notice_type = 'info';
ob_start();
include($GLOBALS['WPO_CONFIG']['plugin_dir'] . '/templates/admin-notifications.php');
$content = ob_get_clean();
echo '' . wp_kses($content, WordPress_Helpers::get_allowed_html());
}
}
// review
if (
$GLOBALS['WPO_CONFIG']['plugin'] == 'wpo365-login/wpo365-login.php'
&& isset($_GET['page'])
&& WordPress_Helpers::trim($_GET['page']) == 'wpo365-wizard'
&& !Options_Service::get_global_boolean_var('review_stop', false)
&& true === Options_Service::is_wpo365_configured()
&& false === Wpmu_Helpers::mu_get_transient('wpo365_review_dismissed')
&& false === Wpmu_Helpers::mu_get_transient('wpo365_user_created')
&& !Plugin_Helpers::is_premium_edition_active()
) {
$title = __('Sharing is caring', 'wpo365-login');
$buttons = sprintf(
'<a class="button button-primary" href="http://wordpress.org/support/view/plugin-reviews/wpo365-login?filter=5#postform" target="_blank">%s</a> <a class="button" href="./?wpo365_review_dismissed">%s</a> <a class="button" href="./?wpo365_review_stop">%s</a></p>',
__('Yes, here we go!', 'wpo365-login'),
__('Remind me later', 'wpo365-login'),
__('No thanks', 'wpo365-login')
);
$message = sprintf(
__('Many thanks for using the %s plugin! Could you please spare a minute and give it a review over at WordPress.org?%s%s', 'wpo365-login'),
'<strong>WPO365 | LOGIN</strong>',
'</p><p>',
$buttons
);
$footer = '- Marco van Wieren | Downloads by van Wieren | <a href="https://www.wpo365.com/">https://www.wpo365.com/</a>';
$notice_type = 'info';
ob_start();
include($GLOBALS['WPO_CONFIG']['plugin_dir'] . '/templates/admin-notifications.php');
$content = ob_get_clean();
echo '' . wp_kses($content, WordPress_Helpers::get_allowed_html());
}
// upgrade
if (
$GLOBALS['WPO_CONFIG']['plugin'] == 'wpo365-login/wpo365-login.php'
&& isset($_GET['page'])
&& WordPress_Helpers::trim($_GET['page']) == 'wpo365-wizard'
&& true === Options_Service::is_wpo365_configured()
&& false !== Wpmu_Helpers::mu_get_transient('wpo365_user_created')
&& false === Wpmu_Helpers::mu_get_transient('wpo365_upgrade_dismissed')
&& !Plugin_Helpers::is_premium_edition_active()
) {
$title = __('Sharing is caring', 'wpo365-login');
$buttons = sprintf(
'<a class="button button-primary" href="http://wordpress.org/support/view/plugin-reviews/wpo365-login?filter=5#postform" target="_blank">%s</a> <a class="button" href="./?wpo365_upgrade_dismissed">%s</a></p>',
__('Yes, here we go!', 'wpo365-login'),
__('Remind me later', 'wpo365-login')
);
$message = sprintf(
__('The %s plugin just created a new WordPress user for you! Could you please spare a minute and give it a review over at WordPress.org?%s%s', 'wpo365-login'),
'<strong>WPO365 | LOGIN</strong>',
'</p><p>',
$buttons
);
$footer = '- Marco van Wieren | Downloads by van Wieren | <a href="https://www.wpo365.com/">https://www.wpo365.com/</a>';
$notice_type = 'info';
ob_start();
include($GLOBALS['WPO_CONFIG']['plugin_dir'] . '/templates/admin-notifications.php');
$content = ob_get_clean();
echo '' . wp_kses($content, WordPress_Helpers::get_allowed_html());
}
}
}
/**
* Helper to configure a transient to surpress admoin notices when the user clicked dismiss.
*
* @since 7.18
*
* @return void
*/
public static function dismiss_admin_notices()
{
if (isset($_GET['wpo365_errors_dismissed'])) {
Wpmu_Helpers::mu_delete_transient('wpo365_errors');
Url_Helpers::force_redirect(remove_query_arg('wpo365_errors_dismissed'));
}
if (isset($_GET['wpo365_review_dismissed'])) {
Wpmu_Helpers::mu_set_transient('wpo365_review_dismissed', date('d'), 1209600);
Url_Helpers::force_redirect(remove_query_arg('wpo365_review_dismissed'));
}
if (isset($_GET['wpo365_review_stop'])) {
Wpmu_Helpers::mu_delete_transient('wpo365_review_dismissed');
Options_Service::add_update_option('review_stop', true);
Url_Helpers::force_redirect(remove_query_arg('wpo365_review_stop'));
}
if (isset($_GET['wpo365_upgrade_dismissed'])) {
Wpmu_Helpers::mu_delete_transient('wpo365_user_created');
Wpmu_Helpers::mu_set_transient('wpo365_upgrade_dismissed', date('d'), 1209600);
Url_Helpers::force_redirect(remove_query_arg('wpo365_upgrade_dismissed'));
}
}
}
}