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-admin.php +212 -143 3.0.53.4.2 View file →
@@ -1,5 +1,6 @@
1 1 <?php
2 +
2 3 namespace WP_Stream;
3 4
4 5 use DateTime;
5 6 use DateTimeZone;
@@ -7,8 +8,9 @@
7 8 use \WP_CLI;
8 9 use \WP_Roles;
9 10
10 11 class Admin {
12 +
11 13 /**
12 14 * Hold Plugin class
13 15 *
14 16 * @var Plugin
@@ -124,9 +126,9 @@
124 126 add_action( 'init', array( $this, 'init' ) );
125 127
126 128 // Ensure function used in various methods is pre-loaded.
127 129 if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
128 - require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
130 + require_once ABSPATH . '/wp-admin/includes/plugin.php';
129 131 }
130 132
131 133 // User and role caps.
132 134 add_filter( 'user_has_cap', array( $this, 'filter_user_caps' ), 10, 4 );
@@ -131,9 +133,9 @@
131 133 // User and role caps.
132 134 add_filter( 'user_has_cap', array( $this, 'filter_user_caps' ), 10, 4 );
133 135 add_filter( 'role_has_cap', array( $this, 'filter_role_caps' ), 10, 3 );
134 136
135 - if ( is_multisite() && is_plugin_active_for_network( $this->plugin->locations['plugin'] ) && ! is_network_admin() ) {
137 + if ( is_multisite() && $plugin->is_network_activated() && ! is_network_admin() ) {
136 138 $options = (array) get_site_option( 'wp_stream_network', array() );
137 139 $option = isset( $options['general_site_access'] ) ? absint( $options['general_site_access'] ) : 1;
138 140
139 141 $this->disable_access = ( $option ) ? false : true;
@@ -151,36 +153,58 @@
151 153 // Add admin body class.
152 154 add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
153 155
154 156 // Plugin action links.
155 - add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2 );
157 + add_filter(
158 + 'plugin_action_links',
159 + array(
160 + $this,
161 + 'plugin_action_links',
162 + ),
163 + 10,
164 + 2
165 + );
156 166
157 167 // Load admin scripts and styles.
158 - add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
168 + add_action(
169 + 'admin_enqueue_scripts',
170 + array(
171 + $this,
172 + 'admin_enqueue_scripts',
173 + )
174 + );
159 175 add_action( 'admin_enqueue_scripts', array( $this, 'admin_menu_css' ) );
160 176
161 177 // Reset Streams database.
162 - add_action( 'wp_ajax_wp_stream_reset', array( $this, 'wp_ajax_reset' ) );
178 + add_action(
179 + 'wp_ajax_wp_stream_reset',
180 + array(
181 + $this,
182 + 'wp_ajax_reset',
183 + )
184 + );
163 185
164 186 // Uninstall Streams and Deactivate plugin.
165 - $uninstall = new Uninstall( $this->plugin );
166 - add_action( 'wp_ajax_wp_stream_uninstall', array( $uninstall, 'uninstall' ) );
187 + $uninstall = $this->plugin->db->driver->purge_storage( $this->plugin );
167 188
168 189 // Auto purge setup.
169 190 add_action( 'wp_loaded', array( $this, 'purge_schedule_setup' ) );
170 - add_action( 'wp_stream_auto_purge', array( $this, 'purge_scheduled_action' ) );
191 + add_action(
192 + 'wp_stream_auto_purge',
193 + array(
194 + $this,
195 + 'purge_scheduled_action',
196 + )
197 + );
171 198
172 199 // Ajax users list.
173 - add_action( 'wp_ajax_wp_stream_filters', array( $this, 'ajax_filters' ) );
174 -
175 - // Ajax user's name by ID.
176 - add_action( 'wp_ajax_wp_stream_get_filter_value_by_id', array( $this, 'get_filter_value_by_id' ) );
177 -
178 - // Ajax users list.
179 - add_action( 'wp_ajax_wp_stream_filters', array( $this, 'ajax_filters' ) );
180 -
181 - // Ajax user's name by ID.
182 - add_action( 'wp_ajax_wp_stream_get_filter_value_by_id', array( $this, 'get_filter_value_by_id' ) );
200 + add_action(
201 + 'wp_ajax_wp_stream_filters',
202 + array(
203 + $this,
204 + 'ajax_filters',
205 + )
206 + );
183 207 }
184 208
185 209 /**
186 210 * Load admin classes
@@ -308,8 +332,16 @@
308 332 $main_menu_position
309 333 );
310 334
311 335 /**
336 + * Fires before submenu items are added to the Stream menu
337 + * allowing plugins to add menu items before Settings
338 + *
339 + * @return void
340 + */
341 + do_action( 'wp_stream_admin_menu' );
342 +
343 + /**
312 344 * Filter the Settings admin page title
313 345 *
314 346 * @return string
315 347 */
@@ -332,9 +364,15 @@
332 364 */
333 365 do_action( 'wp_stream_admin_menu_screens' );
334 366
335 367 // Register the list table early, so it associates the column headers with 'Screen settings'.
336 - add_action( 'load-' . $this->screen_id['main'], array( $this, 'register_list_table' ) );
368 + add_action(
369 + 'load-' . $this->screen_id['main'],
370 + array(
371 + $this,
372 + 'register_list_table',
373 + )
374 + );
337 375 }
338 376 }
339 377
340 378 /**
@@ -346,10 +384,10 @@
346 384 *
347 385 * @return void
348 386 */
349 387 public function admin_enqueue_scripts( $hook ) {
350 - wp_register_script( 'wp-stream-select2', $this->plugin->locations['url'] . 'ui/lib/select2/select2.js', array( 'jquery' ), '3.5.2', true );
351 - wp_register_style( 'wp-stream-select2', $this->plugin->locations['url'] . 'ui/lib/select2/select2.css', array(), '3.5.2' );
388 + wp_register_script( 'wp-stream-select2', $this->plugin->locations['url'] . 'ui/lib/select2/js/select2.full.min.js', array( 'jquery' ), '3.5.2', true );
389 + wp_register_style( 'wp-stream-select2', $this->plugin->locations['url'] . 'ui/lib/select2/css/select2.min.css', array(), '3.5.2' );
352 390 wp_register_script( 'wp-stream-timeago', $this->plugin->locations['url'] . 'ui/lib/timeago/jquery.timeago.js', array(), '1.4.1', true );
353 391
354 392 $locale = strtolower( substr( get_locale(), 0, 2 ) );
355 393 $file_tmpl = 'ui/lib/timeago/locales/jquery.timeago.%s.js';
@@ -359,9 +397,10 @@
359 397 } else {
360 398 wp_register_script( 'wp-stream-timeago-locale', $this->plugin->locations['url'] . sprintf( $file_tmpl, 'en' ), array( 'wp-stream-timeago' ), '1' );
361 399 }
362 400
363 - wp_enqueue_style( 'wp-stream-admin', $this->plugin->locations['url'] . 'ui/css/admin.css', array(), $this->plugin->get_version() );
401 + $min = wp_stream_min_suffix();
402 + wp_enqueue_style( 'wp-stream-admin', $this->plugin->locations['url'] . 'ui/css/admin.' . $min . 'css', array(), $this->plugin->get_version() );
364 403
365 404 $script_screens = array( 'plugins.php' );
366 405
367 406 if ( in_array( $hook, $this->screen_id, true ) || in_array( $hook, $script_screens, true ) ) {
@@ -370,10 +409,35 @@
370 409
371 410 wp_enqueue_script( 'wp-stream-timeago' );
372 411 wp_enqueue_script( 'wp-stream-timeago-locale' );
373 412
374 - wp_enqueue_script( 'wp-stream-admin', $this->plugin->locations['url'] . 'ui/js/admin.js', array( 'jquery', 'wp-stream-select2' ), $this->plugin->get_version() );
375 - wp_enqueue_script( 'wp-stream-live-updates', $this->plugin->locations['url'] . 'ui/js/live-updates.js', array( 'jquery', 'heartbeat' ), $this->plugin->get_version() );
413 + wp_enqueue_script(
414 + 'wp-stream-admin',
415 + $this->plugin->locations['url'] . 'ui/js/admin.' . $min . 'js',
416 + array(
417 + 'jquery',
418 + 'wp-stream-select2',
419 + ),
420 + $this->plugin->get_version()
421 + );
422 + wp_enqueue_script(
423 + 'wp-stream-admin-exclude',
424 + $this->plugin->locations['url'] . 'ui/js/exclude.' . $min . 'js',
425 + array(
426 + 'jquery',
427 + 'wp-stream-select2',
428 + ),
429 + $this->plugin->get_version()
430 + );
431 + wp_enqueue_script(
432 + 'wp-stream-live-updates',
433 + $this->plugin->locations['url'] . 'ui/js/live-updates.' . $min . 'js',
434 + array(
435 + 'jquery',
436 + 'heartbeat',
437 + ),
438 + $this->plugin->get_version()
439 + );
376 440
377 441 wp_localize_script(
378 442 'wp-stream-admin',
379 443 'wp_stream',
@@ -392,12 +456,16 @@
392 456 'wp-stream-live-updates',
393 457 'wp_stream_live_updates',
394 458 array(
395 459 'current_screen' => $hook,
396 - 'current_page' => isset( $_GET['paged'] ) ? esc_js( $_GET['paged'] ) : '1', // input var okay
397 - 'current_order' => isset( $_GET['order'] ) ? esc_js( $_GET['order'] ) : 'desc', // input var okay
398 - 'current_query' => wp_stream_json_encode( $_GET ), // input var okay
399 - 'current_query_count' => count( $_GET ), // input var okay
460 + 'current_page' => isset( $_GET['paged'] ) ? esc_js( $_GET['paged'] ) : '1', // WPCS: CSRF ok.
461 + // input var okay, CSRF okay
462 + 'current_order' => isset( $_GET['order'] ) ? esc_js( $_GET['order'] ) : 'desc', // WPCS: CSRF ok.
463 + // input var okay, CSRF okay
464 + 'current_query' => wp_stream_json_encode( $_GET ), // WPCS: CSRF ok.
465 + // input var okay, CSRF okay
466 + 'current_query_count' => count( $_GET ), // WPCS: CSRF ok.
467 + // input var okay, CSRF okay
400 468 )
401 469 );
402 470 }
403 471
@@ -414,15 +482,16 @@
414 482 * @return int
415 483 */
416 484 $bulk_actions_threshold = apply_filters( 'wp_stream_bulk_actions_threshold', 100 );
417 485
418 - wp_enqueue_script( 'wp-stream-global', $this->plugin->locations['url'] . 'ui/js/global.js', array( 'jquery' ), $this->plugin->get_version() );
486 + wp_enqueue_script( 'wp-stream-global', $this->plugin->locations['url'] . 'ui/js/global.' . $min . 'js', array( 'jquery' ), $this->plugin->get_version() );
419 487 wp_localize_script(
420 488 'wp-stream-global',
421 489 'wp_stream_global',
422 490 array(
423 - 'bulk_actions' => array(
424 - 'i18n' => array(
491 + 'bulk_actions' => array(
492 + 'i18n' => array(
493 + // translators: Placeholder refers to a number of items (e.g. "1,742")
425 494 '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 ) ) ),
426 495 ),
427 496 'threshold' => absint( $bulk_actions_threshold ),
428 497 ),
@@ -440,8 +509,13 @@
440 509 if ( is_admin() && false !== strpos( wp_stream_filter_input( INPUT_GET, 'page' ), $this->records_page_slug ) ) {
441 510 return true;
442 511 }
443 512
513 + $screen = get_current_screen();
514 + if ( is_admin() && Alerts::POST_TYPE === $screen->post_type ) {
515 + return true;
516 + }
517 +
444 518 return false;
445 519 }
446 520
447 521 /**
@@ -458,10 +532,10 @@
458 532
459 533 if ( $this->is_stream_screen() ) {
460 534 $stream_classes[] = $this->admin_body_class;
461 535
462 - if ( isset( $_GET['page'] ) ) {
463 - $stream_classes[] = sanitize_key( $_GET['page'] ); // input var okay
536 + if ( isset( $_GET['page'] ) ) { // CSRF okay
537 + $stream_classes[] = sanitize_key( $_GET['page'] ); // input var okay, CSRF okay
464 538 }
465 539 }
466 540
467 541 /**
@@ -482,9 +556,10 @@
482 556 *
483 557 * @action admin_enqueue_scripts
484 558 */
485 559 public function admin_menu_css() {
486 - wp_register_style( 'wp-stream-datepicker', $this->plugin->locations['url'] . 'ui/css/datepicker.css', array(), $this->plugin->get_version() );
560 + $min = wp_stream_min_suffix();
561 + wp_register_style( 'wp-stream-datepicker', $this->plugin->locations['url'] . 'ui/css/datepicker.' . $min . 'css', array(), $this->plugin->get_version() );
487 562 wp_register_style( 'wp-stream-icons', $this->plugin->locations['url'] . 'ui/stream-icons/style.css', array(), $this->plugin->get_version() );
488 563
489 564 // Make sure we're working off a clean version
490 565 if ( ! file_exists( ABSPATH . WPINC . '/version.php' ) ) {
@@ -489,9 +564,9 @@
489 564 // Make sure we're working off a clean version
490 565 if ( ! file_exists( ABSPATH . WPINC . '/version.php' ) ) {
491 566 return;
492 567 }
493 - include( ABSPATH . WPINC . '/version.php' );
568 + include ABSPATH . WPINC . '/version.php';
494 569
495 570 if ( ! isset( $wp_version ) ) {
496 571 return;
497 572 }
@@ -550,10 +625,15 @@
550 625
551 626 \wp_add_inline_style( 'wp-admin', $css );
552 627 }
553 628
629 + /**
630 + * Handle the reset AJAX request to reset logs.
631 + *
632 + * @return bool
633 + */
554 634 public function wp_ajax_reset() {
555 - check_ajax_referer( 'stream_nonce', 'wp_stream_nonce' );
635 + check_ajax_referer( 'stream_nonce_reset', 'wp_stream_nonce_reset' );
556 636
557 637 if ( ! current_user_can( $this->settings_cap ) ) {
558 638 wp_die(
559 639 esc_html__( "You don't have sufficient privileges to do this action.", 'stream' )
@@ -583,9 +663,9 @@
583 663 global $wpdb;
584 664
585 665 $where = '';
586 666
587 - if ( is_multisite() && ! is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) {
667 + if ( is_multisite() && ! $this->plugin->is_network_activated() ) {
588 668 $where .= $wpdb->prepare( ' AND `blog_id` = %d', get_current_blog_id() );
589 669 }
590 670
591 671 $wpdb->query(
@@ -611,25 +691,26 @@
611 691 is_multisite()
612 692 &&
613 693 is_network_admin()
614 694 &&
615 - ! is_plugin_active_for_network( $this->plugin->locations['plugin'] )
695 + ! $this->plugin->is_network_activated()
616 696 ) {
617 697 return;
618 698 }
619 699
620 - if ( is_multisite() && is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) {
700 + if ( is_multisite() && $this->plugin->is_network_activated() ) {
621 701 $options = (array) get_site_option( 'wp_stream_network', array() );
622 702 } else {
623 703 $options = (array) get_option( 'wp_stream', array() );
624 704 }
625 705
626 - if ( isset( $options['general_keep_records_indefinitely'] ) || ! isset( $options['general_records_ttl'] ) ) {
706 + if ( ! empty( $options['general_keep_records_indefinitely'] ) || ! isset( $options['general_records_ttl'] ) ) {
627 707 return;
628 708 }
629 709
630 - $days = $options['general_records_ttl'];
631 - $date = new DateTime( 'now', $timezone = new DateTimeZone( 'UTC' ) );
710 + $days = $options['general_records_ttl'];
711 + $timezone = new DateTimeZone( 'UTC' );
712 + $date = new DateTime( 'now', $timezone );
632 713
633 714 $date->sub( DateInterval::createFromDateString( "$days days" ) );
634 715
635 716 $where = $wpdb->prepare( ' AND `stream`.`created` < %s', $date->format( 'Y-m-d H:i:s' ) );
@@ -634,9 +715,9 @@
634 715
635 716 $where = $wpdb->prepare( ' AND `stream`.`created` < %s', $date->format( 'Y-m-d H:i:s' ) );
636 717
637 718 // Multisite but NOT network activated, only purge the current blog
638 - if ( is_multisite() && ! is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) {
719 + if ( is_multisite() && ! $this->plugin->is_network_activated() ) {
639 720 $where .= $wpdb->prepare( ' AND `blog_id` = %d', get_current_blog_id() );
640 721 }
641 722
642 723 $wpdb->query(
@@ -648,9 +729,9 @@
648 729 );
649 730 }
650 731
651 732 /**
652 - * @param array $links
733 + * @param array $links
653 734 * @param string $file
654 735 *
655 736 * @filter plugin_action_links
656 737 *
@@ -661,29 +742,41 @@
661 742 return $links;
662 743 }
663 744
664 745 // Also don't show links in Network Admin if Stream isn't network enabled
665 - if ( is_network_admin() && is_multisite() && ! is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) {
746 + if ( is_network_admin() && is_multisite() && ! $this->plugin->is_network_activated() ) {
666 747 return $links;
667 748 }
668 749
669 750 if ( is_network_admin() ) {
670 - $admin_page_url = add_query_arg( array( 'page' => $this->network->network_settings_page_slug ), network_admin_url( $this->admin_parent_page ) );
751 + $admin_page_url = add_query_arg(
752 + array(
753 + 'page' => $this->network->network_settings_page_slug,
754 + ),
755 + network_admin_url( $this->admin_parent_page )
756 + );
671 757 } else {
672 - $admin_page_url = add_query_arg( array( 'page' => $this->settings_page_slug ), admin_url( $this->admin_parent_page ) );
758 + $admin_page_url = add_query_arg(
759 + array(
760 + 'page' => $this->settings_page_slug,
761 + ),
762 + admin_url( $this->admin_parent_page )
763 + );
673 764 }
674 765
675 766 $links[] = sprintf( '<a href="%s">%s</a>', esc_url( $admin_page_url ), esc_html__( 'Settings', 'default' ) );
676 767
677 - $url = add_query_arg(
678 - array(
679 - 'action' => 'wp_stream_uninstall',
680 - 'wp_stream_nonce' => wp_create_nonce( 'stream_nonce' ),
681 - ),
682 - admin_url( 'admin-ajax.php' )
683 - );
768 + if ( ! defined( 'DISALLOW_FILE_MODS' ) || false === DISALLOW_FILE_MODS ) {
769 + $url = add_query_arg(
770 + array(
771 + 'action' => 'wp_stream_uninstall',
772 + 'wp_stream_nonce' => wp_create_nonce( 'stream_nonce' ),
773 + ),
774 + admin_url( 'admin-ajax.php' )
775 + );
684 776
685 - $links[] = sprintf( '<span id="wp_stream_uninstall" class="delete"><a href="%s">%s</a></span>', esc_url( $url ), esc_html__( 'Uninstall', 'stream' ) );
777 + $links[] = sprintf( '<span id="wp_stream_uninstall" class="delete"><a href="%s">%s</a></span>', esc_url( $url ), esc_html__( 'Uninstall', 'stream' ) );
778 + }
686 779
687 780 return $links;
688 781 }
689 782
@@ -693,12 +786,12 @@
693 786 public function render_list_table() {
694 787 $this->list_table->prepare_items();
695 788 ?>
696 789 <div class="wrap">
697 - <h1><?php echo esc_html( get_admin_page_title() ) ?></h1>
698 - <?php $this->list_table->display() ?>
790 + <h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
791 + <?php $this->list_table->display(); ?>
699 792 </div>
700 - <?php
793 + <?php
701 794 }
702 795
703 796 /**
704 797 * Render settings page
@@ -710,28 +803,28 @@
710 803 $page_description = apply_filters( 'wp_stream_settings_form_description', '' );
711 804
712 805 $sections = $this->plugin->settings->get_fields();
713 806 $active_tab = wp_stream_filter_input( INPUT_GET, 'tab' );
714 -
715 - wp_enqueue_script( 'wp-stream-settings', $this->plugin->locations['url'] . 'ui/js/settings.js', array( 'jquery' ), $this->plugin->get_version(), true );
807 + $min = wp_stream_min_suffix();
808 + wp_enqueue_script( 'wp-stream-settings', $this->plugin->locations['url'] . 'ui/js/settings.' . $min . 'js', array( 'jquery' ), $this->plugin->get_version(), true );
716 809 ?>
717 810 <div class="wrap">
718 - <h1><?php echo esc_html( get_admin_page_title() ) ?></h1>
811 + <h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
719 812
720 813 <?php if ( ! empty( $page_description ) ) : ?>
721 - <p><?php echo esc_html( $page_description ) ?></p>
814 + <p><?php echo esc_html( $page_description ); ?></p>
722 815 <?php endif; ?>
723 816
724 - <?php settings_errors() ?>
817 + <?php settings_errors(); ?>
725 818
726 819 <?php if ( count( $sections ) > 1 ) : ?>
727 820 <h2 class="nav-tab-wrapper">
728 - <?php $i = 0 ?>
821 + <?php $i = 0; ?>
729 822 <?php foreach ( $sections as $section => $data ) : ?>
730 - <?php $i ++ ?>
731 - <?php $is_active = ( ( 1 === $i && ! $active_tab ) || $active_tab === $section ) ?>
732 - <a href="<?php echo esc_url( add_query_arg( 'tab', $section ) ) ?>" class="nav-tab<?php if ( $is_active ) { echo esc_attr( ' nav-tab-active' ); } ?>">
733 - <?php echo esc_html( $data['title'] ) ?>
823 + <?php $i++; ?>
824 + <?php $is_active = ( ( 1 === $i && ! $active_tab ) || $active_tab === $section ); ?>
825 + <a href="<?php echo esc_url( add_query_arg( 'tab', $section ) ); ?>" class="nav-tab <?php echo $is_active ? esc_attr( ' nav-tab-active' ) : ''; ?>">
826 + <?php echo esc_html( $data['title'] ); ?>
734 827 </a>
735 828 <?php endforeach; ?>
736 829 </h2>
737 830 <?php endif; ?>
@@ -736,29 +829,29 @@
736 829 </h2>
737 830 <?php endif; ?>
738 831
739 832 <div class="nav-tab-content" id="tab-content-settings">
740 - <form method="post" action="<?php echo esc_attr( $form_action ) ?>" enctype="multipart/form-data">
833 + <form method="post" action="<?php echo esc_attr( $form_action ); ?>" enctype="multipart/form-data">
741 834 <div class="settings-sections">
742 - <?php
743 - $i = 0;
744 - foreach ( $sections as $section => $data ) {
745 - $i++;
835 + <?php
836 + $i = 0;
837 + foreach ( $sections as $section => $data ) {
838 + $i++;
746 839
747 - $is_active = ( ( 1 === $i && ! $active_tab ) || $active_tab === $section );
840 + $is_active = ( ( 1 === $i && ! $active_tab ) || $active_tab === $section );
748 841
749 - if ( $is_active ) {
750 - settings_fields( $option_key );
751 - do_settings_sections( $option_key );
752 - }
753 - }
754 - ?>
842 + if ( $is_active ) {
843 + settings_fields( $option_key );
844 + do_settings_sections( $option_key );
845 + }
846 + }
847 + ?>
755 848 </div>
756 - <?php submit_button() ?>
849 + <?php submit_button(); ?>
757 850 </form>
758 851 </div>
759 852 </div>
760 - <?php
853 + <?php
761 854 }
762 855
763 856 /**
764 857 * Instantiate the list table
@@ -763,9 +856,14 @@
763 856 /**
764 857 * Instantiate the list table
765 858 */
766 859 public function register_list_table() {
767 - $this->list_table = new List_Table( $this->plugin, array( 'screen' => $this->screen_id['main'] ) );
860 + $this->list_table = new List_Table(
861 + $this->plugin,
862 + array(
863 + 'screen' => $this->screen_id['main'],
864 + )
865 + );
768 866 }
769 867
770 868 /**
771 869 * Check if a particular role has access
@@ -854,12 +952,22 @@
854 952 /**
855 953 * @action wp_ajax_wp_stream_filters
856 954 */
857 955 public function ajax_filters() {
956 + if ( ! defined( 'DOING_AJAX' ) || ! current_user_can( $this->plugin->admin->settings_cap ) ) {
957 + wp_die( '-1' );
958 + }
959 +
960 + check_ajax_referer( 'stream_filters_user_search_nonce', 'nonce' );
961 +
858 962 switch ( wp_stream_filter_input( INPUT_GET, 'filter' ) ) {
859 963 case 'user_id':
860 964 $users = array_merge(
861 - array( 0 => (object) array( 'display_name' => 'WP-CLI' ) ),
965 + array(
966 + 0 => (object) array(
967 + 'display_name' => 'WP-CLI',
968 + ),
969 + ),
862 970 get_users()
863 971 );
864 972
865 973 $search = wp_stream_filter_input( INPUT_GET, 'q' );
@@ -866,9 +974,9 @@
866 974 if ( $search ) {
867 975 // `search` arg for get_users() is not enough
868 976 $users = array_filter(
869 977 $users,
870 - function( $user ) use ( $search ) {
978 + function ( $user ) use ( $search ) {
871 979 return false !== mb_strpos( mb_strtolower( $user->display_name ), mb_strtolower( $search ) );
872 980 }
873 981 );
874 982 }
@@ -883,68 +991,26 @@
883 991 break;
884 992 }
885 993
886 994 if ( isset( $results ) ) {
887 - echo wp_stream_json_encode( array_values( $results ) ); // xss ok
995 + echo wp_stream_json_encode( $results ); // xss ok
888 996 }
889 997
890 - if ( defined( 'WP_STREAM_TESTS' ) && WP_STREAM_TESTS ) {
891 - return;
892 - }
893 -
894 998 die();
895 999 }
896 1000
897 - /**
898 - * @action wp_ajax_wp_stream_get_filter_value_by_id
899 - */
900 - public function get_filter_value_by_id() {
901 - $filter = wp_stream_filter_input( INPUT_POST, 'filter' );
902 -
903 - switch ( $filter ) {
904 - case 'user_id':
905 - $id = wp_stream_filter_input( INPUT_POST, 'id' );
906 -
907 - if ( '0' === $id ) {
908 - $value = 'WP-CLI';
909 -
910 - break;
911 - }
912 -
913 - $user = get_userdata( $id );
914 -
915 - if ( ! $user || is_wp_error( $user ) ) {
916 - $value = '';
917 - } else {
918 - $value = $user->display_name;
919 - }
920 -
921 - break;
922 - default:
923 - $value = '';
924 - }
925 -
926 - echo wp_stream_json_encode( $value ); // xss ok
927 -
928 - if ( defined( 'WP_STREAM_TESTS' ) && WP_STREAM_TESTS ) {
929 - return;
930 - }
931 -
932 - die();
933 - }
934 -
935 1001 public function get_users_record_meta( $authors ) {
936 1002 $authors_records = array();
937 1003
938 1004 foreach ( $authors as $user_id => $args ) {
939 - $author = new Author( $user_id );
1005 + $author = new Author( $args->ID );
940 1006
941 1007 $authors_records[ $user_id ] = array(
942 - 'text' => $author->get_display_name(),
943 - 'id' => $user_id,
944 - 'label' => $author->get_display_name(),
945 - 'icon' => $author->get_avatar_src( 32 ),
946 - 'title' => '',
1008 + 'text' => $author->get_display_name(),
1009 + 'id' => $author->id,
1010 + 'label' => $author->get_display_name(),
1011 + 'icon' => $author->get_avatar_src( 32 ),
1012 + 'title' => '',
947 1013 );
948 1014 }
949 1015
950 1016 return $authors_records;
@@ -952,18 +1018,19 @@
952 1018
953 1019 /**
954 1020 * Get user meta in a way that is also safe for VIP
955 1021 *
956 - * @param int $user_id
1022 + * @param int $user_id
957 1023 * @param string $meta_key
958 - * @param bool $single (optional)
1024 + * @param bool $single (optional)
959 1025 *
960 1026 * @return mixed
961 1027 */
962 - function get_user_meta( $user_id, $meta_key, $single = true ) {
1028 + public function get_user_meta( $user_id, $meta_key, $single = true ) {
963 1029 if ( wp_stream_is_vip() && function_exists( 'get_user_attribute' ) ) {
964 1030 return get_user_attribute( $user_id, $meta_key );
965 1031 }
1032 +
966 1033 return get_user_meta( $user_id, $meta_key, $single );
967 1034 }
968 1035
969 1036 /**
@@ -968,19 +1035,20 @@
968 1035
969 1036 /**
970 1037 * Update user meta in a way that is also safe for VIP
971 1038 *
972 - * @param int $user_id
1039 + * @param int $user_id
973 1040 * @param string $meta_key
974 1041 * @param mixed $meta_value
975 - * @param mixed $prev_value (optional)
1042 + * @param mixed $prev_value (optional)
976 1043 *
977 1044 * @return int|bool
978 1045 */
979 - function update_user_meta( $user_id, $meta_key, $meta_value, $prev_value = '' ) {
1046 + public function update_user_meta( $user_id, $meta_key, $meta_value, $prev_value = '' ) {
980 1047 if ( wp_stream_is_vip() && function_exists( 'update_user_attribute' ) ) {
981 1048 return update_user_attribute( $user_id, $meta_key, $meta_value );
982 1049 }
1050 +
983 1051 return update_user_meta( $user_id, $meta_key, $meta_value, $prev_value );
984 1052 }
985 1053
986 1054 /**
@@ -985,17 +1053,18 @@
985 1053
986 1054 /**
987 1055 * Delete user meta in a way that is also safe for VIP
988 1056 *
989 - * @param int $user_id
1057 + * @param int $user_id
990 1058 * @param string $meta_key
991 - * @param mixed $meta_value (optional)
1059 + * @param mixed $meta_value (optional)
992 1060 *
993 1061 * @return bool
994 1062 */
995 - function delete_user_meta( $user_id, $meta_key, $meta_value = '' ) {
1063 + public function delete_user_meta( $user_id, $meta_key, $meta_value = '' ) {
996 1064 if ( wp_stream_is_vip() && function_exists( 'delete_user_attribute' ) ) {
997 1065 return delete_user_attribute( $user_id, $meta_key, $meta_value );
998 1066 }
1067 +
999 1068 return delete_user_meta( $user_id, $meta_key, $meta_value );
1000 1069 }
1001 1070 }