Support » Networking WordPress » Adding a link to stats in My Sites drop down

Viewing 8 replies - 1 through 8 (of 8 total)
  • What stats plugin are you using?

    Jetpack and Google Analytics, I really only want a link to jetpack.

    It has a top-level menu, you know. You see it per-site. But if you want it to show up under the section for dashboard etc… this will have to be done via a custom plugin.

    Make a file called adminbar-jetpack.php, we’re going to put it in your mu-plugins folder.

    It should contain this:

    <?php
    
    /*
    Plugin Name: Jetpack Menu Stats
    Description: Show 'stats' in the per-site menu bar.
    Version: 1
    Author: Me
    */
    
    function jetpack_stats_my_sites( $wp_admin_bar ) {
            global $wpdb;
    
            foreach ( (array) $wp_admin_bar->user->blogs as $blog ) {
    
                    $blogname = empty( $blog->blogname ) ? $blog->domain : $blog->blogname;
                    $menu_id  = 'blog-' . $blog->userblog_id;
    
                    $wp_admin_bar->add_menu( array(
                            'parent' => $menu_id,
                            'id'     => $menu_id . '-stats',
                            'title'  => __( 'Stats' ),
                            'href'   => get_admin_url( $blog->userblog_id ).'admin.php?page=stats',
                    ) );
            }
    }
    
    add_action( 'admin_bar_menu', 'jetpack_stats_my_sites', 90 );
    
    ?>

    @ipstenu Thank you so much, it works beautifully!

    No problem (it was an interesting coding challenge!)

    Of note – It’ll still show the links if you have Jetpack’s Stats on or not, because I couldn’t sort out how to tell if that feature was on or not. I know how to check if a plugin’s on or not (you’d have to do a quick switch to blog and use is_plugin_active() for it), but Stats are a ‘sub’ plugin and I’m not entirely sure if that’s grabable.

    I’m not too concerned about it, but could you just put it in the plugin file for stats?

    Yes and no. You can, but you’d lose it every time you upgrade.

    I’ve tossed it up here: http://halfelf.org/hacks/jetpack-menu-stats/

    There are a couple tweaks and adjustments for i8n and cleaning up.

    Thank ya much!

Viewing 8 replies - 1 through 8 (of 8 total)
  • The topic ‘Adding a link to stats in My Sites drop down’ is closed to new replies.