PluginProbe
Stream – Activity Log & Audit Trail / 3.9.0
Stream – Activity Log & Audit Trail v3.9.0
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 +78 -40 3.1.13.9.0 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
15 - function __construct( $plugin ) {
36 + /**
37 + * Class constructor
38 + *
39 + * @param Plugin $plugin Instance of plugin object.
40 + */
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' ) );
@@ -50,8 +76,10 @@
50 76
51 77 /**
52 78 * Workaround to get admin-ajax.php to know when the request is from the Network Admin
53 79 *
80 + * @return bool
81 + *
54 82 * @action init
55 83 *
56 84 * @see https://core.trac.wordpress.org/ticket/22589
57 85 */
@@ -63,9 +91,12 @@
63 91 &&
64 92 preg_match( '#^' . network_admin_url() . '#i', $_SERVER['HTTP_REFERER'] )
65 93 ) {
66 94 define( 'WP_NETWORK_ADMIN', true );
95 + return WP_NETWORK_ADMIN;
67 96 }
97 +
98 + return false;
68 99 }
69 100
70 101 /**
71 102 * Builds a stdClass object used when displaying actions done in network administration
@@ -72,9 +103,9 @@
72 103 *
73 104 * @return object
74 105 */
75 106 public function get_network_blog() {
76 - $blog = new \stdClass;
107 + $blog = new \stdClass();
77 108 $blog->blog_id = 0;
78 109 $blog->blogname = esc_html__( 'Network Admin', 'stream' );
79 110
80 111 return $blog;
@@ -85,13 +116,9 @@
85 116 *
86 117 * @return bool
87 118 */
88 119 public function is_network_activated() {
89 - if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
90 - require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
91 - }
92 -
93 - return is_plugin_active_for_network( $this->plugin->locations['plugin'] );
120 + return $this->plugin->is_network_activated();
94 121 }
95 122
96 123 /**
97 124 * Adds Stream to the admin bar under the "My Sites > Network Admin" menu
@@ -98,9 +125,9 @@
98 125 * if Stream has been network-activated.
99 126 *
100 127 * @action admin_bar_menu
101 128 *
102 - * @param object $admin_bar
129 + * @param object $admin_bar Admin bar object.
103 130 *
104 131 * @return void
105 132 */
106 133 public function network_admin_bar_menu( $admin_bar ) {
@@ -125,9 +152,9 @@
125 152 );
126 153 }
127 154
128 155 /**
129 - * Add Network Settings and Default Settings menu items
156 + * Add Network Settings and Default Settings menu pages
130 157 *
131 158 * @return array
132 159 */
133 160 public function admin_menu_screens() {
@@ -135,8 +162,9 @@
135 162 return;
136 163 }
137 164
138 165 remove_submenu_page( $this->plugin->admin->records_page_slug, 'wp_stream_settings' );
166 + remove_submenu_page( $this->plugin->admin->records_page_slug, 'edit.php?post_type=wp_stream_alerts' );
139 167
140 168 $this->plugin->admin->screen_id['network_settings'] = add_submenu_page(
141 169 $this->plugin->admin->records_page_slug,
142 170 __( 'Stream Network Settings', 'stream' ),
@@ -149,11 +177,11 @@
149 177
150 178 /**
151 179 * Remove records when records TTL is shortened
152 180 *
153 - * @param string $option_key
154 - * @param array $old_value
155 - * @param array $new_value
181 + * @param string $option_key Unused.
182 + * @param array $new_value New value.
183 + * @param array $old_value Old value.
156 184 *
157 185 * @action update_option_wp_stream
158 186 * @return void
159 187 */
@@ -164,9 +192,9 @@
164 192
165 193 /**
166 194 * Adjust the action of the settings form when in the Network Admin
167 195 *
168 - * @param $action
196 + * @param string $action Query string.
169 197 *
170 198 * @return string
171 199 */
172 200 public function settings_form_action( $action ) {
@@ -171,9 +199,14 @@
171 199 */
172 200 public function settings_form_action( $action ) {
173 201 if ( is_network_admin() ) {
174 202 $current_page = wp_stream_filter_input( INPUT_GET, 'page' );
175 - $action = add_query_arg( array( 'action' => $current_page ), 'edit.php' );
203 + $action = add_query_arg(
204 + array(
205 + 'action' => $current_page,
206 + ),
207 + 'edit.php'
208 + );
176 209 }
177 210
178 211 return $action;
179 212 }
@@ -180,9 +213,9 @@
180 213
181 214 /**
182 215 * Add a description to each of the Settings pages in the Network Admin
183 216 *
184 - * @param $description
217 + * @param string $description Description of the current page.
185 218 *
186 219 * @return string
187 220 */
188 221 public function settings_form_description( $description ) {
@@ -192,12 +225,12 @@
192 225
193 226 $current_page = wp_stream_filter_input( INPUT_GET, 'page' );
194 227
195 228 switch ( $current_page ) {
196 - case $this->network_settings_page_slug :
229 + case $this->network_settings_page_slug:
197 230 $description = __( 'These settings apply to all sites on the network.', 'stream' );
198 231 break;
199 - case $this->default_settings_page_slug :
232 + case $this->default_settings_page_slug:
200 233 $description = __( 'These default settings will apply to new sites created on the network. These settings do not alter existing sites.', 'stream' );
201 234 break;
202 235 }
203 236
@@ -206,9 +239,9 @@
206 239
207 240 /**
208 241 * Adjusts the settings fields displayed in various network admin screens
209 242 *
210 - * @param $fields
243 + * @param array $fields Page settings fields.
211 244 *
212 245 * @return mixed
213 246 */
214 247 public function get_network_admin_fields( $fields ) {
@@ -218,9 +251,9 @@
218 251
219 252 $stream_hidden_options = apply_filters(
220 253 'wp_stream_hidden_option_fields',
221 254 array(
222 - 'general' => array(
255 + 'general' => array(
223 256 'records_ttl',
224 257 ),
225 258 'advanced' => array(
226 259 'delete_all_records',
@@ -245,9 +278,9 @@
245 278 ),
246 279 )
247 280 );
248 281
249 - // Remove settings based on context
282 + // Remove settings based on context.
250 283 if ( $this->plugin->settings->network_options_key === $this->plugin->settings->option_key ) {
251 284 $hidden_options = $network_hidden_options;
252 285 } else {
253 286 $hidden_options = $stream_hidden_options;
@@ -264,9 +297,9 @@
264 297 }
265 298 }
266 299 }
267 300
268 - // Add settings based on context
301 + // Add settings based on context.
269 302 if ( $this->plugin->settings->network_options_key === $this->plugin->settings->option_key ) {
270 303 $new_fields['general']['fields'][] = array(
271 304 'name' => 'site_access',
272 305 'title' => __( 'Site Access', 'stream' ),
@@ -278,9 +311,9 @@
278 311
279 312 $fields = array_merge_recursive( $new_fields, $fields );
280 313 }
281 314
282 - // Remove empty settings sections
315 + // Remove empty settings sections.
283 316 foreach ( $fields as $section_key => $section ) {
284 317 if ( empty( $section['fields'] ) ) {
285 318 unset( $fields[ $section_key ] );
286 319 }
@@ -293,8 +326,10 @@
293 326 * Get translations of serialized Stream Network settings
294 327 *
295 328 * @filter wp_stream_serialized_labels
296 329 *
330 + * @param array $labels Setting labels.
331 + *
297 332 * @return array Multidimensional array of fields
298 333 */
299 334 public function get_settings_translations( $labels ) {
300 335 $network_key = $this->plugin->settings->network_options_key;
@@ -320,15 +355,15 @@
320 355 $this->network_settings_page_slug,
321 356 $this->default_settings_page_slug,
322 357 );
323 358
359 + // @codingStandardsIgnoreLine
324 360 if ( ! isset( $_GET['action'] ) || ! in_array( $_GET['action'], $allowed_referers, true ) ) {
325 361 return;
326 362 }
327 363
328 - // @codingStandardsIgnoreStart
364 + // @codingStandardsIgnoreLine
329 365 $options = isset( $_POST['option_page'] ) ? explode( ',', stripslashes( $_POST['option_page'] ) ) : null;
330 - // @codingStandardsIgnoreEnd
331 366
332 367 if ( $options ) {
333 368
334 369 foreach ( $options as $option ) {
@@ -365,9 +400,9 @@
365 400 set_transient( 'settings_errors', get_settings_errors(), 30 );
366 401
367 402 $go_back = add_query_arg( 'settings-updated', 'true', wp_get_referer() );
368 403
369 - wp_redirect( $go_back );
404 + wp_safe_redirect( $go_back );
370 405
371 406 exit;
372 407 }
373 408
@@ -375,9 +410,9 @@
375 410 * Add the Site filter to the Network records screen
376 411 *
377 412 * @filter wp_stream_list_table_filters
378 413 *
379 - * @param $filters
414 + * @param array $filters Filters.
380 415 *
381 416 * @return array
382 417 */
383 418 public function list_table_filters( $filters ) {
@@ -386,9 +421,9 @@
386 421 }
387 422
388 423 $blogs = array();
389 424
390 - // Display network blog as the first option
425 + // Display network blog as the first option.
391 426 $network_blog = $this->get_network_blog();
392 427
393 428 $blogs[ $network_blog->blog_id ] = array(
394 429 'label' => $network_blog->blogname,
@@ -394,9 +429,9 @@
394 429 'label' => $network_blog->blogname,
395 430 'disabled' => '',
396 431 );
397 432
398 - // add all sites
433 + // Add all sites.
399 434 foreach ( wp_stream_get_sites() as $blog ) {
400 435 $blog_data = get_blog_details( $blog->blog_id );
401 436
402 437 $blogs[ $blog->blog_id ] = array(
@@ -415,9 +450,9 @@
415 450
416 451 /**
417 452 * Add the Site toggle to screen options in network admin
418 453 *
419 - * @param $filters
454 + * @param array $filters Filters.
420 455 *
421 456 * @return array
422 457 */
423 458 public function toggle_filters( $filters ) {
@@ -430,9 +465,9 @@
430 465
431 466 /**
432 467 * Add the network suffix to the $screen_id when in the network admin
433 468 *
434 - * @param $screen_id
469 + * @param int $screen_id Screen ID.
435 470 *
436 471 * @return string
437 472 */
438 473 public function list_table_screen_id( $screen_id ) {
@@ -447,8 +482,10 @@
447 482
448 483 /**
449 484 * Set blog_id for network admin activity
450 485 *
486 + * @param int $blog_id Blog ID.
487 + *
451 488 * @return int
452 489 */
453 490 public function blog_id_logged( $blog_id ) {
454 491 return is_network_admin() ? 0 : $blog_id;
@@ -458,9 +495,9 @@
458 495 * Customize query args on multisite installs
459 496 *
460 497 * @filter wp_stream_query_args
461 498 *
462 - * @param array $args
499 + * @param array $args Site arguments.
463 500 *
464 501 * @return array
465 502 */
466 503 public function network_query_args( $args ) {
@@ -474,14 +511,15 @@
474 511 * Add site count to the page title in the network admin
475 512 *
476 513 * @filter wp_stream_admin_page_title
477 514 *
478 - * @param string $page_title
515 + * @param string $page_title Page title.
479 516 *
480 517 * @return string
481 518 */
482 519 public function network_admin_page_title( $page_title ) {
483 520 if ( is_network_admin() ) {
521 + /* translators: %d: number of sites on the network (e.g. "42") */
484 522 $site_count = sprintf( _n( '%d site', '%d sites', get_blog_count(), 'stream' ), number_format( get_blog_count() ) );
485 523 $page_title = sprintf( '%s (%s)', $page_title, $site_count );
486 524 }
487 525
@@ -490,14 +528,14 @@
490 528
491 529 /**
492 530 * Add the Site column to the network stream records
493 531 *
494 - * @param $columns
532 + * @param array $columns Columns data.
495 533 *
496 534 * @return mixed
497 535 */
498 536 public function network_admin_columns( $columns ) {
499 - if ( is_network_admin() ) {
537 + if ( is_network_admin() || $this->ajax_network_admin() ) {
500 538 $columns = array_merge(
501 539 array_slice( $columns, 0, -1 ),
502 540 array(
503 541 'blog_id' => esc_html__( 'Site', 'stream' ),
@@ -511,9 +549,9 @@
511 549
512 550 /**
513 551 * Prevent the Blogs connector from loading when not in Network Admin
514 552 *
515 - * @param $connectors
553 + * @param array $connectors Connectors.
516 554 *
517 555 * @return mixed
518 556 */
519 557 public function hide_blogs_connector( $connectors ) {