PluginProbe
Jetpack – WP Security, Backup, Speed, & Growth / 16.2
Jetpack – WP Security, Backup, Speed, & Growth v16.2
16.2 16.2-beta 12.0.3 12.1.3 12.2.3 12.3.2 12.4.2 12.5.2 12.6.4 12.7.3 12.8.3 12.9.5 13.0.2 13.1.5 13.2.4 13.3.3 13.4.5 13.5.2 13.6.2 13.7.2 13.8.3 13.9.2 14.0.1 14.1.1 14.2.2 All 502 releases
jetpack / modules / scan / admin-bar-notice.js

admin-bar-notice.js in Jetpack – WP Security, Backup, Speed, & Growth 16.2, at modules/scan/admin-bar-notice.js

53 lines 1.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 ( function ( localized ) {
2 function ready( fn ) {
3 if ( document.readyState !== 'loading' ) {
4 fn();
5 } else {
6 document.addEventListener( 'DOMContentLoaded', fn );
7 }
8 }
9
10 function fetch_scan_treats_and_add_link() {
11 var xhrRequest = new XMLHttpRequest();
12 xhrRequest.open( 'GET', localized.scan_endpoint, true );
13 xhrRequest.onload = function () {
14 if ( this.status === 200 ) {
15 // Success!
16 var body = JSON.parse( this.response );
17 if ( body && body.data ) {
18 var apiResponse = JSON.parse( body.data );
19 var numberOfThreats =
20 apiResponse.threats && apiResponse.threats.length ? apiResponse.threats.length : 0;
21 update_threats_link( numberOfThreats );
22 } else {
23 update_threats_link( 0 );
24 }
25 } else {
26 update_threats_link( 0 );
27 }
28 };
29 xhrRequest.setRequestHeader( 'X-WP-Nonce', localized.nonce );
30 xhrRequest.send();
31 }
32
33 ready( function () {
34 fetch_scan_treats_and_add_link();
35 } );
36
37 function update_threats_link( numberOfThreats ) {
38 var element = document.getElementById( 'wp-admin-bar-jetpack-scan-notice' );
39 if ( ! element ) {
40 return;
41 }
42
43 if ( ! numberOfThreats ) {
44 element.parentNode.removeChild( element );
45 return;
46 }
47
48 var textLabel = numberOfThreats === 1 ? localized.singular : localized.multiple;
49 element.innerHTML =
50 '<a href="' + localized.scan_dashboard_url + '" class="ab-item">' + textLabel + '</a>';
51 }
52 } )( window.Jetpack_Scan );
53