| @@ -17,9 +17,9 @@ | ||
| 17 | 17 | * TODO Maybe pass this as a constructor dependency? |
| 18 | 18 | * |
| 19 | 19 | * @const string |
| 20 | 20 | */ |
| 21 | - const VERSION = '3.10.0'; | |
| 21 | + const VERSION = '4.0.2'; | |
| 22 | 22 | |
| 23 | 23 | /** |
| 24 | 24 | * WP-CLI command |
| 25 | 25 | * |
| @@ -90,8 +90,15 @@ | ||
| 90 | 90 | */ |
| 91 | 91 | public $locations = array(); |
| 92 | 92 | |
| 93 | 93 | /** |
| 94 | + * IP address for the current request to be associated with the log entry. | |
| 95 | + * | |
| 96 | + * @var null|false|string Valid IP address, null if not set, false if invalid. | |
| 97 | + */ | |
| 98 | + protected $client_ip_address; | |
| 99 | + | |
| 100 | + /** | |
| 94 | 101 | * Class constructor |
| 95 | 102 | */ |
| 96 | 103 | public function __construct() { |
| 97 | 104 | $locate = $this->locate_plugin(); |
| @@ -137,8 +144,11 @@ | ||
| 137 | 144 | |
| 138 | 145 | // Load logger class. |
| 139 | 146 | $this->log = apply_filters( 'wp_stream_log_handler', new Log( $this ) ); |
| 140 | 147 | |
| 148 | + // Set the IP address for the current request. | |
| 149 | + $this->client_ip_address = wp_stream_filter_input( INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP ); | |
| 150 | + | |
| 141 | 151 | // Load settings and connectors after widgets_init and before the default init priority. |
| 142 | 152 | add_action( 'init', array( $this, 'init' ), 9 ); |
| 143 | 153 | |
| 144 | 154 | // Add frontend indicator. |
| @@ -163,12 +173,12 @@ | ||
| 163 | 173 | |
| 164 | 174 | /** |
| 165 | 175 | * Autoloader for classes |
| 166 | 176 | * |
| 167 | - * @param string $class Fully qualified classname to be loaded. | |
| 177 | + * @param string $class_name Fully qualified classname to be loaded. | |
| 168 | 178 | */ |
| 169 | - public function autoload( $class ) { | |
| 170 | - if ( ! preg_match( '/^(?P<namespace>.+)\\\\(?P<autoload>[^\\\\]+)$/', $class, $matches ) ) { | |
| 179 | + public function autoload( $class_name ) { | |
| 180 | + if ( ! preg_match( '/^(?P<namespace>.+)\\\\(?P<autoload>[^\\\\]+)$/', $class_name, $matches ) ) { | |
| 171 | 181 | return; |
| 172 | 182 | } |
| 173 | 183 | |
| 174 | 184 | static $reflection; |
| @@ -208,9 +218,8 @@ | ||
| 208 | 218 | $this->settings = new Settings( $this ); |
| 209 | 219 | $this->connectors = new Connectors( $this ); |
| 210 | 220 | $this->alerts = new Alerts( $this ); |
| 211 | 221 | $this->alerts_list = new Alerts_List( $this ); |
| 212 | - | |
| 213 | 222 | } |
| 214 | 223 | |
| 215 | 224 | /** |
| 216 | 225 | * Displays an HTML comment in the frontend head to indicate that Stream is activated, |
| @@ -232,9 +241,9 @@ | ||
| 232 | 241 | */ |
| 233 | 242 | $comment = apply_filters( 'wp_stream_frontend_indicator', $comment ); |
| 234 | 243 | |
| 235 | 244 | if ( ! empty( $comment ) ) { |
| 236 | - echo sprintf( "<!-- %s -->\n", esc_html( $comment ) ); // xss ok. | |
| 245 | + printf( "<!-- %s -->\n", esc_html( $comment ) ); | |
| 237 | 246 | } |
| 238 | 247 | } |
| 239 | 248 | |
| 240 | 249 | /** |
| @@ -243,10 +252,10 @@ | ||
| 243 | 252 | * |
| 244 | 253 | * @return array |
| 245 | 254 | */ |
| 246 | 255 | private function locate_plugin() { |
| 247 | - $dir_url = trailingslashit( plugins_url( '', dirname( __FILE__ ) ) ); | |
| 248 | - $dir_path = plugin_dir_path( dirname( __FILE__ ) ); | |
| 256 | + $dir_url = trailingslashit( plugins_url( '', __DIR__ ) ); | |
| 257 | + $dir_path = plugin_dir_path( __DIR__ ); | |
| 249 | 258 | $dir_basename = basename( $dir_path ); |
| 250 | 259 | $plugin_basename = trailingslashit( $dir_basename ) . $dir_basename . '.php'; |
| 251 | 260 | |
| 252 | 261 | return compact( 'dir_url', 'dir_path', 'dir_basename', 'plugin_basename' ); |
| @@ -313,6 +322,15 @@ | ||
| 313 | 322 | return true; |
| 314 | 323 | } |
| 315 | 324 | |
| 316 | 325 | return false; |
| 326 | + } | |
| 327 | + | |
| 328 | + /** | |
| 329 | + * Get the IP address for the current request. | |
| 330 | + * | |
| 331 | + * @return false|null|string Valid IP address, null if not set, false if invalid. | |
| 332 | + */ | |
| 333 | + public function get_client_ip_address() { | |
| 334 | + return apply_filters( 'wp_stream_client_ip_address', $this->client_ip_address ); | |
| 317 | 335 | } |
| 318 | 336 | } |