Skip to content

Commit e70f46c

Browse files
authored
Merge branch 'xwp:develop' into meta-field-display
2 parents 3d98893 + 0336294 commit e70f46c

25 files changed

+176
-115
lines changed

.travis.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,6 @@ before_install:
7474
- docker-compose pull
7575
- nvm install
7676
- nvm use
77-
# Lock to Composer version 1 for now.
78-
- composer self-update --1
7977

8078
install:
8179
- npm install

classes/class-admin.php

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,12 @@ public function init() {
220220
$this->network = new Network( $this->plugin );
221221
$this->live_update = new Live_Update( $this->plugin );
222222
$this->export = new Export( $this->plugin );
223+
224+
// Check if the host has configured the `REMOTE_ADDR` correctly.
225+
$client_ip = $this->plugin->get_client_ip_address();
226+
if ( empty( $client_ip ) && $this->is_stream_screen() ) {
227+
$this->notice( __( 'Stream plugin can\'t determine a reliable client IP address! Please update the hosting environment to set the $_SERVER[\'REMOTE_ADDR\'] variable or use the wp_stream_client_ip_address filter to specify the verified client IP address!', 'stream' ) );
228+
}
223229
}
224230

225231
/**
@@ -541,9 +547,10 @@ public function is_stream_screen() {
541547
return true;
542548
}
543549

544-
$screen = get_current_screen();
545-
if ( Alerts::POST_TYPE === $screen->post_type ) {
546-
return true;
550+
if ( is_admin() && function_exists( 'get_current_screen' ) ) {
551+
$screen = get_current_screen();
552+
553+
return ( Alerts::POST_TYPE === $screen->post_type );
547554
}
548555

549556
return false;

classes/class-alert.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ public function update_meta( $meta_key, $meta_value, $prev_value = '' ) {
186186
/**
187187
* Determine the title of the alert.
188188
*
189-
* @todo enhance human readibility
189+
* @todo enhance human readability
190190
* @return string The title of the alert
191191
*/
192192
public function get_title() {
@@ -207,7 +207,7 @@ public function get_title() {
207207
}
208208

209209
/**
210-
* Retreive current alert type object
210+
* Retrieve current alert type object
211211
*
212212
* @return Alert_Type
213213
*/

classes/class-live-update.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -170,7 +170,7 @@ public function gather_updated_items( $last_time, $args = array() ) {
170170
/**
171171
* Handles live updates for Stream Post List
172172
*
173-
* @action heartbeat_recieved
173+
* @action heartbeat_received
174174
*
175175
* @param array $response Response to be sent to heartbeat tick.
176176
* @param array $data Data from heartbeat send.

classes/class-log.php

Lines changed: 4 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -19,14 +19,6 @@ class Log {
1919
*/
2020
public $plugin;
2121

22-
/**
23-
* Hold Current visitors IP Address.
24-
*
25-
* @var string
26-
*/
27-
private $ip_address;
28-
29-
3022
/**
3123
* Previous Stream record ID, used for chaining same-session records
3224
*
@@ -42,12 +34,6 @@ class Log {
4234
public function __construct( $plugin ) {
4335
$this->plugin = $plugin;
4436

45-
// Support proxy mode by checking the `X-Forwarded-For` header first.
46-
$ip_address = wp_stream_filter_input( INPUT_SERVER, 'HTTP_X_FORWARDED_FOR', FILTER_VALIDATE_IP );
47-
$ip_address = $ip_address ? $ip_address : wp_stream_filter_input( INPUT_SERVER, 'REMOTE_ADDR', FILTER_VALIDATE_IP );
48-
49-
$this->ip_address = $ip_address;
50-
5137
// Ensure function used in various methods is pre-loaded.
5238
if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
5339
require_once ABSPATH . '/wp-admin/includes/plugin.php';
@@ -87,9 +73,11 @@ public function log( $connector, $message, $args, $object_id, $context, $action,
8773
return false;
8874
}
8975

76+
$ip_address = $this->plugin->get_client_ip_address();
77+
9078
$user = new \WP_User( $user_id );
9179

92-
if ( $this->is_record_excluded( $connector, $context, $action, $user ) ) {
80+
if ( $this->is_record_excluded( $connector, $context, $action, $user, $ip_address ) ) {
9381
return false;
9482
}
9583

@@ -140,7 +128,7 @@ function ( $var ) {
140128
'connector' => (string) $connector,
141129
'context' => (string) $context,
142130
'action' => (string) $action,
143-
'ip' => (string) $this->ip_address,
131+
'ip' => (string) $ip_address,
144132
'meta' => (array) $stream_meta,
145133
);
146134

@@ -174,12 +162,6 @@ public function is_record_excluded( $connector, $context, $action, $user = null,
174162
$user = wp_get_current_user();
175163
}
176164

177-
if ( is_null( $ip ) ) {
178-
$ip = $this->ip_address;
179-
} else {
180-
$ip = wp_stream_filter_var( $ip, FILTER_VALIDATE_IP );
181-
}
182-
183165
if ( ! empty( $user->roles ) ) {
184166
$roles = array_values( $user->roles );
185167
$role = $roles[0];

classes/class-network.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,13 +351,13 @@ public function get_settings_translations( $labels ) {
351351
* Wrapper for the settings API to work on the network settings page
352352
*/
353353
public function network_options_action() {
354-
$allowed_referers = array(
354+
$allowed_referrers = array(
355355
$this->network_settings_page_slug,
356356
$this->default_settings_page_slug,
357357
);
358358

359359
// @codingStandardsIgnoreLine
360-
if ( ! isset( $_GET['action'] ) || ! in_array( $_GET['action'], $allowed_referers, true ) ) {
360+
if ( ! isset( $_GET['action'] ) || ! in_array( $_GET['action'], $allowed_referrers, true ) ) {
361361
return;
362362
}
363363

classes/class-plugin.php

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class Plugin {
1818
*
1919
* @const string
2020
*/
21-
const VERSION = '3.10.0';
21+
const VERSION = '4.0.0';
2222

2323
/**
2424
* WP-CLI command
@@ -90,6 +90,13 @@ class Plugin {
9090
*/
9191
public $locations = array();
9292

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+
93100
/**
94101
* Class constructor
95102
*/
@@ -138,6 +145,9 @@ public function __construct() {
138145
// Load logger class.
139146
$this->log = apply_filters( 'wp_stream_log_handler', new Log( $this ) );
140147

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+
141151
// Load settings and connectors after widgets_init and before the default init priority.
142152
add_action( 'init', array( $this, 'init' ), 9 );
143153

@@ -315,4 +325,13 @@ public function is_mustuse() {
315325

316326
return false;
317327
}
328+
329+
/**
330+
* Get the IP address for the current request.
331+
*
332+
* @return false|null|string Valid IP address, null if not set, false if invalid.
333+
*/
334+
public function get_client_ip_address() {
335+
return apply_filters( 'wp_stream_client_ip_address', $this->client_ip_address );
336+
}
318337
}

connectors/class-connector-posts.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public function action_links( $links, $record ) {
110110
/* translators: %s: a post type singular name (e.g. "Post") */
111111
$links[ sprintf( esc_html_x( 'Restore %s', 'Post type singular name', 'stream' ), $post_type_name ) ] = $untrash;
112112
/* translators: %s: a post type singular name (e.g. "Post") */
113-
$links[ sprintf( esc_html_x( 'Delete %s Permenantly', 'Post type singular name', 'stream' ), $post_type_name ) ] = $delete;
113+
$links[ sprintf( esc_html_x( 'Delete %s Permanently', 'Post type singular name', 'stream' ), $post_type_name ) ] = $delete;
114114
} else {
115115
/* translators: %s a post type singular name (e.g. "Post") */
116116
$links[ sprintf( esc_html_x( 'Edit %s', 'Post type singular name', 'stream' ), $post_type_name ) ] = get_edit_post_link( $post->ID );

connectors/class-connector-settings.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,7 @@ public function get_serialized_field_label( $option_name, $field_key ) {
459459
/**
460460
* Filter allows for insertion of serialized labels
461461
*
462-
* @param array $lables Serialized labels
462+
* @param array $labels Serialized labels
463463
* @return array Updated array of serialzed labels
464464
*/
465465
$labels = apply_filters( 'wp_stream_serialized_labels', $labels );

connectors/class-connector-taxonomies.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ public function action_links( $links, $record ) {
124124
}
125125

126126
/**
127-
* Catch registration of taxonomies after inital loading, so we can cache its labels
127+
* Catch registration of taxonomies after initial loading, so we can cache its labels
128128
*
129129
* @action registered_taxonomy
130130
*

0 commit comments

Comments
 (0)