Skip to content

Commit

Permalink
Add AMP support for admin bar stats
Browse files Browse the repository at this point in the history
  • Loading branch information
westonruter committed Dec 10, 2018
1 parent 6a07664 commit c83dd8c
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions modules/stats.php
Original file line number Diff line number Diff line change
Expand Up @@ -958,7 +958,7 @@ function stats_admin_bar_head() {
}
#wpadminbar .quicklinks li#wp-admin-bar-stats a img {
height: 24px;
padding: 4px 0;
margin: 4px 0;
max-width: none;
border: none;
}
Expand All @@ -983,7 +983,15 @@ function stats_admin_bar_menu( &$wp_admin_bar ) {

$title = esc_attr( __( 'Views over 48 hours. Click for more Site Stats.', 'jetpack' ) );

$menu = array( 'id' => 'stats', 'title' => "<div><script type='text/javascript'>var src;if(typeof(window.devicePixelRatio)=='undefined'||window.devicePixelRatio<2){src='$img_src';}else{src='$img_src_2x';}document.write('<img src=\''+src+'\' alt=\'$alt\' title=\'$title\' />');</script></div>", 'href' => $url );
$menu = array(
'id' => 'stats',
'href' => $url,
);
if ( Jetpack_AMP_Support::is_amp_request() ) {
$menu['title'] = "<amp-img src='$img_src_2x' width=112 height=24 layout=fixed alt='$alt' title='$title'></amp-img>";
} else {
$menu['title'] = "<div><script type='text/javascript'>var src;if(typeof(window.devicePixelRatio)=='undefined'||window.devicePixelRatio<2){src='$img_src';}else{src='$img_src_2x';}document.write('<img src=\''+src+'\' alt=\'$alt\' title=\'$title\' />');</script></div>";
}

$wp_admin_bar->add_menu( $menu );
}
Expand Down

0 comments on commit c83dd8c

Please sign in to comment.