Arrow

Redirect by client IP | Peter's Login Redirect | Forum

Back to the login redirect plugin page

Please consider registering
guest

Log In

Lost password?
Advanced Search

— Forum Scope —

  

— Match —

   

— Forum Options —

   

Minimum search word length is 4 characters - maximum search word length is 84 characters

Topic RSS
Redirect by client IP
April 8, 2011
3:46 pm
belg4mit
Guest

Would you consider adding the ability to redirect to a certain location if the client IP matches a certain class? If it does not, it would fail over to the other rules? I've patched our local install of an older version to do so, but it would be easier to keep up to date if it were not custom.

We use this because we have dedicated kiosk for staff to access our site when they are in the office, and there is a specific page they are most likely to access, but when off site there are other areas they are more likely to need.

TIA!

April 12, 2011
8:35 am
Peter
Admin
Forum Posts: 841
Offline

Can you share your code? At least in the short term, I don't think I would add such functionality. But your code might help others in the meantime and could also serve as the basis for including the functionality in the core plugin release.

In general, I've considered adding generic hooks within my plugin, although I realized that people would then be creating plugins for my plugin. You could instead use the WordPress hook that I use in your own separate plugin to add functionality before or after WordPress loads my plugin. I could add my own hooks for people to add redirect rules in between my plugin's rules, if there's enough demand for it.

April 12, 2011
11:14 am
belg4mit
Guest

There's not too much to it, since it's hard-coded rather than having user settings, but it's enough to put the module out of sync an a PITA to keep up to date:

function redirect_to_front_page( $redirect_to, $requested_redirect_to, $user )
{
global $wpdb, $rul_db_addresses;

+ #Kiosk-specific redirect
+ if( preg_match('/^192\.168\.15\./', $_SERVER['REMOTE_ADDR']) )
+ return '/kiosk';

June 5, 2011
9:05 pm
Peter
Admin
Forum Posts: 841
Offline

In version 2.1.0 of the plugin you can now add your own extensions to the plugin to accomplish the above. See readme.txt included in the plugin for full documentation. Here is an example of code for your own plugin to add logic before any of the redirect plugin's checks (sorry about the lack of indenting by the forum software):

function redirectByIP( $empty, $redirect_to, $requested_redirect_to, $user )
{
$ip_check = '192.168.0';
if( 0 === strpos( $_SERVER['REMOTE_ADDR'], $ip_check ) )
{
return '/secret_area';
}
else
{
return false;
}
}

add_filter( 'rul_before_user', 'redirectByIP', 10, 4 );

June 6, 2011
8:59 am
belg4mit
Guest

Thanks!