PluginProbe
Stream – Activity Log & Audit Trail / 3.9.2
Stream – Activity Log & Audit Trail v3.9.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 +64 -55 3.2.33.9.2 View file →
@@ -1,32 +1,58 @@
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 +
2 9 namespace WP_Stream;
3 10
11 +/**
12 + * Class - Network
13 + */
4 14 class Network {
5 15 /**
6 - * Hold Plugin class
16 + * Holds instance of plugin object
17 + *
7 18 * @var Plugin
8 19 */
9 20 public $plugin;
10 21
22 + /**
23 + * Network page slug
24 + *
25 + * @var string
26 + */
11 27 public $network_settings_page_slug = 'wp_stream_network_settings';
12 28
29 + /**
30 + * Default setting page slug
31 + *
32 + * @var string
33 + */
13 34 public $default_settings_page_slug = 'wp_stream_default_settings';
14 35
36 + /**
37 + * Class constructor
38 + *
39 + * @param Plugin $plugin Instance of plugin object.
40 + */
15 41 public function __construct( $plugin ) {
16 42 $this->plugin = $plugin;
17 43
18 - // Always add default site_id/blog_id params when multisite
44 + // Always add default site_id/blog_id params when multisite.
19 45 if ( is_multisite() ) {
20 46 add_filter( 'wp_stream_query_args', array( $this, 'network_query_args' ) );
21 47 }
22 48
23 - // Bail early if not network-activated
49 + // Bail early if not network-activated.
24 50 if ( ! $this->is_network_activated() ) {
25 51 return;
26 52 }
27 53
28 - // Actions
54 + // Actions.
29 55 add_action( 'init', array( $this, 'ajax_network_admin' ) );
30 56 add_action( 'network_admin_menu', array( $this->plugin->admin, 'register_menu' ) );
31 57 add_action( 'network_admin_menu', array( $this, 'admin_menu_screens' ) );
32 58 add_action( 'admin_menu', array( $this, 'admin_menu_screens' ) );
@@ -34,9 +60,9 @@
34 60 add_action( 'network_admin_notices', array( $this->plugin->admin, 'admin_notices' ) );
35 61 add_action( 'wpmuadminedit', array( $this, 'network_options_action' ) );
36 62 add_action( 'update_site_option_' . $this->plugin->settings->network_options_key, array( $this, 'updated_option_ttl_remove_records' ), 10, 3 );
37 63
38 - // Filters
64 + // Filters.
39 65 add_filter( 'wp_stream_blog_id_logged', array( $this, 'blog_id_logged' ) );
40 66 add_filter( 'wp_stream_admin_page_title', array( $this, 'network_admin_page_title' ) );
41 67 add_filter( 'wp_stream_list_table_screen_id', array( $this, 'list_table_screen_id' ) );
42 68 add_filter( 'wp_stream_list_table_filters', array( $this, 'list_table_filters' ) );
@@ -90,42 +116,18 @@
90 116 *
91 117 * @return bool
92 118 */
93 119 public function is_network_activated() {
94 - if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
95 - require_once ABSPATH . '/wp-admin/includes/plugin.php';
96 - }
97 -
98 - if ( $this->is_mustuse() ) {
99 - return true;
100 - }
101 -
102 - return is_plugin_active_for_network( $this->plugin->locations['plugin'] );
120 + return $this->plugin->is_network_activated();
103 121 }
104 122
105 123 /**
106 - * Returns true if Stream is a must-use plugin, otherwise false
107 - *
108 - * @return bool
109 - */
110 - public function is_mustuse() {
111 -
112 - $stream_php = trailingslashit( WPMU_PLUGIN_DIR ) . $this->plugin->locations['plugin'];
113 -
114 - if ( file_exists( $stream_php ) && class_exists( 'WP_Stream\Plugin' ) ) {
115 - return true;
116 - }
117 -
118 - return false;
119 - }
120 -
121 - /**
122 124 * Adds Stream to the admin bar under the "My Sites > Network Admin" menu
123 125 * if Stream has been network-activated.
124 126 *
125 127 * @action admin_bar_menu
126 128 *
127 - * @param object $admin_bar
129 + * @param object $admin_bar Admin bar object.
128 130 *
129 131 * @return void
130 132 */
131 133 public function network_admin_bar_menu( $admin_bar ) {
@@ -150,9 +152,9 @@
150 152 );
151 153 }
152 154
153 155 /**
154 - * Add Network Settings and Default Settings menu items
156 + * Add Network Settings and Default Settings menu pages
155 157 *
156 158 * @return array
157 159 */
158 160 public function admin_menu_screens() {
@@ -175,11 +177,11 @@
175 177
176 178 /**
177 179 * Remove records when records TTL is shortened
178 180 *
179 - * @param string $option_key
180 - * @param array $old_value
181 - * @param array $new_value
181 + * @param string $option_key Unused.
182 + * @param array $new_value New value.
183 + * @param array $old_value Old value.
182 184 *
183 185 * @action update_option_wp_stream
184 186 * @return void
185 187 */
@@ -190,9 +192,9 @@
190 192
191 193 /**
192 194 * Adjust the action of the settings form when in the Network Admin
193 195 *
194 - * @param $action
196 + * @param string $action Query string.
195 197 *
196 198 * @return string
197 199 */
198 200 public function settings_form_action( $action ) {
@@ -200,9 +202,10 @@
200 202 $current_page = wp_stream_filter_input( INPUT_GET, 'page' );
201 203 $action = add_query_arg(
202 204 array(
203 205 'action' => $current_page,
204 - ), 'edit.php'
206 + ),
207 + 'edit.php'
205 208 );
206 209 }
207 210
208 211 return $action;
@@ -210,9 +213,9 @@
210 213
211 214 /**
212 215 * Add a description to each of the Settings pages in the Network Admin
213 216 *
214 - * @param $description
217 + * @param string $description Description of the current page.
215 218 *
216 219 * @return string
217 220 */
218 221 public function settings_form_description( $description ) {
@@ -236,9 +239,9 @@
236 239
237 240 /**
238 241 * Adjusts the settings fields displayed in various network admin screens
239 242 *
240 - * @param $fields
243 + * @param array $fields Page settings fields.
241 244 *
242 245 * @return mixed
243 246 */
244 247 public function get_network_admin_fields( $fields ) {
@@ -275,9 +278,9 @@
275 278 ),
276 279 )
277 280 );
278 281
279 - // Remove settings based on context
282 + // Remove settings based on context.
280 283 if ( $this->plugin->settings->network_options_key === $this->plugin->settings->option_key ) {
281 284 $hidden_options = $network_hidden_options;
282 285 } else {
283 286 $hidden_options = $stream_hidden_options;
@@ -294,9 +297,9 @@
294 297 }
295 298 }
296 299 }
297 300
298 - // Add settings based on context
301 + // Add settings based on context.
299 302 if ( $this->plugin->settings->network_options_key === $this->plugin->settings->option_key ) {
300 303 $new_fields['general']['fields'][] = array(
301 304 'name' => 'site_access',
302 305 'title' => __( 'Site Access', 'stream' ),
@@ -308,9 +311,9 @@
308 311
309 312 $fields = array_merge_recursive( $new_fields, $fields );
310 313 }
311 314
312 - // Remove empty settings sections
315 + // Remove empty settings sections.
313 316 foreach ( $fields as $section_key => $section ) {
314 317 if ( empty( $section['fields'] ) ) {
315 318 unset( $fields[ $section_key ] );
316 319 }
@@ -323,8 +326,10 @@
323 326 * Get translations of serialized Stream Network settings
324 327 *
325 328 * @filter wp_stream_serialized_labels
326 329 *
330 + * @param array $labels Setting labels.
331 + *
327 332 * @return array Multidimensional array of fields
328 333 */
329 334 public function get_settings_translations( $labels ) {
330 335 $network_key = $this->plugin->settings->network_options_key;
@@ -350,13 +355,15 @@
350 355 $this->network_settings_page_slug,
351 356 $this->default_settings_page_slug,
352 357 );
353 358
354 - if ( ! isset( $_GET['action'] ) || ! in_array( $_GET['action'], $allowed_referers, true ) ) { // CSRF okay
359 + // @codingStandardsIgnoreLine
360 + if ( ! isset( $_GET['action'] ) || ! in_array( $_GET['action'], $allowed_referers, true ) ) {
355 361 return;
356 362 }
357 363
358 - $options = isset( $_POST['option_page'] ) ? explode( ',', stripslashes( $_POST['option_page'] ) ) : null; // CSRF okay
364 + // @codingStandardsIgnoreLine
365 + $options = isset( $_POST['option_page'] ) ? explode( ',', stripslashes( $_POST['option_page'] ) ) : null;
359 366
360 367 if ( $options ) {
361 368
362 369 foreach ( $options as $option ) {
@@ -393,9 +400,9 @@
393 400 set_transient( 'settings_errors', get_settings_errors(), 30 );
394 401
395 402 $go_back = add_query_arg( 'settings-updated', 'true', wp_get_referer() );
396 403
397 - wp_redirect( $go_back );
404 + wp_safe_redirect( $go_back );
398 405
399 406 exit;
400 407 }
401 408
@@ -403,9 +410,9 @@
403 410 * Add the Site filter to the Network records screen
404 411 *
405 412 * @filter wp_stream_list_table_filters
406 413 *
407 - * @param $filters
414 + * @param array $filters Filters.
408 415 *
409 416 * @return array
410 417 */
411 418 public function list_table_filters( $filters ) {
@@ -414,9 +421,9 @@
414 421 }
415 422
416 423 $blogs = array();
417 424
418 - // Display network blog as the first option
425 + // Display network blog as the first option.
419 426 $network_blog = $this->get_network_blog();
420 427
421 428 $blogs[ $network_blog->blog_id ] = array(
422 429 'label' => $network_blog->blogname,
@@ -422,9 +429,9 @@
422 429 'label' => $network_blog->blogname,
423 430 'disabled' => '',
424 431 );
425 432
426 - // add all sites
433 + // Add all sites.
427 434 foreach ( wp_stream_get_sites() as $blog ) {
428 435 $blog_data = get_blog_details( $blog->blog_id );
429 436
430 437 $blogs[ $blog->blog_id ] = array(
@@ -443,9 +450,9 @@
443 450
444 451 /**
445 452 * Add the Site toggle to screen options in network admin
446 453 *
447 - * @param $filters
454 + * @param array $filters Filters.
448 455 *
449 456 * @return array
450 457 */
451 458 public function toggle_filters( $filters ) {
@@ -458,9 +465,9 @@
458 465
459 466 /**
460 467 * Add the network suffix to the $screen_id when in the network admin
461 468 *
462 - * @param $screen_id
469 + * @param int $screen_id Screen ID.
463 470 *
464 471 * @return string
465 472 */
466 473 public function list_table_screen_id( $screen_id ) {
@@ -475,8 +482,10 @@
475 482
476 483 /**
477 484 * Set blog_id for network admin activity
478 485 *
486 + * @param int $blog_id Blog ID.
487 + *
479 488 * @return int
480 489 */
481 490 public function blog_id_logged( $blog_id ) {
482 491 return is_network_admin() ? 0 : $blog_id;
@@ -486,9 +495,9 @@
486 495 * Customize query args on multisite installs
487 496 *
488 497 * @filter wp_stream_query_args
489 498 *
490 - * @param array $args
499 + * @param array $args Site arguments.
491 500 *
492 501 * @return array
493 502 */
494 503 public function network_query_args( $args ) {
@@ -502,15 +511,15 @@
502 511 * Add site count to the page title in the network admin
503 512 *
504 513 * @filter wp_stream_admin_page_title
505 514 *
506 - * @param string $page_title
515 + * @param string $page_title Page title.
507 516 *
508 517 * @return string
509 518 */
510 519 public function network_admin_page_title( $page_title ) {
511 520 if ( is_network_admin() ) {
512 - // translators: Placeholder refers to a number of sites on the network (e.g. "42")
521 + /* translators: %d: number of sites on the network (e.g. "42") */
513 522 $site_count = sprintf( _n( '%d site', '%d sites', get_blog_count(), 'stream' ), number_format( get_blog_count() ) );
514 523 $page_title = sprintf( '%s (%s)', $page_title, $site_count );
515 524 }
516 525
@@ -519,9 +528,9 @@
519 528
520 529 /**
521 530 * Add the Site column to the network stream records
522 531 *
523 - * @param $columns
532 + * @param array $columns Columns data.
524 533 *
525 534 * @return mixed
526 535 */
527 536 public function network_admin_columns( $columns ) {
@@ -540,9 +549,9 @@
540 549
541 550 /**
542 551 * Prevent the Blogs connector from loading when not in Network Admin
543 552 *
544 - * @param $connectors
553 + * @param array $connectors Connectors.
545 554 *
546 555 * @return mixed
547 556 */
548 557 public function hide_blogs_connector( $connectors ) {