PluginProbe
Stream – Activity Log & Audit Trail / 4.0.2
Stream – Activity Log & Audit Trail v4.0.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-admin.php +170 -108 3.2.34.0.2 View file →
@@ -1,5 +1,10 @@
1 1 <?php
2 +/**
3 + * Centralized manager for WordPress backend functionality.
4 + *
5 + * @package WP_Stream
6 + */
2 7
3 8 namespace WP_Stream;
4 9
5 10 use DateTime;
@@ -4,15 +9,18 @@
4 9
5 10 use DateTime;
6 11 use DateTimeZone;
7 12 use DateInterval;
8 -use \WP_CLI;
9 -use \WP_Roles;
13 +use WP_CLI;
14 +use WP_Roles;
10 15
16 +/**
17 + * Class - Admin
18 + */
11 19 class Admin {
12 20
13 21 /**
14 - * Hold Plugin class
22 + * Holds Instance of plugin object
15 23 *
16 24 * @var Plugin
17 25 */
18 26 public $plugin;
@@ -117,9 +125,9 @@
117 125
118 126 /**
119 127 * Class constructor.
120 128 *
121 - * @param Plugin $plugin The main Plugin class.
129 + * @param Plugin $plugin Instance of plugin object.
122 130 */
123 131 public function __construct( $plugin ) {
124 132 $this->plugin = $plugin;
125 133
@@ -133,9 +141,9 @@
133 141 // User and role caps.
134 142 add_filter( 'user_has_cap', array( $this, 'filter_user_caps' ), 10, 4 );
135 143 add_filter( 'role_has_cap', array( $this, 'filter_role_caps' ), 10, 3 );
136 144
137 - if ( is_multisite() && is_plugin_active_for_network( $this->plugin->locations['plugin'] ) && ! is_network_admin() ) {
145 + if ( is_multisite() && $plugin->is_network_activated() && ! is_network_admin() ) {
138 146 $options = (array) get_site_option( 'wp_stream_network', array() );
139 147 $option = isset( $options['general_site_access'] ) ? absint( $options['general_site_access'] ) : 1;
140 148
141 149 $this->disable_access = ( $option ) ? false : true;
@@ -154,17 +162,21 @@
154 162 add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
155 163
156 164 // Plugin action links.
157 165 add_filter(
158 - 'plugin_action_links', array(
166 + 'plugin_action_links',
167 + array(
159 168 $this,
160 169 'plugin_action_links',
161 - ), 10, 2
170 + ),
171 + 10,
172 + 2
162 173 );
163 174
164 175 // Load admin scripts and styles.
165 176 add_action(
166 - 'admin_enqueue_scripts', array(
177 + 'admin_enqueue_scripts',
178 + array(
167 179 $this,
168 180 'admin_enqueue_scripts',
169 181 )
170 182 );
@@ -171,21 +183,20 @@
171 183 add_action( 'admin_enqueue_scripts', array( $this, 'admin_menu_css' ) );
172 184
173 185 // Reset Streams database.
174 186 add_action(
175 - 'wp_ajax_wp_stream_reset', array(
187 + 'wp_ajax_wp_stream_reset',
188 + array(
176 189 $this,
177 190 'wp_ajax_reset',
178 191 )
179 192 );
180 193
181 - // Uninstall Streams and Deactivate plugin.
182 - $uninstall = $this->plugin->db->driver->purge_storage( $this->plugin );
183 -
184 194 // Auto purge setup.
185 195 add_action( 'wp_loaded', array( $this, 'purge_schedule_setup' ) );
186 196 add_action(
187 - 'wp_stream_auto_purge', array(
197 + 'wp_stream_auto_purge',
198 + array(
188 199 $this,
189 200 'purge_scheduled_action',
190 201 )
191 202 );
@@ -191,9 +202,10 @@
191 202 );
192 203
193 204 // Ajax users list.
194 205 add_action(
195 - 'wp_ajax_wp_stream_filters', array(
206 + 'wp_ajax_wp_stream_filters',
207 + array(
196 208 $this,
197 209 'ajax_filters',
198 210 )
199 211 );
@@ -207,8 +219,14 @@
207 219 public function init() {
208 220 $this->network = new Network( $this->plugin );
209 221 $this->live_update = new Live_Update( $this->plugin );
210 222 $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 + }
211 229 }
212 230
213 231 /**
214 232 * Output specific updates passed as URL parameters.
@@ -234,9 +252,9 @@
234 252 * @param bool $is_error If the message is error_level (true) or warning (false).
235 253 */
236 254 public function notice( $message, $is_error = true ) {
237 255 if ( defined( 'WP_CLI' ) && WP_CLI ) {
238 - $message = strip_tags( $message );
256 + $message = wp_strip_all_tags( $message );
239 257
240 258 if ( $is_error ) {
241 259 WP_CLI::warning( $message );
242 260 } else {
@@ -358,9 +376,10 @@
358 376 do_action( 'wp_stream_admin_menu_screens' );
359 377
360 378 // Register the list table early, so it associates the column headers with 'Screen settings'.
361 379 add_action(
362 - 'load-' . $this->screen_id['main'], array(
380 + 'load-' . $this->screen_id['main'],
381 + array(
363 382 $this,
364 383 'register_list_table',
365 384 )
366 385 );
@@ -371,15 +390,15 @@
371 390 * Enqueue scripts/styles for admin screen
372 391 *
373 392 * @action admin_enqueue_scripts
374 393 *
375 - * @param string $hook
394 + * @param string $hook Current hook.
376 395 *
377 396 * @return void
378 397 */
379 398 public function admin_enqueue_scripts( $hook ) {
380 - wp_register_script( 'wp-stream-select2', $this->plugin->locations['url'] . 'ui/lib/select2/js/select2.full.min.js', array( 'jquery' ), '3.5.2', true );
381 - wp_register_style( 'wp-stream-select2', $this->plugin->locations['url'] . 'ui/lib/select2/css/select2.min.css', array(), '3.5.2' );
399 + wp_register_script( 'wp-stream-select2', $this->plugin->locations['url'] . 'ui/lib/select2/js/select2.full.min.js', array( 'jquery' ), '4.0.13', true );
400 + wp_register_style( 'wp-stream-select2', $this->plugin->locations['url'] . 'ui/lib/select2/css/select2.min.css', array(), '4.0.13' );
382 401 wp_register_script( 'wp-stream-timeago', $this->plugin->locations['url'] . 'ui/lib/timeago/jquery.timeago.js', array(), '1.4.1', true );
383 402
384 403 $locale = strtolower( substr( get_locale(), 0, 2 ) );
385 404 $file_tmpl = 'ui/lib/timeago/locales/jquery.timeago.%s.js';
@@ -384,11 +403,23 @@
384 403 $locale = strtolower( substr( get_locale(), 0, 2 ) );
385 404 $file_tmpl = 'ui/lib/timeago/locales/jquery.timeago.%s.js';
386 405
387 406 if ( file_exists( $this->plugin->locations['dir'] . sprintf( $file_tmpl, $locale ) ) ) {
388 - wp_register_script( 'wp-stream-timeago-locale', $this->plugin->locations['url'] . sprintf( $file_tmpl, $locale ), array( 'wp-stream-timeago' ), '1' );
407 + wp_register_script(
408 + 'wp-stream-timeago-locale',
409 + $this->plugin->locations['url'] . sprintf( $file_tmpl, $locale ),
410 + array( 'wp-stream-timeago' ),
411 + '1',
412 + false
413 + );
389 414 } else {
390 - wp_register_script( 'wp-stream-timeago-locale', $this->plugin->locations['url'] . sprintf( $file_tmpl, 'en' ), array( 'wp-stream-timeago' ), '1' );
415 + wp_register_script(
416 + 'wp-stream-timeago-locale',
417 + $this->plugin->locations['url'] . sprintf( $file_tmpl, 'en' ),
418 + array( 'wp-stream-timeago' ),
419 + '1',
420 + false
421 + );
391 422 }
392 423
393 424 $min = wp_stream_min_suffix();
394 425 wp_enqueue_style( 'wp-stream-admin', $this->plugin->locations['url'] . 'ui/css/admin.' . $min . 'css', array(), $this->plugin->get_version() );
@@ -402,24 +433,36 @@
402 433 wp_enqueue_script( 'wp-stream-timeago' );
403 434 wp_enqueue_script( 'wp-stream-timeago-locale' );
404 435
405 436 wp_enqueue_script(
406 - 'wp-stream-admin', $this->plugin->locations['url'] . 'ui/js/admin.' . $min . 'js', array(
437 + 'wp-stream-admin',
438 + $this->plugin->locations['url'] . 'ui/js/admin.' . $min . 'js',
439 + array(
407 440 'jquery',
408 441 'wp-stream-select2',
409 - ), $this->plugin->get_version()
442 + ),
443 + $this->plugin->get_version(),
444 + false
410 445 );
411 446 wp_enqueue_script(
412 - 'wp-stream-admin-exclude', $this->plugin->locations['url'] . 'ui/js/exclude.' . $min . 'js', array(
447 + 'wp-stream-admin-exclude',
448 + $this->plugin->locations['url'] . 'ui/js/exclude.' . $min . 'js',
449 + array(
413 450 'jquery',
414 451 'wp-stream-select2',
415 - ), $this->plugin->get_version()
452 + ),
453 + $this->plugin->get_version(),
454 + false
416 455 );
417 456 wp_enqueue_script(
418 - 'wp-stream-live-updates', $this->plugin->locations['url'] . 'ui/js/live-updates.' . $min . 'js', array(
457 + 'wp-stream-live-updates',
458 + $this->plugin->locations['url'] . 'ui/js/live-updates.' . $min . 'js',
459 + array(
419 460 'jquery',
420 461 'heartbeat',
421 - ), $this->plugin->get_version()
462 + ),
463 + $this->plugin->get_version(),
464 + false
422 465 );
423 466
424 467 wp_localize_script(
425 468 'wp-stream-admin',
@@ -425,11 +468,10 @@
425 468 'wp-stream-admin',
426 469 'wp_stream',
427 470 array(
428 471 'i18n' => array(
429 - 'confirm_purge' => esc_html__( 'Are you sure you want to delete all Stream activity records from the database? This cannot be undone.', 'stream' ),
430 - 'confirm_defaults' => esc_html__( 'Are you sure you want to reset all site settings to default? This cannot be undone.', 'stream' ),
431 - 'confirm_uninstall' => esc_html__( 'Are you sure you want to uninstall and deactivate Stream? This will delete all Stream tables from the database and cannot be undone.', 'stream' ),
472 + 'confirm_purge' => esc_html__( 'Are you sure you want to delete all Stream activity records from the database? This cannot be undone.', 'stream' ),
473 + 'confirm_defaults' => esc_html__( 'Are you sure you want to reset all site settings to default? This cannot be undone.', 'stream' ),
432 474 ),
433 475 'locale' => esc_js( $locale ),
434 476 'gmt_offset' => get_option( 'gmt_offset' ),
435 477 )
@@ -434,21 +476,21 @@
434 476 'gmt_offset' => get_option( 'gmt_offset' ),
435 477 )
436 478 );
437 479
480 + $order_types = array( 'asc', 'desc' );
481 +
438 482 wp_localize_script(
439 483 'wp-stream-live-updates',
440 484 'wp_stream_live_updates',
441 485 array(
442 486 'current_screen' => $hook,
443 - 'current_page' => isset( $_GET['paged'] ) ? esc_js( $_GET['paged'] ) : '1', // WPCS: CSRF ok.
444 - // input var okay, CSRF okay
445 - 'current_order' => isset( $_GET['order'] ) ? esc_js( $_GET['order'] ) : 'desc', // WPCS: CSRF ok.
446 - // input var okay, CSRF okay
447 - 'current_query' => wp_stream_json_encode( $_GET ), // WPCS: CSRF ok.
448 - // input var okay, CSRF okay
449 - 'current_query_count' => count( $_GET ), // WPCS: CSRF ok.
450 - // input var okay, CSRF okay
487 + 'current_page' => isset( $_GET['paged'] ) ? absint( wp_unslash( $_GET['paged'] ) ) : '1', // phpcs:ignore WordPress.Security.NonceVerification.Recommended
488 + 'current_order' => isset( $_GET['order'] ) && in_array( strtolower( $_GET['order'] ), $order_types, true ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
489 + ? esc_js( $_GET['order'] ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
490 + : 'desc',
491 + 'current_query' => wp_json_encode( $_GET ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended
492 + 'current_query_count' => count( $_GET ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended
451 493 )
452 494 );
453 495 }
454 496
@@ -465,9 +507,16 @@
465 507 * @return int
466 508 */
467 509 $bulk_actions_threshold = apply_filters( 'wp_stream_bulk_actions_threshold', 100 );
468 510
469 - wp_enqueue_script( 'wp-stream-global', $this->plugin->locations['url'] . 'ui/js/global.' . $min . 'js', array( 'jquery' ), $this->plugin->get_version() );
511 + wp_enqueue_script(
512 + 'wp-stream-global',
513 + $this->plugin->locations['url'] . 'ui/js/global.' . $min . 'js',
514 + array( 'jquery' ),
515 + $this->plugin->get_version(),
516 + false
517 + );
518 +
470 519 wp_localize_script(
471 520 'wp-stream-global',
472 521 'wp_stream_global',
473 522 array(
@@ -472,9 +521,9 @@
472 521 'wp_stream_global',
473 522 array(
474 523 'bulk_actions' => array(
475 524 'i18n' => array(
476 - // translators: Placeholder refers to a number of items (e.g. "1,742")
525 + /* translators: %s: a number of items (e.g. "1,742") */
477 526 'confirm_action' => sprintf( esc_html__( 'Are you sure you want to perform bulk actions on over %s items? This process could take a while to complete.', 'stream' ), number_format( absint( $bulk_actions_threshold ) ) ),
478 527 ),
479 528 'threshold' => absint( $bulk_actions_threshold ),
480 529 ),
@@ -488,15 +537,21 @@
488 537 *
489 538 * @return bool
490 539 */
491 540 public function is_stream_screen() {
492 - if ( is_admin() && false !== strpos( wp_stream_filter_input( INPUT_GET, 'page' ), $this->records_page_slug ) ) {
541 + if ( ! is_admin() ) {
542 + return false;
543 + }
544 +
545 + $page = wp_stream_filter_input( INPUT_GET, 'page' );
546 + if ( is_string( $page ) && false !== strpos( $page, $this->records_page_slug ) ) {
493 547 return true;
494 548 }
495 549
496 - $screen = get_current_screen();
497 - if ( is_admin() && Alerts::POST_TYPE === $screen->post_type ) {
498 - 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 );
499 554 }
500 555
501 556 return false;
502 557 }
@@ -503,9 +558,9 @@
503 558
504 559 /**
505 560 * Add a specific body class to all Stream admin screens
506 561 *
507 - * @param string $classes CSS classes to output to body
562 + * @param string $classes CSS classes to output to body.
508 563 *
509 564 * @filter admin_body_class
510 565 *
511 566 * @return string
@@ -515,10 +570,10 @@
515 570
516 571 if ( $this->is_stream_screen() ) {
517 572 $stream_classes[] = $this->admin_body_class;
518 573
519 - if ( isset( $_GET['page'] ) ) { // CSRF okay
520 - $stream_classes[] = sanitize_key( $_GET['page'] ); // input var okay, CSRF okay
574 + if ( isset( $_GET['page'] ) ) { // // phpcs:ignore WordPress.Security.NonceVerification.Recommended
575 + $stream_classes[] = sanitize_key( $_GET['page'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
521 576 }
522 577 }
523 578
524 579 /**
@@ -543,9 +598,9 @@
543 598 $min = wp_stream_min_suffix();
544 599 wp_register_style( 'wp-stream-datepicker', $this->plugin->locations['url'] . 'ui/css/datepicker.' . $min . 'css', array(), $this->plugin->get_version() );
545 600 wp_register_style( 'wp-stream-icons', $this->plugin->locations['url'] . 'ui/stream-icons/style.css', array(), $this->plugin->get_version() );
546 601
547 - // Make sure we're working off a clean version
602 + // Make sure we're working off a clean version.
548 603 if ( ! file_exists( ABSPATH . WPINC . '/version.php' ) ) {
549 604 return;
550 605 }
551 606 include ABSPATH . WPINC . '/version.php';
@@ -628,9 +683,9 @@
628 683 if ( defined( 'WP_STREAM_TESTS' ) && WP_STREAM_TESTS ) {
629 684 return true;
630 685 }
631 686
632 - wp_redirect(
687 + wp_safe_redirect(
633 688 add_query_arg(
634 689 array(
635 690 'page' => is_network_admin() ? $this->network->network_settings_page_slug : $this->settings_page_slug,
636 691 'message' => 'data_erased',
@@ -641,14 +696,19 @@
641 696
642 697 exit;
643 698 }
644 699
700 + /**
701 + * Clears stream records from the database.
702 + *
703 + * @return void
704 + */
645 705 private function erase_stream_records() {
646 706 global $wpdb;
647 707
648 708 $where = '';
649 709
650 - if ( is_multisite() && ! is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) {
710 + if ( is_multisite() && ! $this->plugin->is_network_activated() ) {
651 711 $where .= $wpdb->prepare( ' AND `blog_id` = %d', get_current_blog_id() );
652 712 }
653 713
654 714 $wpdb->query(
@@ -659,8 +719,13 @@
659 719 WHERE 1=1 {$where};" // @codingStandardsIgnoreLine $where already prepared
660 720 );
661 721 }
662 722
723 + /**
724 + * Schedules a purge of records.
725 + *
726 + * @return void
727 + */
663 728 public function purge_schedule_setup() {
664 729 if ( ! wp_next_scheduled( 'wp_stream_auto_purge' ) ) {
665 730 wp_schedule_event( time(), 'twicedaily', 'wp_stream_auto_purge' );
666 731 }
@@ -665,26 +730,32 @@
665 730 wp_schedule_event( time(), 'twicedaily', 'wp_stream_auto_purge' );
666 731 }
667 732 }
668 733
734 + /**
735 + * Executes a scheduled purge
736 + *
737 + * @return void
738 + */
669 739 public function purge_scheduled_action() {
670 740 global $wpdb;
671 741
672 - // Don't purge when in Network Admin unless Stream is network activated
742 + // Don't purge when in Network Admin unless Stream is network activated.
673 743 if (
674 744 is_multisite()
675 745 &&
676 746 is_network_admin()
677 747 &&
678 - ! is_plugin_active_for_network( $this->plugin->locations['plugin'] )
748 + ! $this->plugin->is_network_activated()
679 749 ) {
680 750 return;
681 751 }
682 752
683 - if ( is_multisite() && is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) {
684 - $options = (array) get_site_option( 'wp_stream_network', array() );
753 + $defaults = $this->plugin->settings->get_defaults();
754 + if ( is_multisite() && $this->plugin->is_network_activated() ) {
755 + $options = (array) get_site_option( 'wp_stream_network', $defaults );
685 756 } else {
686 - $options = (array) get_option( 'wp_stream', array() );
757 + $options = (array) get_option( 'wp_stream', $defaults );
687 758 }
688 759
689 760 if ( ! empty( $options['general_keep_records_indefinitely'] ) || ! isset( $options['general_records_ttl'] ) ) {
690 761 return;
@@ -697,10 +768,10 @@
697 768 $date->sub( DateInterval::createFromDateString( "$days days" ) );
698 769
699 770 $where = $wpdb->prepare( ' AND `stream`.`created` < %s', $date->format( 'Y-m-d H:i:s' ) );
700 771
701 - // Multisite but NOT network activated, only purge the current blog
702 - if ( is_multisite() && ! is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) {
772 + // Multisite but NOT network activated, only purge the current blog.
773 + if ( is_multisite() && ! $this->plugin->is_network_activated() ) {
703 774 $where .= $wpdb->prepare( ' AND `blog_id` = %d', get_current_blog_id() );
704 775 }
705 776
706 777 $wpdb->query(
@@ -712,13 +783,15 @@
712 783 );
713 784 }
714 785
715 786 /**
716 - * @param array $links
717 - * @param string $file
787 + * Returns the admin action links.
718 788 *
719 789 * @filter plugin_action_links
720 790 *
791 + * @param array $links Action links.
792 + * @param string $file Plugin file.
793 + *
721 794 * @return array
722 795 */
723 796 public function plugin_action_links( $links, $file ) {
724 797 if ( plugin_basename( $this->plugin->locations['dir'] . 'stream.php' ) !== $file ) {
@@ -724,10 +797,10 @@
724 797 if ( plugin_basename( $this->plugin->locations['dir'] . 'stream.php' ) !== $file ) {
725 798 return $links;
726 799 }
727 800
728 - // Also don't show links in Network Admin if Stream isn't network enabled
729 - if ( is_network_admin() && is_multisite() && ! is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) {
801 + // Also don't show links in Network Admin if Stream isn't network enabled.
802 + if ( is_network_admin() && is_multisite() && ! $this->plugin->is_network_activated() ) {
730 803 return $links;
731 804 }
732 805
733 806 if ( is_network_admin() ) {
@@ -733,30 +806,22 @@
733 806 if ( is_network_admin() ) {
734 807 $admin_page_url = add_query_arg(
735 808 array(
736 809 'page' => $this->network->network_settings_page_slug,
737 - ), network_admin_url( $this->admin_parent_page )
810 + ),
811 + network_admin_url( $this->admin_parent_page )
738 812 );
739 813 } else {
740 814 $admin_page_url = add_query_arg(
741 815 array(
742 816 'page' => $this->settings_page_slug,
743 - ), admin_url( $this->admin_parent_page )
817 + ),
818 + admin_url( $this->admin_parent_page )
744 819 );
745 820 }
746 821
747 822 $links[] = sprintf( '<a href="%s">%s</a>', esc_url( $admin_page_url ), esc_html__( 'Settings', 'default' ) );
748 823
749 - $url = add_query_arg(
750 - array(
751 - 'action' => 'wp_stream_uninstall',
752 - 'wp_stream_nonce' => wp_create_nonce( 'stream_nonce' ),
753 - ),
754 - admin_url( 'admin-ajax.php' )
755 - );
756 -
757 - $links[] = sprintf( '<span id="wp_stream_uninstall" class="delete"><a href="%s">%s</a></span>', esc_url( $url ), esc_html__( 'Uninstall', 'stream' ) );
758 -
759 824 return $links;
760 825 }
761 826
762 827 /**
@@ -798,9 +863,9 @@
798 863 <?php if ( count( $sections ) > 1 ) : ?>
799 864 <h2 class="nav-tab-wrapper">
800 865 <?php $i = 0; ?>
801 866 <?php foreach ( $sections as $section => $data ) : ?>
802 - <?php $i++; ?>
867 + <?php ++$i; ?>
803 868 <?php $is_active = ( ( 1 === $i && ! $active_tab ) || $active_tab === $section ); ?>
804 869 <a href="<?php echo esc_url( add_query_arg( 'tab', $section ) ); ?>" class="nav-tab <?php echo $is_active ? esc_attr( ' nav-tab-active' ) : ''; ?>">
805 870 <?php echo esc_html( $data['title'] ); ?>
806 871 </a>
@@ -813,9 +878,9 @@
813 878 <div class="settings-sections">
814 879 <?php
815 880 $i = 0;
816 881 foreach ( $sections as $section => $data ) {
817 - $i++;
882 + ++$i;
818 883
819 884 $is_active = ( ( 1 === $i && ! $active_tab ) || $active_tab === $section );
820 885
821 886 if ( $is_active ) {
@@ -836,9 +901,10 @@
836 901 * Instantiate the list table
837 902 */
838 903 public function register_list_table() {
839 904 $this->list_table = new List_Table(
840 - $this->plugin, array(
905 + $this->plugin,
906 + array(
841 907 'screen' => $this->screen_id['main'],
842 908 )
843 909 );
844 910 }
@@ -845,9 +911,9 @@
845 911
846 912 /**
847 913 * Check if a particular role has access
848 914 *
849 - * @param string $role
915 + * @param string $role User role.
850 916 *
851 917 * @return bool
852 918 */
853 919 private function role_can_view( $role ) {
@@ -860,12 +926,12 @@
860 926
861 927 /**
862 928 * Filter user caps to dynamically grant our view cap based on allowed roles
863 929 *
864 - * @param $allcaps
865 - * @param $caps
866 - * @param $args
867 - * @param $user
930 + * @param array $allcaps All capabilities.
931 + * @param array $caps Required caps.
932 + * @param array $args Unused.
933 + * @param WP_User $user User.
868 934 *
869 935 * @filter user_has_cap
870 936 *
871 937 * @return array
@@ -910,11 +976,11 @@
910 976 * Filter role caps to dynamically grant our view cap based on allowed roles
911 977 *
912 978 * @filter role_has_cap
913 979 *
914 - * @param $allcaps
915 - * @param $cap
916 - * @param $role
980 + * @param array $allcaps All capabilities.
981 + * @param string $cap Require cap.
982 + * @param string $role User role.
917 983 *
918 984 * @return array
919 985 */
920 986 public function filter_role_caps( $allcaps, $cap, $role ) {
@@ -927,8 +993,10 @@
927 993 return $allcaps;
928 994 }
929 995
930 996 /**
997 + * Ajax callback for return a user list.
998 + *
931 999 * @action wp_ajax_wp_stream_filters
932 1000 */
933 1001 public function ajax_filters() {
934 1002 if ( ! defined( 'DOING_AJAX' ) || ! current_user_can( $this->plugin->admin->settings_cap ) ) {
@@ -962,9 +1030,9 @@
962 1030 if ( count( $users ) > $this->preload_users_max ) {
963 1031 $users = array_slice( $users, 0, $this->preload_users_max );
964 1032 }
965 1033
966 - // Get gravatar / roles for final result set
1034 + // Get gravatar / roles for final result set.
967 1035 $results = $this->get_users_record_meta( $users );
968 1036
969 1037 break;
970 1038 }
@@ -969,14 +1037,20 @@
969 1037 break;
970 1038 }
971 1039
972 1040 if ( isset( $results ) ) {
973 - echo wp_stream_json_encode( $results ); // xss ok
1041 + echo wp_json_encode( $results );
974 1042 }
975 1043
976 1044 die();
977 1045 }
978 1046
1047 + /**
1048 + * Return relevant user meta data.
1049 + *
1050 + * @param array $authors Author data.
1051 + * @return array
1052 + */
979 1053 public function get_users_record_meta( $authors ) {
980 1054 $authors_records = array();
981 1055
982 1056 foreach ( $authors as $user_id => $args ) {
@@ -996,19 +1070,15 @@
996 1070
997 1071 /**
998 1072 * Get user meta in a way that is also safe for VIP
999 1073 *
1000 - * @param int $user_id
1001 - * @param string $meta_key
1002 - * @param bool $single (optional)
1074 + * @param int $user_id User ID.
1075 + * @param string $meta_key Meta key.
1076 + * @param bool $single Return first found meta value connected to the meta key (optional).
1003 1077 *
1004 1078 * @return mixed
1005 1079 */
1006 1080 public function get_user_meta( $user_id, $meta_key, $single = true ) {
1007 - if ( wp_stream_is_vip() && function_exists( 'get_user_attribute' ) ) {
1008 - return get_user_attribute( $user_id, $meta_key );
1009 - }
1010 -
1011 1081 return get_user_meta( $user_id, $meta_key, $single );
1012 1082 }
1013 1083
1014 1084 /**
@@ -1013,20 +1083,16 @@
1013 1083
1014 1084 /**
1015 1085 * Update user meta in a way that is also safe for VIP
1016 1086 *
1017 - * @param int $user_id
1018 - * @param string $meta_key
1019 - * @param mixed $meta_value
1020 - * @param mixed $prev_value (optional)
1087 + * @param int $user_id User ID.
1088 + * @param string $meta_key Meta key.
1089 + * @param mixed $meta_value Meta value.
1090 + * @param mixed $prev_value Previous meta value being overwritten (optional).
1021 1091 *
1022 1092 * @return int|bool
1023 1093 */
1024 1094 public function update_user_meta( $user_id, $meta_key, $meta_value, $prev_value = '' ) {
1025 - if ( wp_stream_is_vip() && function_exists( 'update_user_attribute' ) ) {
1026 - return update_user_attribute( $user_id, $meta_key, $meta_value );
1027 - }
1028 -
1029 1095 return update_user_meta( $user_id, $meta_key, $meta_value, $prev_value );
1030 1096 }
1031 1097
1032 1098 /**
@@ -1031,18 +1097,14 @@
1031 1097
1032 1098 /**
1033 1099 * Delete user meta in a way that is also safe for VIP
1034 1100 *
1035 - * @param int $user_id
1036 - * @param string $meta_key
1037 - * @param mixed $meta_value (optional)
1101 + * @param int $user_id User ID.
1102 + * @param string $meta_key Meta key.
1103 + * @param mixed $meta_value Meta value (optional).
1038 1104 *
1039 1105 * @return bool
1040 1106 */
1041 1107 public function delete_user_meta( $user_id, $meta_key, $meta_value = '' ) {
1042 - if ( wp_stream_is_vip() && function_exists( 'delete_user_attribute' ) ) {
1043 - return delete_user_attribute( $user_id, $meta_key, $meta_value );
1044 - }
1045 -
1046 1108 return delete_user_meta( $user_id, $meta_key, $meta_value );
1047 1109 }
1048 1110 }