Last active
March 17, 2017 18:38
-
-
Save cklosowski/78723020a93bc030d62589bbe69f6b34 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: Public IP FIx | |
* Plugin URI: https://kungfugrep.com | |
* Description: For testing IP sensitive code, use the public facing IP in your localhost | |
* Version: 1.0 | |
* Author: Filament Studios | |
* Author URI: https://filament-studios.com | |
* License: GPL-2.0+ | |
*/ | |
/** | |
* | |
* The point of this plugin is to allow a local development environment to identify | |
* the REMOTE_ADDR of the user as the public facing IP, which is able to be used in | |
* GeoIP lookups and WHOIS checks for things like fraud services and other types of | |
* eCommerce and rate limiting checks | |
* | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; | |
} | |
function kfg_use_external_ip() { | |
$ip = get_transient( '_kfg_remote_ip' ); | |
// When testing this by manually changing the IP below on line 49, uncomment the following line | |
// $ip = false; | |
if ( false === $ip ) { | |
$response = wp_remote_get( 'http://bot.whatismyipaddress.com/' ); | |
if ( ! is_wp_error( $response ) ) { | |
$body = wp_remote_retrieve_body( $response ); | |
$ip = $body; | |
set_transient( '_kfg_remote_ip', $ip, HOUR_IN_SECONDS ); | |
} | |
} | |
if ( false !== filter_var( $ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE ) ) { | |
$_SERVER['REMOTE_ADDR'] = $ip; | |
} | |
/** | |
* If you want to use a specific IP Address just uncomment out the following line, and put in the IP you want to use | |
*/ | |
// $_SERVER['REMOTE_ADDR'] = '123.123.123.123'; | |
} | |
add_action( 'plugins_loaded', 'kfg_use_external_ip', 1 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment