PluginProbe
Stream – Activity Log & Audit Trail / 3.4.2
Stream – Activity Log & Audit Trail v3.4.2
4.4.0 4.3.0 4.2.2 4.2.1 trunk 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.0.5 3.0.6 3.0.7 3.1 3.1.1 3.10.0 3.2.0 3.2.1 3.2.2 3.2.3 All 50 releases
← All changes | classes/class-network.php +63 -93 4.2.23.4.2 View file →
@@ -1,58 +1,33 @@
1 1 <?php
2 -/**
3 - * Manages functionality for the Stream Admin pages on both
4 - * single and multi-sites.
5 - *
6 - * @package WP_Stream
7 - */
8 -
9 2 namespace WP_Stream;
10 3
11 -/**
12 - * Class - Network
13 - */
14 4 class Network {
15 5 /**
16 - * Holds instance of plugin object
6 + * Hold Plugin class
17 7 *
18 8 * @var Plugin
19 9 */
20 10 public $plugin;
21 11
22 - /**
23 - * Network page slug
24 - *
25 - * @var string
26 - */
27 12 public $network_settings_page_slug = 'wp_stream_network_settings';
28 13
29 - /**
30 - * The option name for the network settings.
31 - *
32 - * @var string
33 - */
34 - public $network_settings_option = 'wp_stream_network';
14 + public $default_settings_page_slug = 'wp_stream_default_settings';
35 15
36 - /**
37 - * Class constructor
38 - *
39 - * @param Plugin $plugin Instance of plugin object.
40 - */
41 16 public function __construct( $plugin ) {
42 17 $this->plugin = $plugin;
43 18
44 - // Always add default site_id/blog_id params when multisite.
19 + // Always add default site_id/blog_id params when multisite
45 20 if ( is_multisite() ) {
46 21 add_filter( 'wp_stream_query_args', array( $this, 'network_query_args' ) );
47 22 }
48 23
49 - // Bail early if not network-activated.
24 + // Bail early if not network-activated
50 25 if ( ! $this->is_network_activated() ) {
51 26 return;
52 27 }
53 28
54 - // Actions.
29 + // Actions
55 30 add_action( 'init', array( $this, 'ajax_network_admin' ) );
56 31 add_action( 'network_admin_menu', array( $this->plugin->admin, 'register_menu' ) );
57 32 add_action( 'network_admin_menu', array( $this, 'admin_menu_screens' ) );
58 33 add_action( 'admin_menu', array( $this, 'admin_menu_screens' ) );
@@ -60,9 +35,9 @@
60 35 add_action( 'network_admin_notices', array( $this->plugin->admin, 'admin_notices' ) );
61 36 add_action( 'wpmuadminedit', array( $this, 'network_options_action' ) );
62 37 add_action( 'update_site_option_' . $this->plugin->settings->network_options_key, array( $this, 'updated_option_ttl_remove_records' ), 10, 3 );
63 38
64 - // Filters.
39 + // Filters
65 40 add_filter( 'wp_stream_blog_id_logged', array( $this, 'blog_id_logged' ) );
66 41 add_filter( 'wp_stream_admin_page_title', array( $this, 'network_admin_page_title' ) );
67 42 add_filter( 'wp_stream_list_table_screen_id', array( $this, 'list_table_screen_id' ) );
68 43 add_filter( 'wp_stream_list_table_filters', array( $this, 'list_table_filters' ) );
@@ -83,16 +58,14 @@
83 58 *
84 59 * @see https://core.trac.wordpress.org/ticket/22589
85 60 */
86 61 public function ajax_network_admin() {
87 - $http_referer = isset( $_SERVER['HTTP_REFERER'] ) ? esc_url_raw( wp_unslash( $_SERVER['HTTP_REFERER'] ) ) : '';
88 -
89 62 if (
90 63 defined( 'DOING_AJAX' )
91 64 &&
92 65 DOING_AJAX
93 66 &&
94 - 0 === stripos( $http_referer, network_admin_url() )
67 + preg_match( '#^' . network_admin_url() . '#i', $_SERVER['HTTP_REFERER'] )
95 68 ) {
96 69 define( 'WP_NETWORK_ADMIN', true );
97 70 return WP_NETWORK_ADMIN;
98 71 }
@@ -127,9 +100,9 @@
127 100 * if Stream has been network-activated.
128 101 *
129 102 * @action admin_bar_menu
130 103 *
131 - * @param object $admin_bar Admin bar object.
104 + * @param object $admin_bar
132 105 *
133 106 * @return void
134 107 */
135 108 public function network_admin_bar_menu( $admin_bar ) {
@@ -154,9 +127,9 @@
154 127 );
155 128 }
156 129
157 130 /**
158 - * Add Network Settings and Default Settings menu pages
131 + * Add Network Settings and Default Settings menu items
159 132 *
160 133 * @return array
161 134 */
162 135 public function admin_menu_screens() {
@@ -179,11 +152,11 @@
179 152
180 153 /**
181 154 * Remove records when records TTL is shortened
182 155 *
183 - * @param string $option_key Unused.
184 - * @param array $new_value New value.
185 - * @param array $old_value Old value.
156 + * @param string $option_key
157 + * @param array $old_value
158 + * @param array $new_value
186 159 *
187 160 * @action update_option_wp_stream
188 161 * @return void
189 162 */
@@ -194,9 +167,9 @@
194 167
195 168 /**
196 169 * Adjust the action of the settings form when in the Network Admin
197 170 *
198 - * @param string $action Query string.
171 + * @param $action
199 172 *
200 173 * @return string
201 174 */
202 175 public function settings_form_action( $action ) {
@@ -215,9 +188,9 @@
215 188
216 189 /**
217 190 * Add a description to each of the Settings pages in the Network Admin
218 191 *
219 - * @param string $description Description of the current page.
192 + * @param $description
220 193 *
221 194 * @return string
222 195 */
223 196 public function settings_form_description( $description ) {
@@ -226,10 +199,15 @@
226 199 }
227 200
228 201 $current_page = wp_stream_filter_input( INPUT_GET, 'page' );
229 202
230 - if ( $this->network_settings_page_slug === $current_page ) {
231 - $description = __( 'These settings apply to all sites on the network.', 'stream' );
203 + switch ( $current_page ) {
204 + case $this->network_settings_page_slug:
205 + $description = __( 'These settings apply to all sites on the network.', 'stream' );
206 + break;
207 + case $this->default_settings_page_slug:
208 + $description = __( 'These default settings will apply to new sites created on the network. These settings do not alter existing sites.', 'stream' );
209 + break;
232 210 }
233 211
234 212 return $description;
235 213 }
@@ -236,9 +214,9 @@
236 214
237 215 /**
238 216 * Adjusts the settings fields displayed in various network admin screens
239 217 *
240 - * @param array $fields Page settings fields.
218 + * @param $fields
241 219 *
242 220 * @return mixed
243 221 */
244 222 public function get_network_admin_fields( $fields ) {
@@ -275,9 +253,9 @@
275 253 ),
276 254 )
277 255 );
278 256
279 - // Remove settings based on context.
257 + // Remove settings based on context
280 258 if ( $this->plugin->settings->network_options_key === $this->plugin->settings->option_key ) {
281 259 $hidden_options = $network_hidden_options;
282 260 } else {
283 261 $hidden_options = $stream_hidden_options;
@@ -294,9 +272,9 @@
294 272 }
295 273 }
296 274 }
297 275
298 - // Add settings based on context.
276 + // Add settings based on context
299 277 if ( $this->plugin->settings->network_options_key === $this->plugin->settings->option_key ) {
300 278 $new_fields['general']['fields'][] = array(
301 279 'name' => 'site_access',
302 280 'title' => __( 'Site Access', 'stream' ),
@@ -308,9 +286,9 @@
308 286
309 287 $fields = array_merge_recursive( $new_fields, $fields );
310 288 }
311 289
312 - // Remove empty settings sections.
290 + // Remove empty settings sections
313 291 foreach ( $fields as $section_key => $section ) {
314 292 if ( empty( $section['fields'] ) ) {
315 293 unset( $fields[ $section_key ] );
316 294 }
@@ -323,10 +301,8 @@
323 301 * Get translations of serialized Stream Network settings
324 302 *
325 303 * @filter wp_stream_serialized_labels
326 304 *
327 - * @param array $labels Setting labels.
328 - *
329 305 * @return array Multidimensional array of fields
330 306 */
331 307 public function get_settings_translations( $labels ) {
332 308 $network_key = $this->plugin->settings->network_options_key;
@@ -347,50 +323,46 @@
347 323 /**
348 324 * Wrapper for the settings API to work on the network settings page
349 325 */
350 326 public function network_options_action() {
327 + $allowed_referers = array(
328 + $this->network_settings_page_slug,
329 + $this->default_settings_page_slug,
330 + );
351 331
352 - // Check the nonce.
353 - if (
354 - empty( $_POST['_wpnonce'] )
355 - ||
356 - ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['_wpnonce'] ) ), sprintf( '%s-options', $this->network_settings_option ) )
357 - ) {
332 + if ( ! isset( $_GET['action'] ) || ! in_array( $_GET['action'], $allowed_referers, true ) ) { // CSRF okay
358 333 return;
359 334 }
360 335
361 - // Check the user capability.
362 - if ( ! current_user_can( $this->plugin->admin->settings_cap ) ) {
363 - return;
364 - }
336 + $options = isset( $_POST['option_page'] ) ? explode( ',', stripslashes( $_POST['option_page'] ) ) : null; // CSRF okay
365 337
366 - // Check the action.
367 - $action = isset( $_GET['action'] ) ? sanitize_key( wp_unslash( $_GET['action'] ) ) : '';
368 - if ( $this->network_settings_page_slug !== $action ) {
369 - return;
370 - }
338 + if ( $options ) {
371 339
372 - $option = ! empty( $_POST['option_page'] ) ? sanitize_key( wp_unslash( $_POST['option_page'] ) ) : false;
340 + foreach ( $options as $option ) {
341 + $option = trim( $option );
342 + $value = null;
343 + $sections = $this->plugin->settings->get_fields();
373 344
374 - if ( $option && $this->network_settings_option === $option ) {
345 + foreach ( $sections as $section_name => $section ) {
346 + foreach ( $section['fields'] as $field_idx => $field ) {
347 + $option_key = $section_name . '_' . $field['name'];
375 348
376 - $value = array();
377 - $posted_options = isset( $_POST[ $option ] ) && is_array( $_POST[ $option ] ) ? wp_unslash( $_POST[ $option ] ) : array();
378 - $sections = $this->plugin->settings->get_fields();
349 + // @codingStandardsIgnoreStart
350 + if ( isset( $_POST[ $option ][ $option_key ] ) ) {
351 + $value[ $option_key ] = $_POST[ $option ][ $option_key ];
352 + } else {
353 + $value[ $option_key ] = false;
354 + }
355 + // @codingStandardsIgnoreEnd
356 + }
357 + }
379 358
380 - foreach ( $sections as $section_name => $section ) {
381 - foreach ( $section['fields'] as $field_idx => $field ) {
382 - $option_key = $section_name . '_' . $field['name'];
359 + if ( ! is_array( $value ) ) {
360 + $value = trim( $value );
361 + }
383 362
384 - if ( isset( $posted_options[ $option_key ] ) ) {
385 - $value[ $option_key ] = $this->plugin->settings->sanitize_setting_by_field_type( $posted_options[ $option_key ], $field['type'] );
386 - } else {
387 - $value[ $option_key ] = false;
388 - }
389 - }
363 + update_site_option( $option, $value );
390 364 }
391 -
392 - update_site_option( $this->network_settings_option, $value );
393 365 }
394 366
395 367 if ( ! count( get_settings_errors() ) ) {
396 368 add_settings_error( 'general', 'settings_updated', __( 'Settings saved.', 'stream' ), 'updated' );
@@ -399,9 +371,9 @@
399 371 set_transient( 'settings_errors', get_settings_errors(), 30 );
400 372
401 373 $go_back = add_query_arg( 'settings-updated', 'true', wp_get_referer() );
402 374
403 - wp_safe_redirect( $go_back );
375 + wp_redirect( $go_back );
404 376
405 377 exit;
406 378 }
407 379
@@ -409,9 +381,9 @@
409 381 * Add the Site filter to the Network records screen
410 382 *
411 383 * @filter wp_stream_list_table_filters
412 384 *
413 - * @param array $filters Filters.
385 + * @param $filters
414 386 *
415 387 * @return array
416 388 */
417 389 public function list_table_filters( $filters ) {
@@ -420,9 +392,9 @@
420 392 }
421 393
422 394 $blogs = array();
423 395
424 - // Display network blog as the first option.
396 + // Display network blog as the first option
425 397 $network_blog = $this->get_network_blog();
426 398
427 399 $blogs[ $network_blog->blog_id ] = array(
428 400 'label' => $network_blog->blogname,
@@ -428,9 +400,9 @@
428 400 'label' => $network_blog->blogname,
429 401 'disabled' => '',
430 402 );
431 403
432 - // Add all sites.
404 + // add all sites
433 405 foreach ( wp_stream_get_sites() as $blog ) {
434 406 $blog_data = get_blog_details( $blog->blog_id );
435 407
436 408 $blogs[ $blog->blog_id ] = array(
@@ -449,9 +421,9 @@
449 421
450 422 /**
451 423 * Add the Site toggle to screen options in network admin
452 424 *
453 - * @param array $filters Filters.
425 + * @param $filters
454 426 *
455 427 * @return array
456 428 */
457 429 public function toggle_filters( $filters ) {
@@ -464,9 +436,9 @@
464 436
465 437 /**
466 438 * Add the network suffix to the $screen_id when in the network admin
467 439 *
468 - * @param int $screen_id Screen ID.
440 + * @param $screen_id
469 441 *
470 442 * @return string
471 443 */
472 444 public function list_table_screen_id( $screen_id ) {
@@ -481,10 +453,8 @@
481 453
482 454 /**
483 455 * Set blog_id for network admin activity
484 456 *
485 - * @param int $blog_id Blog ID.
486 - *
487 457 * @return int
488 458 */
489 459 public function blog_id_logged( $blog_id ) {
490 460 return is_network_admin() ? 0 : $blog_id;
@@ -494,9 +464,9 @@
494 464 * Customize query args on multisite installs
495 465 *
496 466 * @filter wp_stream_query_args
497 467 *
498 - * @param array $args Site arguments.
468 + * @param array $args
499 469 *
500 470 * @return array
501 471 */
502 472 public function network_query_args( $args ) {
@@ -510,15 +480,15 @@
510 480 * Add site count to the page title in the network admin
511 481 *
512 482 * @filter wp_stream_admin_page_title
513 483 *
514 - * @param string $page_title Page title.
484 + * @param string $page_title
515 485 *
516 486 * @return string
517 487 */
518 488 public function network_admin_page_title( $page_title ) {
519 489 if ( is_network_admin() ) {
520 - /* translators: %d: number of sites on the network (e.g. "42") */
490 + // translators: Placeholder refers to a number of sites on the network (e.g. "42")
521 491 $site_count = sprintf( _n( '%d site', '%d sites', get_blog_count(), 'stream' ), number_format( get_blog_count() ) );
522 492 $page_title = sprintf( '%s (%s)', $page_title, $site_count );
523 493 }
524 494
@@ -527,9 +497,9 @@
527 497
528 498 /**
529 499 * Add the Site column to the network stream records
530 500 *
531 - * @param array $columns Columns data.
501 + * @param $columns
532 502 *
533 503 * @return mixed
534 504 */
535 505 public function network_admin_columns( $columns ) {
@@ -548,9 +518,9 @@
548 518
549 519 /**
550 520 * Prevent the Blogs connector from loading when not in Network Admin
551 521 *
552 - * @param array $connectors Connectors.
522 + * @param $connectors
553 523 *
554 524 * @return mixed
555 525 */
556 526 public function hide_blogs_connector( $connectors ) {