| Conditions | 7 |
| Paths | 6 |
| Total Lines | 151 |
| Code Lines | 131 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 205 | function monsterinsights_administrator_tracking_notice() { |
||
| 206 | // Don't do anything for guests. |
||
| 207 | if ( ! is_user_logged_in() ) { |
||
| 208 | return; |
||
| 209 | } |
||
| 210 | |||
| 211 | // Only show this for users who can see the settings panel. |
||
| 212 | if ( ! current_user_can( 'monsterinsights_save_settings' ) ) { |
||
| 213 | return; |
||
| 214 | } |
||
| 215 | |||
| 216 | // Only show when tracking. |
||
| 217 | $ua = monsterinsights_get_ua(); |
||
| 218 | if ( empty( $ua ) ) { |
||
| 219 | return; |
||
| 220 | } |
||
| 221 | |||
| 222 | // Don't show if already dismissed. |
||
| 223 | if ( get_option( 'monsterinsights_frontend_tracking_notice_viewed', false ) ) { |
||
| 224 | return; |
||
| 225 | } |
||
| 226 | |||
| 227 | ?> |
||
| 228 | <div class="monsterinsights-tracking-notice monsterinsights-tracking-notice-hide"> |
||
| 229 | <div class="monsterinsights-tracking-notice-icon"> |
||
| 230 | <img src="<?php echo esc_url( plugins_url( 'assets/images/mascot.png', MONSTERINSIGHTS_PLUGIN_FILE ) ); ?>" width="40" alt="MonsterInsights Mascot" /> |
||
| 231 | </div> |
||
| 232 | <div class="monsterinsights-tracking-notice-text"> |
||
| 233 | <h3><?php esc_html_e( 'Tracking is Disabled for Administrators', 'ga-premium' ); ?></h3> |
||
| 234 | <p> |
||
| 235 | <?php |
||
| 236 | $doc_url = 'https://monsterinsights.com/docs/tracking-disabled-administrators-editors'; |
||
| 237 | $doc_url = add_query_arg( array( |
||
| 238 | 'utm_source' => monsterinsights_is_pro_version() ? 'proplugin' : 'liteplugin', |
||
| 239 | 'utm_medium' => 'frontend-notice', |
||
| 240 | 'utm_campaign' => 'admin-tracking-doc', |
||
| 241 | ), $doc_url ); |
||
| 242 | // Translators: %s is the link to the article where more details about tracking are listed. |
||
| 243 | printf( esc_html__( 'To keep stats accurate, we do not load Google Analytics scripts for admin users. %1$sLearn More »%2$s', 'ga-premium' ), '<a href="' . esc_url( $doc_url ) . '" target="_blank">', '</a>' ); |
||
| 244 | ?> |
||
| 245 | </p> |
||
| 246 | </div> |
||
| 247 | <div class="monsterinsights-tracking-notice-close">×</div> |
||
| 248 | </div> |
||
| 249 | <style type="text/css"> |
||
| 250 | .monsterinsights-tracking-notice { |
||
| 251 | position: fixed; |
||
| 252 | bottom: 20px; |
||
| 253 | right: 15px; |
||
| 254 | font-family: Arial, Helvetica, "Trebuchet MS", sans-serif; |
||
| 255 | background: #fff; |
||
| 256 | box-shadow: 0 0 10px 0 #dedede; |
||
| 257 | padding: 6px 5px; |
||
| 258 | display: flex; |
||
| 259 | align-items: center; |
||
| 260 | justify-content: center; |
||
| 261 | width: 380px; |
||
| 262 | max-width: calc( 100% - 30px ); |
||
| 263 | border-radius: 6px; |
||
| 264 | transition: bottom 700ms ease; |
||
| 265 | z-index: 10000; |
||
| 266 | } |
||
| 267 | |||
| 268 | .monsterinsights-tracking-notice h3 { |
||
| 269 | font-size: 13px; |
||
| 270 | color: #222; |
||
| 271 | font-weight: 700; |
||
| 272 | margin: 0 0 8px; |
||
| 273 | padding: 0; |
||
| 274 | line-height: 1; |
||
| 275 | border: none; |
||
| 276 | } |
||
| 277 | |||
| 278 | .monsterinsights-tracking-notice p { |
||
| 279 | font-size: 13px; |
||
| 280 | color: #7f7f7f; |
||
| 281 | font-weight: 400; |
||
| 282 | margin: 0; |
||
| 283 | padding: 0; |
||
| 284 | line-height: 1.2; |
||
| 285 | border: none; |
||
| 286 | } |
||
| 287 | |||
| 288 | .monsterinsights-tracking-notice p a { |
||
| 289 | color: #7f7f7f; |
||
| 290 | font-size: 13px; |
||
| 291 | line-height: 1.2; |
||
| 292 | margin: 0; |
||
| 293 | padding: 0; |
||
| 294 | text-decoration: underline; |
||
| 295 | font-weight: 400; |
||
| 296 | } |
||
| 297 | |||
| 298 | .monsterinsights-tracking-notice p a:hover { |
||
| 299 | color: #7f7f7f; |
||
| 300 | text-decoration: none; |
||
| 301 | } |
||
| 302 | |||
| 303 | .monsterinsights-tracking-notice-icon img { |
||
| 304 | height: auto; |
||
| 305 | display: block; |
||
| 306 | margin: 0; |
||
| 307 | } |
||
| 308 | |||
| 309 | .monsterinsights-tracking-notice-icon { |
||
| 310 | padding: 14px; |
||
| 311 | background-color: #f2f6ff; |
||
| 312 | border-radius: 6px; |
||
| 313 | flex-grow: 0; |
||
| 314 | flex-shrink: 0; |
||
| 315 | margin-right: 12px; |
||
| 316 | } |
||
| 317 | |||
| 318 | .monsterinsights-tracking-notice-close { |
||
| 319 | padding: 0; |
||
| 320 | margin: 0 3px 0 0; |
||
| 321 | border: none; |
||
| 322 | box-shadow: none; |
||
| 323 | border-radius: 0; |
||
| 324 | color: #7f7f7f; |
||
| 325 | background: transparent; |
||
| 326 | line-height: 1; |
||
| 327 | align-self: flex-start; |
||
| 328 | cursor: pointer; |
||
| 329 | font-weight: 400; |
||
| 330 | } |
||
| 331 | |||
| 332 | .monsterinsights-tracking-notice.monsterinsights-tracking-notice-hide { |
||
| 333 | bottom: -200px; |
||
| 334 | } |
||
| 335 | </style> |
||
| 336 | <?php |
||
| 337 | |||
| 338 | if ( ! wp_script_is( 'jquery', 'queue' ) ) { |
||
| 339 | wp_enqueue_script( 'jquery' ); |
||
| 340 | } |
||
| 341 | ?> |
||
| 342 | <script> |
||
| 343 | if ( 'undefined' !== typeof jQuery ) { |
||
| 344 | jQuery( document ).ready( function ( $ ) { |
||
| 345 | /* Don't show the notice if we don't have a way to hide it (no js, no jQuery). */ |
||
| 346 | $( document.querySelector( '.monsterinsights-tracking-notice' ) ).removeClass( 'monsterinsights-tracking-notice-hide' ); |
||
| 347 | $( document.querySelector( '.monsterinsights-tracking-notice-close' ) ).on( 'click', function ( e ) { |
||
| 348 | e.preventDefault(); |
||
| 349 | $( this ).closest( '.monsterinsights-tracking-notice' ).addClass( 'monsterinsights-tracking-notice-hide' ); |
||
| 350 | $.ajax( { |
||
| 351 | url: '<?php echo esc_url( admin_url( 'admin-ajax.php' ) ); ?>', |
||
| 352 | method: 'POST', |
||
| 353 | data: { |
||
| 354 | action: 'monsterinsights_dismiss_tracking_notice', |
||
| 355 | nonce: '<?php echo esc_js( wp_create_nonce( 'monsterinsights-tracking-notice' ) ); ?>', |
||
| 356 | } |
||
| 381 |