| 1 |
<?php |
| 2 |
|
| 3 |
class Redirection_IP { |
| 4 |
private $ip; |
| 5 |
|
| 6 |
public function __construct( $ip = '' ) { |
| 7 |
$this->ip = ''; |
| 8 |
|
| 9 |
$ip = sanitize_text_field( $ip ); |
| 10 |
$ip = explode( ',', $ip ); |
| 11 |
$ip = array_shift( $ip ); |
| 12 |
$ip = filter_var( $ip, FILTER_VALIDATE_IP ); |
| 13 |
|
| 14 |
// Convert to binary |
| 15 |
// phpcs:ignore |
| 16 |
$ip = @inet_pton( trim( $ip ) ); |
| 17 |
if ( $ip !== false ) { |
| 18 |
// phpcs:ignore |
| 19 |
$this->ip = @inet_ntop( $ip ); // Convert back to string |
| 20 |
} |
| 21 |
} |
| 22 |
|
| 23 |
public function get() { |
| 24 |
return $this->ip; |
| 25 |
} |
| 26 |
} |