Multisites – Limit visits per month.

Hello

Does anyone have any suggestions on a possible way to limit the total unique visitors, sessions or pageviews per month on a multisite plan?

When they reach the limit it will alert an admin or something around these lines.

Cheers.

  • Nithin Ramdas
    • Support Wizard

    Hi Elliot Sowersby,

    Hope you are doing good today. :slight_smile:

    I’ll have to ping the developer regarding this, and ask to give a look whether there is a workaround. If possible, he would be able to offer some advice, if you are up to coding this. Please do note developers work round the clock, and have a slow response time, it may take a while to get a response. Either myself or the developer would keep you updated.

    I hope this helps. Please let us know if you need any further help. Have a nice day. :slight_smile:

    Kind Regards,

    Nithin

  • Ash
    • Code Norris

    Hi Elliot Sowersby

    Here is a code snippet that may help you. In the code, there is nothing to do with pro sites, but a very simple code to check every page visits, then restrict when it reaches the limit.

    To check with pageview, sessions etc you need to write your own algorithm, but I hope you will get an idea: https://gist.github.com/bappi-d-great/e1fff3801dfcef9c6915375fec8f4d5f

    Hope it helps :slight_smile: Please feel free to ask more question if you have any.

    Cheers

    Ash

  • Elliot Sowersby
    • The Incredible Code Injector

    For anyone that’s interested, here is a rough code guide for doing this.

    – This will track 1 hit per day, per visitor (using cache).

    – Alerts user if their site is over the visits limit.

    – Displays stats on a admin page.

    – Also displays upload usage and limit.

    The code should work fine if setup correctly. It does everything I need it to do.

    It is designed to work as a plugin. So create a new plugin, create a menu like:

    function pss_register_menus()
    {
    add_menu_page('PLUGIN NAME', 'PAGE NAME', 'manage_options', '/PLUGINPATH/pss_main.php', '', plugins_url('/icon.png', __FILE__), 35);
    }
    add_action('admin_menu', 'pss_register_menus');

    Then create the file ‘pss_main.php’ and insert code which can be found here:

    https://gist.github.com/elliotvs/ad5c0d2833d4c220da9bd089a76fa34c

    May extend this to send email to admin if limit is reached for a site.

    I may also create this into a downloadable plugin that’s easier to use in the future. Will post here if so.

    Enjoy! :grinning:

    Thanks to Ash and nithin for the help.

  • Ash
    • Code Norris

    Great snippet :slight_smile:

    Maybe you can replace these two line with the standard way:

    $sql = "SELECT level FROM {$wpdb->base_prefix}pro_sites WHERE blog_ID = '$blog_id'";
    $level = $wpdb->get_var($sql);

    with

    global $psts;
    $level = $psts->get_level($blog_id);

    And instead of

    global $wpdb;
    $blog_id = $wpdb->blogid;

    just

    $blog_id = get_current_blog_id();

    This is because, if anywhere in the code there is switch_to_blog(x) applied and then current blog is not restored, then $blog_id = $wpdb->blogid; will return x instead of current blog ID.

    Anyway, thanks for sharing the code, sending some points in your way :slight_smile:

    Have an awesome day!

    Cheers

    Ash