| @@ -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' ) ); |
| @@ -77,9 +103,9 @@ | ||
| 77 | 103 | * |
| 78 | 104 | * @return object |
| 79 | 105 | */ |
| 80 | 106 | public function get_network_blog() { |
| 81 | - $blog = new \stdClass; | |
| 107 | + $blog = new \stdClass(); | |
| 82 | 108 | $blog->blog_id = 0; |
| 83 | 109 | $blog->blogname = esc_html__( 'Network Admin', 'stream' ); |
| 84 | 110 | |
| 85 | 111 | return $blog; |
| @@ -90,13 +116,9 @@ | ||
| 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 | - return is_plugin_active_for_network( $this->plugin->locations['plugin'] ); | |
| 120 | + return $this->plugin->is_network_activated(); | |
| 99 | 121 | } |
| 100 | 122 | |
| 101 | 123 | /** |
| 102 | 124 | * Adds Stream to the admin bar under the "My Sites > Network Admin" menu |
| @@ -103,9 +125,9 @@ | ||
| 103 | 125 | * if Stream has been network-activated. |
| 104 | 126 | * |
| 105 | 127 | * @action admin_bar_menu |
| 106 | 128 | * |
| 107 | - * @param object $admin_bar | |
| 129 | + * @param object $admin_bar Admin bar object. | |
| 108 | 130 | * |
| 109 | 131 | * @return void |
| 110 | 132 | */ |
| 111 | 133 | public function network_admin_bar_menu( $admin_bar ) { |
| @@ -130,9 +152,9 @@ | ||
| 130 | 152 | ); |
| 131 | 153 | } |
| 132 | 154 | |
| 133 | 155 | /** |
| 134 | - * Add Network Settings and Default Settings menu items | |
| 156 | + * Add Network Settings and Default Settings menu pages | |
| 135 | 157 | * |
| 136 | 158 | * @return array |
| 137 | 159 | */ |
| 138 | 160 | public function admin_menu_screens() { |
| @@ -155,11 +177,11 @@ | ||
| 155 | 177 | |
| 156 | 178 | /** |
| 157 | 179 | * Remove records when records TTL is shortened |
| 158 | 180 | * |
| 159 | - * @param string $option_key | |
| 160 | - * @param array $old_value | |
| 161 | - * @param array $new_value | |
| 181 | + * @param string $option_key Unused. | |
| 182 | + * @param array $new_value New value. | |
| 183 | + * @param array $old_value Old value. | |
| 162 | 184 | * |
| 163 | 185 | * @action update_option_wp_stream |
| 164 | 186 | * @return void |
| 165 | 187 | */ |
| @@ -170,9 +192,9 @@ | ||
| 170 | 192 | |
| 171 | 193 | /** |
| 172 | 194 | * Adjust the action of the settings form when in the Network Admin |
| 173 | 195 | * |
| 174 | - * @param $action | |
| 196 | + * @param string $action Query string. | |
| 175 | 197 | * |
| 176 | 198 | * @return string |
| 177 | 199 | */ |
| 178 | 200 | public function settings_form_action( $action ) { |
| @@ -177,9 +199,14 @@ | ||
| 177 | 199 | */ |
| 178 | 200 | public function settings_form_action( $action ) { |
| 179 | 201 | if ( is_network_admin() ) { |
| 180 | 202 | $current_page = wp_stream_filter_input( INPUT_GET, 'page' ); |
| 181 | - $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 | + ); | |
| 182 | 209 | } |
| 183 | 210 | |
| 184 | 211 | return $action; |
| 185 | 212 | } |
| @@ -186,9 +213,9 @@ | ||
| 186 | 213 | |
| 187 | 214 | /** |
| 188 | 215 | * Add a description to each of the Settings pages in the Network Admin |
| 189 | 216 | * |
| 190 | - * @param $description | |
| 217 | + * @param string $description Description of the current page. | |
| 191 | 218 | * |
| 192 | 219 | * @return string |
| 193 | 220 | */ |
| 194 | 221 | public function settings_form_description( $description ) { |
| @@ -198,12 +225,12 @@ | ||
| 198 | 225 | |
| 199 | 226 | $current_page = wp_stream_filter_input( INPUT_GET, 'page' ); |
| 200 | 227 | |
| 201 | 228 | switch ( $current_page ) { |
| 202 | - case $this->network_settings_page_slug : | |
| 229 | + case $this->network_settings_page_slug: | |
| 203 | 230 | $description = __( 'These settings apply to all sites on the network.', 'stream' ); |
| 204 | 231 | break; |
| 205 | - case $this->default_settings_page_slug : | |
| 232 | + case $this->default_settings_page_slug: | |
| 206 | 233 | $description = __( 'These default settings will apply to new sites created on the network. These settings do not alter existing sites.', 'stream' ); |
| 207 | 234 | break; |
| 208 | 235 | } |
| 209 | 236 | |
| @@ -212,9 +239,9 @@ | ||
| 212 | 239 | |
| 213 | 240 | /** |
| 214 | 241 | * Adjusts the settings fields displayed in various network admin screens |
| 215 | 242 | * |
| 216 | - * @param $fields | |
| 243 | + * @param array $fields Page settings fields. | |
| 217 | 244 | * |
| 218 | 245 | * @return mixed |
| 219 | 246 | */ |
| 220 | 247 | public function get_network_admin_fields( $fields ) { |
| @@ -224,9 +251,9 @@ | ||
| 224 | 251 | |
| 225 | 252 | $stream_hidden_options = apply_filters( |
| 226 | 253 | 'wp_stream_hidden_option_fields', |
| 227 | 254 | array( |
| 228 | - 'general' => array( | |
| 255 | + 'general' => array( | |
| 229 | 256 | 'records_ttl', |
| 230 | 257 | ), |
| 231 | 258 | 'advanced' => array( |
| 232 | 259 | 'delete_all_records', |
| @@ -251,9 +278,9 @@ | ||
| 251 | 278 | ), |
| 252 | 279 | ) |
| 253 | 280 | ); |
| 254 | 281 | |
| 255 | - // Remove settings based on context | |
| 282 | + // Remove settings based on context. | |
| 256 | 283 | if ( $this->plugin->settings->network_options_key === $this->plugin->settings->option_key ) { |
| 257 | 284 | $hidden_options = $network_hidden_options; |
| 258 | 285 | } else { |
| 259 | 286 | $hidden_options = $stream_hidden_options; |
| @@ -270,9 +297,9 @@ | ||
| 270 | 297 | } |
| 271 | 298 | } |
| 272 | 299 | } |
| 273 | 300 | |
| 274 | - // Add settings based on context | |
| 301 | + // Add settings based on context. | |
| 275 | 302 | if ( $this->plugin->settings->network_options_key === $this->plugin->settings->option_key ) { |
| 276 | 303 | $new_fields['general']['fields'][] = array( |
| 277 | 304 | 'name' => 'site_access', |
| 278 | 305 | 'title' => __( 'Site Access', 'stream' ), |
| @@ -284,9 +311,9 @@ | ||
| 284 | 311 | |
| 285 | 312 | $fields = array_merge_recursive( $new_fields, $fields ); |
| 286 | 313 | } |
| 287 | 314 | |
| 288 | - // Remove empty settings sections | |
| 315 | + // Remove empty settings sections. | |
| 289 | 316 | foreach ( $fields as $section_key => $section ) { |
| 290 | 317 | if ( empty( $section['fields'] ) ) { |
| 291 | 318 | unset( $fields[ $section_key ] ); |
| 292 | 319 | } |
| @@ -299,8 +326,10 @@ | ||
| 299 | 326 | * Get translations of serialized Stream Network settings |
| 300 | 327 | * |
| 301 | 328 | * @filter wp_stream_serialized_labels |
| 302 | 329 | * |
| 330 | + * @param array $labels Setting labels. | |
| 331 | + * | |
| 303 | 332 | * @return array Multidimensional array of fields |
| 304 | 333 | */ |
| 305 | 334 | public function get_settings_translations( $labels ) { |
| 306 | 335 | $network_key = $this->plugin->settings->network_options_key; |
| @@ -326,15 +355,15 @@ | ||
| 326 | 355 | $this->network_settings_page_slug, |
| 327 | 356 | $this->default_settings_page_slug, |
| 328 | 357 | ); |
| 329 | 358 | |
| 359 | + // @codingStandardsIgnoreLine | |
| 330 | 360 | if ( ! isset( $_GET['action'] ) || ! in_array( $_GET['action'], $allowed_referers, true ) ) { |
| 331 | 361 | return; |
| 332 | 362 | } |
| 333 | 363 | |
| 334 | - // @codingStandardsIgnoreStart | |
| 364 | + // @codingStandardsIgnoreLine | |
| 335 | 365 | $options = isset( $_POST['option_page'] ) ? explode( ',', stripslashes( $_POST['option_page'] ) ) : null; |
| 336 | - // @codingStandardsIgnoreEnd | |
| 337 | 366 | |
| 338 | 367 | if ( $options ) { |
| 339 | 368 | |
| 340 | 369 | foreach ( $options as $option ) { |
| @@ -371,9 +400,9 @@ | ||
| 371 | 400 | set_transient( 'settings_errors', get_settings_errors(), 30 ); |
| 372 | 401 | |
| 373 | 402 | $go_back = add_query_arg( 'settings-updated', 'true', wp_get_referer() ); |
| 374 | 403 | |
| 375 | - wp_redirect( $go_back ); | |
| 404 | + wp_safe_redirect( $go_back ); | |
| 376 | 405 | |
| 377 | 406 | exit; |
| 378 | 407 | } |
| 379 | 408 | |
| @@ -381,9 +410,9 @@ | ||
| 381 | 410 | * Add the Site filter to the Network records screen |
| 382 | 411 | * |
| 383 | 412 | * @filter wp_stream_list_table_filters |
| 384 | 413 | * |
| 385 | - * @param $filters | |
| 414 | + * @param array $filters Filters. | |
| 386 | 415 | * |
| 387 | 416 | * @return array |
| 388 | 417 | */ |
| 389 | 418 | public function list_table_filters( $filters ) { |
| @@ -392,9 +421,9 @@ | ||
| 392 | 421 | } |
| 393 | 422 | |
| 394 | 423 | $blogs = array(); |
| 395 | 424 | |
| 396 | - // Display network blog as the first option | |
| 425 | + // Display network blog as the first option. | |
| 397 | 426 | $network_blog = $this->get_network_blog(); |
| 398 | 427 | |
| 399 | 428 | $blogs[ $network_blog->blog_id ] = array( |
| 400 | 429 | 'label' => $network_blog->blogname, |
| @@ -400,9 +429,9 @@ | ||
| 400 | 429 | 'label' => $network_blog->blogname, |
| 401 | 430 | 'disabled' => '', |
| 402 | 431 | ); |
| 403 | 432 | |
| 404 | - // add all sites | |
| 433 | + // Add all sites. | |
| 405 | 434 | foreach ( wp_stream_get_sites() as $blog ) { |
| 406 | 435 | $blog_data = get_blog_details( $blog->blog_id ); |
| 407 | 436 | |
| 408 | 437 | $blogs[ $blog->blog_id ] = array( |
| @@ -421,9 +450,9 @@ | ||
| 421 | 450 | |
| 422 | 451 | /** |
| 423 | 452 | * Add the Site toggle to screen options in network admin |
| 424 | 453 | * |
| 425 | - * @param $filters | |
| 454 | + * @param array $filters Filters. | |
| 426 | 455 | * |
| 427 | 456 | * @return array |
| 428 | 457 | */ |
| 429 | 458 | public function toggle_filters( $filters ) { |
| @@ -436,9 +465,9 @@ | ||
| 436 | 465 | |
| 437 | 466 | /** |
| 438 | 467 | * Add the network suffix to the $screen_id when in the network admin |
| 439 | 468 | * |
| 440 | - * @param $screen_id | |
| 469 | + * @param int $screen_id Screen ID. | |
| 441 | 470 | * |
| 442 | 471 | * @return string |
| 443 | 472 | */ |
| 444 | 473 | public function list_table_screen_id( $screen_id ) { |
| @@ -453,8 +482,10 @@ | ||
| 453 | 482 | |
| 454 | 483 | /** |
| 455 | 484 | * Set blog_id for network admin activity |
| 456 | 485 | * |
| 486 | + * @param int $blog_id Blog ID. | |
| 487 | + * | |
| 457 | 488 | * @return int |
| 458 | 489 | */ |
| 459 | 490 | public function blog_id_logged( $blog_id ) { |
| 460 | 491 | return is_network_admin() ? 0 : $blog_id; |
| @@ -464,9 +495,9 @@ | ||
| 464 | 495 | * Customize query args on multisite installs |
| 465 | 496 | * |
| 466 | 497 | * @filter wp_stream_query_args |
| 467 | 498 | * |
| 468 | - * @param array $args | |
| 499 | + * @param array $args Site arguments. | |
| 469 | 500 | * |
| 470 | 501 | * @return array |
| 471 | 502 | */ |
| 472 | 503 | public function network_query_args( $args ) { |
| @@ -480,14 +511,15 @@ | ||
| 480 | 511 | * Add site count to the page title in the network admin |
| 481 | 512 | * |
| 482 | 513 | * @filter wp_stream_admin_page_title |
| 483 | 514 | * |
| 484 | - * @param string $page_title | |
| 515 | + * @param string $page_title Page title. | |
| 485 | 516 | * |
| 486 | 517 | * @return string |
| 487 | 518 | */ |
| 488 | 519 | public function network_admin_page_title( $page_title ) { |
| 489 | 520 | if ( is_network_admin() ) { |
| 521 | + /* translators: %d: number of sites on the network (e.g. "42") */ | |
| 490 | 522 | $site_count = sprintf( _n( '%d site', '%d sites', get_blog_count(), 'stream' ), number_format( get_blog_count() ) ); |
| 491 | 523 | $page_title = sprintf( '%s (%s)', $page_title, $site_count ); |
| 492 | 524 | } |
| 493 | 525 | |
| @@ -496,9 +528,9 @@ | ||
| 496 | 528 | |
| 497 | 529 | /** |
| 498 | 530 | * Add the Site column to the network stream records |
| 499 | 531 | * |
| 500 | - * @param $columns | |
| 532 | + * @param array $columns Columns data. | |
| 501 | 533 | * |
| 502 | 534 | * @return mixed |
| 503 | 535 | */ |
| 504 | 536 | public function network_admin_columns( $columns ) { |
| @@ -517,9 +549,9 @@ | ||
| 517 | 549 | |
| 518 | 550 | /** |
| 519 | 551 | * Prevent the Blogs connector from loading when not in Network Admin |
| 520 | 552 | * |
| 521 | - * @param $connectors | |
| 553 | + * @param array $connectors Connectors. | |
| 522 | 554 | * |
| 523 | 555 | * @return mixed |
| 524 | 556 | */ |
| 525 | 557 | public function hide_blogs_connector( $connectors ) { |