Page 1 of 1

IP restriction question...

PostPosted: July 25th, 2011, 12:02 pm
by solraco
Is there any way to target certain account levels for different IP restrictions...

For example if I had a level 1 account restricted to 2 IPs and then had a level 2 account that was restricted to 10 IPs?

Is there any way to do this with s2member?

Thanks for the help in advanced.

Re: IP restriction question...

PostPosted: July 26th, 2011, 2:12 am
by Cristián Lávaque
s2Member doesn't have that yet, but you may be able to hack it in.

Here's a related thread viewtopic.php?f=4&t=2839#p9484

Take the hack Jason posted and edit it to work for you. Here's the line where that hook is in the IP Restrictions file. viewtopic.php?f=40&t=13016&src_doc_v=110710#src_doc_line_45

Based on the level of the current user, you could edit the number of IPs changing $GLOBALS["WS_PLUGIN__"]["s2member"]["o"]["max_ip_restriction"] in your hack.

/wp-content/mu-plugins/s2hacks.php
Code: Select all
<?php
add_action 
('ws_plugin__s2member_before_ip_restrictions_ok', 'levels_max_ips');
function levels_max_ips($vars = array()) {
    if (is_object($user = new WP_User($username = $vars['restriction'])))
        if ($user->has_cap('s2member_level1'))
            $GLOBALS['WS_PLUGIN__']['s2member']['o']['max_ip_restriction'] = 2;
        if ($user->has_cap('s2member_level2'))
            $GLOBALS['WS_PLUGIN__']['s2member']['o']['max_ip_restriction'] = 10;
}
?>


Haven't tried it. Let me know if that helps. :)

Re: IP restriction question...

PostPosted: July 26th, 2011, 4:28 pm
by solraco
Hi Cris.

That worked perfectly.

Thank you so much for your help.

Do you know if this functionality will be added to a future release?

Thanks again!

Re: IP restriction question...

PostPosted: July 27th, 2011, 1:55 am
by Cristián Lávaque
Awesome! Thanks for the update. :)

I imagine it may at some point, no date at this moment, though. Still, this hack will remain after updates, so it's safe to use for now.