latest stable versions: v150827 (changelog)

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

IP Restriction by user level

Home Forums Community Forum IP Restriction by user level

This topic contains 3 replies, has 2 voices. Last updated by  Bruce 3 years, 6 months ago.

Topic Author Topic
Posted: Wednesday Jun 26th, 2013 at 7:39 am #52605
aus_team
Username: austeam

Hi,

Is it possible to set IP restriction only to specific users / user levels?

I have VIP members and they are allowed to login inunlimitted devices. Normal users are restricted to 1IP.

Is this doable?

Thanks

List Of Topic Replies

Viewing 3 replies - 1 through 3 (of 3 total)
Author Replies
Author Replies
Posted: Thursday Jun 27th, 2013 at 3:10 am #52649
Bruce
Username: Bruce
Staff Member

Thank you for your inquiry.

This is possible, but it requires custom code. You can use the information here with the ws_plugin__s2member_disable_specific_ip_restriction filter to do this:

Knowledge Base » Hacking s2Member® Via Hooks/Filters

s2Member passes 2 parameters through this filter. The first is a boolean (TRUE or FALSE) value that you can change to TRUE to prevent s2Member from firing the IP restriction and the other is an array of all of the variables that s2Member has at the point where it’s calling on the filter.

You can take a look at the variables that are set at this point in this file:

/s2member/includes/classes/ip-restrictions.inc.php

s2Member has a variable then called $restriction that can be a Username. You’ll want to check if that’s the case, and if it is then the IP Restriction is for when a User is logging in. You can find the User’s level through their Username and decide whether or not to disable IP Restrictions for that User. Here is some example code:

<?php
add_filter('ws_plugin__s2member_disable_specific_ip_restriction', 's2hack_disable_certain_ip_restrictions', 10, 2);

function s2hack_disable_certain_ip_restrictions ($bool, $vars) {
	if(username_exists($vars&#91;'restriction'&#93;)) { // Check if this is a Username
		$user = new WP_User($vars&#91;'restriction'&#93;); // This is now a WordPress User Object
		
		if($user->has_cap('access_s2member_level1')) // If User is s2Member Level 1 or higher, don't run IP Restrictions
			return true;
	}
	
	return false; // If the User doesn't match the needed specifics, then we run IP Restrictions
}

Let me know if you have any further questions. :-)

Posted: Thursday Jun 27th, 2013 at 9:04 am #52677
aus_team
Username: austeam

I think the code you provided will work for me.

I just need to know to which file should I add that code?

Will I have to add it everytime an update is made?

Thanks

Posted: Thursday Jun 27th, 2013 at 3:43 pm #52690
Bruce
Username: Bruce
Staff Member

I just need to know to which file should I add that code?

You would add it to a Must-Use Plugin file. See: http://codex.wordpress.org/Must_Use_Plugins

You only need to add it once.

Viewing 3 replies - 1 through 3 (of 3 total)

This topic is closed to new replies. Topics with no replies for 2 weeks are closed automatically.

Old Forums (READ-ONLY): The community now lives at WP Sharks™. If you have an s2Member® Pro question, please use our new Support System.

Contacting s2Member: Please use our Support Center for bug reports, pre-sale questions & technical assistance.