| @@ -8,8 +8,9 @@ | ||
| 8 | 8 | namespace Automattic\Jetpack\Scan; |
| 9 | 9 | |
| 10 | 10 | use Automattic\Jetpack\Assets; |
| 11 | 11 | use Automattic\Jetpack\Redirect; |
| 12 | +use WP_Admin_Bar; | |
| 12 | 13 | |
| 13 | 14 | /** |
| 14 | 15 | * Class Main |
| 15 | 16 | * |
| @@ -104,10 +105,21 @@ | ||
| 104 | 105 | return; |
| 105 | 106 | } |
| 106 | 107 | |
| 107 | 108 | // We don't know about threats in the cache lets load the JS that fetches the info and updates the admin bar. |
| 108 | - Assets::enqueue_async_script( self::SCRIPT_NAME, '_inc/build/scan/admin-bar-notice.min.js', 'modules/scan/admin-bar-notice.js', array( 'admin-bar' ), self::SCRIPT_VERSION, true ); | |
| 109 | - | |
| 109 | + Assets::register_script( | |
| 110 | + self::SCRIPT_NAME, | |
| 111 | + '_inc/build/scan/admin-bar-notice.min.js', | |
| 112 | + JETPACK__PLUGIN_FILE, | |
| 113 | + array( | |
| 114 | + 'in_footer' => true, | |
| 115 | + 'strategy' => 'defer', | |
| 116 | + 'nonmin_path' => 'modules/scan/admin-bar-notice.js', | |
| 117 | + 'dependencies' => array( 'admin-bar' ), | |
| 118 | + 'version' => self::SCRIPT_VERSION, | |
| 119 | + 'enqueue' => true, | |
| 120 | + ) | |
| 121 | + ); | |
| 110 | 122 | $script_data = array( |
| 111 | 123 | 'nonce' => wp_create_nonce( 'wp_rest' ), |
| 112 | 124 | 'scan_endpoint' => get_rest_url( null, 'jetpack/v4/scan' ), |
| 113 | 125 | 'scan_dashboard_url' => Redirect::get_url( 'calypso-scanner' ), |
| @@ -162,12 +174,13 @@ | ||
| 162 | 174 | ), |
| 163 | 175 | ); |
| 164 | 176 | |
| 165 | 177 | if ( $has_threats ) { |
| 166 | - $node['href'] = esc_url( Redirect::get_url( 'calypso-scanner' ) ); | |
| 167 | - $node['meta']['onclick'] = 'window.open( this.href ); return false;'; | |
| 168 | - $node['meta']['class'] = 'error'; | |
| 169 | - $node['title'] = sprintf( | |
| 178 | + $node['href'] = esc_url( Redirect::get_url( 'calypso-scanner' ) ); | |
| 179 | + $node['meta']['target'] = '_blank'; | |
| 180 | + $node['meta']['rel'] = 'noopener noreferrer'; | |
| 181 | + $node['meta']['class'] = 'error'; | |
| 182 | + $node['title'] = sprintf( | |
| 170 | 183 | esc_html( |
| 171 | 184 | /* translators: %s is the alert icon */ |
| 172 | 185 | _n( '%s Threat found', '%s Threats found', $this->get_threat_count(), 'jetpack' ) |
| 173 | 186 | ), |
| @@ -197,9 +210,9 @@ | ||
| 197 | 210 | if ( empty( $scan_state ) ) { |
| 198 | 211 | return null; |
| 199 | 212 | } |
| 200 | 213 | // Return true if there is at least one threat found. |
| 201 | - return (bool) isset( $scan_state->threats[0] ); | |
| 214 | + return isset( $scan_state->threats[0] ); | |
| 202 | 215 | } |
| 203 | 216 | |
| 204 | 217 | /** |
| 205 | 218 | * Returns the number of threats found or 0. |