@@ -95,8 +95,16 @@ function ct_dashboard_statistics_widget()
95
95
if (isset ($ apbct ->data ['wl_brandname ' ]) && $ apbct ->data ['wl_brandname ' ] !== APBCT_NAME ) {
96
96
$ actual_plugin_name = $ apbct ->data ['wl_brandname ' ];
97
97
}
98
+ /**
99
+ * Hook. List of allowed user roles for the Dashboard widget.
100
+ * add_filter('apbct_hook_dashboard_widget_allowed_roles_list', function($roles_list) {
101
+ * $roles_list[] = 'editor';
102
+ * return $roles_list;
103
+ * });
104
+ */
105
+ $ roles_list = apply_filters ('apbct_hook_dashboard_widget_allowed_roles_list ' , array ('administrator ' ));
98
106
99
- if ( apbct_is_user_role_in (array ( ' administrator ' ) ) ) {
107
+ if (is_array ( $ roles_list ) && apbct_is_user_role_in ($ roles_list ) ) {
100
108
wp_add_dashboard_widget (
101
109
'ct_dashboard_statistics_widget ' ,
102
110
$ actual_plugin_name ,
@@ -172,7 +180,7 @@ function ct_dashboard_statistics_widget_output($_post, $_callback_args)
172
180
"<u> {$ apbct ->brief_data ['error ' ]}</u> "
173
181
)
174
182
. '</h2> ' ;
175
- if ( $ apbct ->user_token && ! $ apbct ->white_label ) {
183
+ if (apbct_is_user_role_in ( array ( ' administrator ' )) && $ apbct ->user_token && ! $ apbct ->white_label ) {
176
184
$ link = LinkConstructor::buildCleanTalkLink (
177
185
'anti_crawler_inactive ' ,
178
186
'my ' ,
@@ -225,7 +233,7 @@ function ct_dashboard_statistics_widget_output($_post, $_callback_args)
225
233
} ?>
226
234
</table>
227
235
<?php
228
- if ( $ apbct ->user_token && ! $ apbct ->data ["wl_mode_enabled " ] ) {
236
+ if (apbct_is_user_role_in ( array ( ' administrator ' )) && $ apbct ->user_token && ! $ apbct ->data ["wl_mode_enabled " ] ) {
229
237
$ link = LinkConstructor::buildCleanTalkLink (
230
238
'dashboard_widget_all_data_link ' ,
231
239
'my/show_requests ' ,
@@ -244,50 +252,55 @@ function ct_dashboard_statistics_widget_output($_post, $_callback_args)
244
252
<?php
245
253
}
246
254
// Notice at the bottom
247
- if ( isset ($ current_user ) && in_array ('administrator ' , $ current_user ->roles ) ) {
248
- if ( $ apbct ->spam_count && $ apbct ->spam_count > 0 ) {
255
+ if ( $ apbct ->spam_count && $ apbct ->spam_count > 0 ) {
256
+ $ cp_total_stats = '' ;
257
+ //Link to CP is only for admins due the token provided
258
+ if ( apbct_is_user_role_in (array ('administrator ' )) ) {
249
259
$ link = LinkConstructor::buildCleanTalkLink (
250
260
'dashboard_widget_go_to_cp ' ,
251
261
'my ' ,
252
262
array (
253
263
'user_token ' => $ apbct ->user_token ,
254
- 'cp_mode ' => 'antispam '
264
+ 'cp_mode ' => 'antispam '
255
265
)
256
266
);
257
- echo '<div class="ct_widget_wprapper_total_blocked"> '
258
- . ($ apbct ->data ["wl_mode_enabled " ] ? '' : '<img src=" ' . Escape::escUrl ($ apbct ->logo__small__colored ) . '" class="ct_widget_small_logo"/> ' )
259
- . '<span title=" ' . sprintf (
260
- __ (
261
- 'This is the count from the %s \'s cloud and could be different to admin bar counters ' ,
262
- 'cleantalk-spam-protect '
263
- ) . '"> ' ,
264
- $ actual_plugin_name
265
- )
266
- . sprintf (
267
- /* translators: %s: Number of spam messages */
268
- __ (
269
- '%s%s%s has blocked %s spam for past year. The statistics are automatically updated every 24 hours. ' ,
270
- 'cleantalk-spam-protect '
271
- ),
272
- ! $ apbct ->data ["wl_mode_enabled " ] ? '<a href=" ' . $ link . '" target="_blank"> ' : '' ,
273
- $ actual_plugin_name ,
274
- ! $ apbct ->data ["wl_mode_enabled " ] ? '</a> ' : '' ,
275
- number_format ($ apbct ->data ['spam_count ' ], 0 , ', ' , ' ' )
276
- )
277
- . '</span> '
278
- . (! $ apbct ->white_label && ! $ apbct ->data ["wl_mode_enabled " ]
279
- ? '<br><br> '
280
- . '<b style="font-size: 16px;"> '
281
- . sprintf (
282
- __ ('Do you like CleanTalk? %sPost your feedback here%s. ' , 'cleantalk-spam-protect ' ),
283
- '<u><a href="https://wordpress.org/support/plugin/cleantalk-spam-protect/reviews/#new-post" target="_blank"> ' ,
284
- '</a></u> '
285
- )
286
- . '</b> '
287
- : ''
288
- )
289
- . '</div> ' ;
267
+ $ cp_total_stats =
268
+ ($ apbct ->data ["wl_mode_enabled " ] ? '' : '<img src=" ' . Escape::escUrl ($ apbct ->logo__small__colored ) . '" class="ct_widget_small_logo"/> ' )
269
+ . '<span title=" '
270
+ . sprintf (
271
+ __ (
272
+ 'This is the count from the %s \'s cloud and could be different to admin bar counters ' ,
273
+ 'cleantalk-spam-protect '
274
+ ) . '"> ' ,
275
+ $ actual_plugin_name
276
+ )
277
+ . sprintf (
278
+ /* translators: %s: Number of spam messages */
279
+ __ (
280
+ '%s%s%s has blocked %s spam for past year. The statistics are automatically updated every 24 hours. ' ,
281
+ 'cleantalk-spam-protect '
282
+ ),
283
+ ! $ apbct ->data ["wl_mode_enabled " ] ? '<a href=" ' . $ link . '" target="_blank"> ' : '' ,
284
+ $ actual_plugin_name ,
285
+ ! $ apbct ->data ["wl_mode_enabled " ] ? '</a> ' : '' ,
286
+ number_format ($ apbct ->data ['spam_count ' ], 0 , ', ' , ' ' )
287
+ )
288
+ . '</span> ' ;
290
289
}
290
+ echo '<div class="ct_widget_wprapper_total_blocked"> '
291
+ . $ cp_total_stats
292
+ . (! $ apbct ->white_label && ! $ apbct ->data ["wl_mode_enabled " ]
293
+ ? '<br><br> '
294
+ . '<b style="font-size: 16px;"> '
295
+ . sprintf (
296
+ __ ('Do you like CleanTalk? %sPost your feedback here%s. ' , 'cleantalk-spam-protect ' ),
297
+ '<u><a href="https://wordpress.org/support/plugin/cleantalk-spam-protect/reviews/#new-post" target="_blank"> ' ,
298
+ '</a></u> '
299
+ )
300
+ . '</b> '
301
+ : ''
302
+ )
303
+ . '</div> ' ;
291
304
}
292
305
echo '</div> ' ;
293
306
}
@@ -527,10 +540,18 @@ function apbct_admin__enqueue_scripts($hook)
527
540
$ data = array_merge ($ data , EmailEncoder::getLocalizationText ());
528
541
wp_localize_script ('cleantalk-admin-js ' , 'ctAdminCommon ' , $ data );
529
542
543
+ /**
544
+ * Hook. List of allowed user roles for the Dashboard widget.
545
+ * add_filter('apbct_hook_dashboard_widget_allowed_roles_list', function($roles_list) {
546
+ * $roles_list[] = 'editor';
547
+ * return $roles_list;
548
+ * });
549
+ */
550
+ $ roles_list = apply_filters ('apbct_hook_dashboard_widget_allowed_roles_list ' , array ('administrator ' ));
530
551
// DASHBOARD page JavaScript and CSS
531
552
if (
532
553
$ hook == 'index.php ' &&
533
- apbct_is_user_role_in ( array ( ' administrator ' ) ) &&
554
+ is_array ( $ roles_list ) && apbct_is_user_role_in ( $ roles_list ) &&
534
555
$ apbct ->settings ['wp__dashboard_widget__show ' ] &&
535
556
! $ apbct ->moderate_ip
536
557
) {
0 commit comments