| 1 |
<?php |
| 2 |
/** |
| 3 |
* Status and information regarding the site visitor. |
| 4 |
* |
| 5 |
* @package automattic/jetpack-status |
| 6 |
*/ |
| 7 |
|
| 8 |
namespace Automattic\Jetpack\Status; |
| 9 |
|
| 10 |
/** |
| 11 |
* Visitor class. |
| 12 |
*/ |
| 13 |
class Visitor { |
| 14 |
|
| 15 |
/** |
| 16 |
* Gets current user IP address. |
| 17 |
* |
| 18 |
* @param bool $check_all_headers Check all headers? Default is `false`. |
| 19 |
* |
| 20 |
* @return string Current user IP address. |
| 21 |
*/ |
| 22 |
public function get_ip( $check_all_headers = false ) { |
| 23 |
if ( $check_all_headers ) { |
| 24 |
foreach ( array( |
| 25 |
'HTTP_CF_CONNECTING_IP', |
| 26 |
'HTTP_CLIENT_IP', |
| 27 |
'HTTP_X_FORWARDED_FOR', |
| 28 |
'HTTP_X_FORWARDED', |
| 29 |
'HTTP_X_CLUSTER_CLIENT_IP', |
| 30 |
'HTTP_FORWARDED_FOR', |
| 31 |
'HTTP_FORWARDED', |
| 32 |
'HTTP_VIA', |
| 33 |
) as $key ) { |
| 34 |
if ( ! empty( $_SERVER[ $key ] ) ) { |
| 35 |
// @todo Some of these might actually be lists of IPs (e.g. HTTP_X_FORWARDED_FOR) or something else entirely (HTTP_VIA). |
| 36 |
return filter_var( wp_unslash( $_SERVER[ $key ] ) ); |
| 37 |
} |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
return ! empty( $_SERVER['REMOTE_ADDR'] ) ? filter_var( wp_unslash( $_SERVER['REMOTE_ADDR'] ) ) : ''; |
| 42 |
} |
| 43 |
|
| 44 |
/** |
| 45 |
* Simple gate check for a11n feature testing purposes using AT_PROXIED_REQUEST constant. |
| 46 |
* IMPORTANT: Only use it for internal feature test purposes, not authorization. |
| 47 |
* |
| 48 |
* The goal of this function is to help us gate features by using a similar function name |
| 49 |
* we find on simple sites: is_automattician(). |
| 50 |
* |
| 51 |
* @return bool True if the current request is PROXIED, false otherwise. |
| 52 |
*/ |
| 53 |
public function is_automattician_feature_flags_only() { |
| 54 |
return ( defined( 'AT_PROXIED_REQUEST' ) && AT_PROXIED_REQUEST ); |
| 55 |
} |
| 56 |
} |
| 57 |
|