Support » Plugins » Hacks » Prevent count of Administrators, not all logged in users

  • Resolved Xps


    Running Stats version 1.8.1 on a self-hosted

    I am looking to modify this plugin to prevent Super Admins and users of the Administrator role from being counted. I know I can disable the “Count the page views of registered users who are logged in” option in the plugin’s settings, but that doesn’t work for me because some of my visitors do register, and I’d like to utilize registrations more in the future. I want to count all visitors – logged in or out – except the main Admin account created during installation and my everyday Admin role account.

    I found line 1298 of /plugins/stats/stats.php where stats_footer is added to the wp_footer hook. Upon adding an if statement around that which checked whether the user wasn’t super_admin nor an administrator role, I got an error message about wp_get_current_user() being called but not yet defined. Would someone please let me know how to perform my task?

    Edit: I’ve looked at these Codex pages:

Viewing 10 replies - 1 through 10 (of 10 total)
  • Tom


    Sorry I can’t offer any help on this matter, but I wanted to comment so I could subscribe to the thread, as I too would like this option.

    I’m using WordPress as an eCommerce store, so I DO want to track registered users, but I don’t want to track Admin/ editors stats.

    I’m glad you commented Tom, because I’m sure a lot of sites run into this. As Admins, we don’t care about tracking our visits, just every other member and visitor to the site.

    I also wanted to correct a mistake I made in my previous post (missed the 1 hr edit and didn’t want to double-post). My everyday account is an Editor.

    If I come up with anything on my own, I’ll be sure to let you know.



    If I’m honest Xps… I don’t think there’s much (or any?) support going on with this plugin anymore.. I feel they’re trying to push us over to using JetPack.

    I have tried it, but it’s just not as good. I really like this plugin, and it’d be great if we could find a fix.

    So, likewise if I find anything, I’ll be sure to post back here & let you know.

    I believe I have the solution. Ignore line 1298 with the wp_footer hook. On line 91, which is blank and after global $wp_the_query, $current_user;
    if ( ! current_user_can('administrator') && ! current_user_can('editor') ) {

    On line 122, add a second right-curly-brace to close the If statement just created.

    Viewing the page source, the stats script didn’t load on my Admin or everyday Editor accounts, but it did load on my test Subscriber account and also to a visitor not logged in.



    Many thanks Xps, I’ll give this a go and let you know how I get on.



    I’ve only just got around to testing this, and whilst it seems to stop the plugin from tracking Admins & Editors – it also stops the plugin from loading in my dashboard (Neither the dashboard widget or the menu item is added to my menu).

    So whilst it’s doing what we needed it to – it’s kinda’ pointless if we can’t see the stats.

    Can you please clarify if you’re having the same issue?




    Reading your instructions again, I’ve realised that I misunderstood what you said…

    By “Ignore line 1298 with the wp_footer hook.” – I thought you meant to comment it out by using // in front of it. By ‘ignore’, and after reading the entire thread again, I now see what you meant by this.

    I can now confirm that this fix works. Thanks very much, most appreciated 🙂

    Sorry for the confusion. How I should have worded post 5:

    …Ignore what I said about adjusting line 1298 with the wp_footer hook because the real adjustments should be made elsewhere…

    Glad you figured it out.

    For others who may read this, the line numbers I mentioned don’t apply to the [currently] recent version of this plugin: 1.8.5
    That blank line which was line 91 is now line 148. The closing right-curly brace is now on line 179 instead of line 122.



    Sorry to be a pain, Xps, but could you please let me know on which lines we need to add this code in the latest version?

    The original line 91 has now become line 195, but I’m not sure on which line to close the if statement?




    OK, actually I figured it out, but it causes an error, so perhaps it no longer goes after the following line:

    global $wp_the_query, $current_user;

Viewing 10 replies - 1 through 10 (of 10 total)
  • The topic ‘Prevent count of Administrators, not all logged in users’ is closed to new replies.