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 +204 -90 3.0.63.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,27 +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' ) );
200 + add_action(
201 + 'wp_ajax_wp_stream_filters',
202 + array(
203 + $this,
204 + 'ajax_filters',
205 + )
206 + );
174 207 }
175 208
176 209 /**
177 210 * Load admin classes
@@ -299,8 +332,16 @@
299 332 $main_menu_position
300 333 );
301 334
302 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 + /**
303 344 * Filter the Settings admin page title
304 345 *
305 346 * @return string
306 347 */
@@ -323,9 +364,15 @@
323 364 */
324 365 do_action( 'wp_stream_admin_menu_screens' );
325 366
326 367 // Register the list table early, so it associates the column headers with 'Screen settings'.
327 - 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 + );
328 375 }
329 376 }
330 377
331 378 /**
@@ -337,10 +384,10 @@
337 384 *
338 385 * @return void
339 386 */
340 387 public function admin_enqueue_scripts( $hook ) {
341 - wp_register_script( 'wp-stream-select2', $this->plugin->locations['url'] . 'ui/lib/select2/js/select2.js', array( 'jquery' ), '3.5.2', true );
342 - wp_register_style( 'wp-stream-select2', $this->plugin->locations['url'] . 'ui/lib/select2/css/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' );
343 390 wp_register_script( 'wp-stream-timeago', $this->plugin->locations['url'] . 'ui/lib/timeago/jquery.timeago.js', array(), '1.4.1', true );
344 391
345 392 $locale = strtolower( substr( get_locale(), 0, 2 ) );
346 393 $file_tmpl = 'ui/lib/timeago/locales/jquery.timeago.%s.js';
@@ -350,9 +397,10 @@
350 397 } else {
351 398 wp_register_script( 'wp-stream-timeago-locale', $this->plugin->locations['url'] . sprintf( $file_tmpl, 'en' ), array( 'wp-stream-timeago' ), '1' );
352 399 }
353 400
354 - 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() );
355 403
356 404 $script_screens = array( 'plugins.php' );
357 405
358 406 if ( in_array( $hook, $this->screen_id, true ) || in_array( $hook, $script_screens, true ) ) {
@@ -361,10 +409,35 @@
361 409
362 410 wp_enqueue_script( 'wp-stream-timeago' );
363 411 wp_enqueue_script( 'wp-stream-timeago-locale' );
364 412
365 - wp_enqueue_script( 'wp-stream-admin', $this->plugin->locations['url'] . 'ui/js/admin.js', array( 'jquery', 'wp-stream-select2' ), $this->plugin->get_version() );
366 - 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 + );
367 440
368 441 wp_localize_script(
369 442 'wp-stream-admin',
370 443 'wp_stream',
@@ -383,12 +456,16 @@
383 456 'wp-stream-live-updates',
384 457 'wp_stream_live_updates',
385 458 array(
386 459 'current_screen' => $hook,
387 - 'current_page' => isset( $_GET['paged'] ) ? esc_js( $_GET['paged'] ) : '1', // input var okay
388 - 'current_order' => isset( $_GET['order'] ) ? esc_js( $_GET['order'] ) : 'desc', // input var okay
389 - 'current_query' => wp_stream_json_encode( $_GET ), // input var okay
390 - '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
391 468 )
392 469 );
393 470 }
394 471
@@ -405,15 +482,16 @@
405 482 * @return int
406 483 */
407 484 $bulk_actions_threshold = apply_filters( 'wp_stream_bulk_actions_threshold', 100 );
408 485
409 - 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() );
410 487 wp_localize_script(
411 488 'wp-stream-global',
412 489 'wp_stream_global',
413 490 array(
414 - 'bulk_actions' => array(
415 - 'i18n' => array(
491 + 'bulk_actions' => array(
492 + 'i18n' => array(
493 + // translators: Placeholder refers to a number of items (e.g. "1,742")
416 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 ) ) ),
417 495 ),
418 496 'threshold' => absint( $bulk_actions_threshold ),
419 497 ),
@@ -431,8 +509,13 @@
431 509 if ( is_admin() && false !== strpos( wp_stream_filter_input( INPUT_GET, 'page' ), $this->records_page_slug ) ) {
432 510 return true;
433 511 }
434 512
513 + $screen = get_current_screen();
514 + if ( is_admin() && Alerts::POST_TYPE === $screen->post_type ) {
515 + return true;
516 + }
517 +
435 518 return false;
436 519 }
437 520
438 521 /**
@@ -449,10 +532,10 @@
449 532
450 533 if ( $this->is_stream_screen() ) {
451 534 $stream_classes[] = $this->admin_body_class;
452 535
453 - if ( isset( $_GET['page'] ) ) {
454 - $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
455 538 }
456 539 }
457 540
458 541 /**
@@ -473,9 +556,10 @@
473 556 *
474 557 * @action admin_enqueue_scripts
475 558 */
476 559 public function admin_menu_css() {
477 - 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() );
478 562 wp_register_style( 'wp-stream-icons', $this->plugin->locations['url'] . 'ui/stream-icons/style.css', array(), $this->plugin->get_version() );
479 563
480 564 // Make sure we're working off a clean version
481 565 if ( ! file_exists( ABSPATH . WPINC . '/version.php' ) ) {
@@ -480,9 +564,9 @@
480 564 // Make sure we're working off a clean version
481 565 if ( ! file_exists( ABSPATH . WPINC . '/version.php' ) ) {
482 566 return;
483 567 }
484 - include( ABSPATH . WPINC . '/version.php' );
568 + include ABSPATH . WPINC . '/version.php';
485 569
486 570 if ( ! isset( $wp_version ) ) {
487 571 return;
488 572 }
@@ -541,10 +625,15 @@
541 625
542 626 \wp_add_inline_style( 'wp-admin', $css );
543 627 }
544 628
629 + /**
630 + * Handle the reset AJAX request to reset logs.
631 + *
632 + * @return bool
633 + */
545 634 public function wp_ajax_reset() {
546 - check_ajax_referer( 'stream_nonce', 'wp_stream_nonce' );
635 + check_ajax_referer( 'stream_nonce_reset', 'wp_stream_nonce_reset' );
547 636
548 637 if ( ! current_user_can( $this->settings_cap ) ) {
549 638 wp_die(
550 639 esc_html__( "You don't have sufficient privileges to do this action.", 'stream' )
@@ -574,9 +663,9 @@
574 663 global $wpdb;
575 664
576 665 $where = '';
577 666
578 - if ( is_multisite() && ! is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) {
667 + if ( is_multisite() && ! $this->plugin->is_network_activated() ) {
579 668 $where .= $wpdb->prepare( ' AND `blog_id` = %d', get_current_blog_id() );
580 669 }
581 670
582 671 $wpdb->query(
@@ -602,25 +691,26 @@
602 691 is_multisite()
603 692 &&
604 693 is_network_admin()
605 694 &&
606 - ! is_plugin_active_for_network( $this->plugin->locations['plugin'] )
695 + ! $this->plugin->is_network_activated()
607 696 ) {
608 697 return;
609 698 }
610 699
611 - if ( is_multisite() && is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) {
700 + if ( is_multisite() && $this->plugin->is_network_activated() ) {
612 701 $options = (array) get_site_option( 'wp_stream_network', array() );
613 702 } else {
614 703 $options = (array) get_option( 'wp_stream', array() );
615 704 }
616 705
617 - 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'] ) ) {
618 707 return;
619 708 }
620 709
621 - $days = $options['general_records_ttl'];
622 - $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 );
623 713
624 714 $date->sub( DateInterval::createFromDateString( "$days days" ) );
625 715
626 716 $where = $wpdb->prepare( ' AND `stream`.`created` < %s', $date->format( 'Y-m-d H:i:s' ) );
@@ -625,9 +715,9 @@
625 715
626 716 $where = $wpdb->prepare( ' AND `stream`.`created` < %s', $date->format( 'Y-m-d H:i:s' ) );
627 717
628 718 // Multisite but NOT network activated, only purge the current blog
629 - if ( is_multisite() && ! is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) {
719 + if ( is_multisite() && ! $this->plugin->is_network_activated() ) {
630 720 $where .= $wpdb->prepare( ' AND `blog_id` = %d', get_current_blog_id() );
631 721 }
632 722
633 723 $wpdb->query(
@@ -639,9 +729,9 @@
639 729 );
640 730 }
641 731
642 732 /**
643 - * @param array $links
733 + * @param array $links
644 734 * @param string $file
645 735 *
646 736 * @filter plugin_action_links
647 737 *
@@ -652,29 +742,41 @@
652 742 return $links;
653 743 }
654 744
655 745 // Also don't show links in Network Admin if Stream isn't network enabled
656 - 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() ) {
657 747 return $links;
658 748 }
659 749
660 750 if ( is_network_admin() ) {
661 - $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 + );
662 757 } else {
663 - $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 + );
664 764 }
665 765
666 766 $links[] = sprintf( '<a href="%s">%s</a>', esc_url( $admin_page_url ), esc_html__( 'Settings', 'default' ) );
667 767
668 - $url = add_query_arg(
669 - array(
670 - 'action' => 'wp_stream_uninstall',
671 - 'wp_stream_nonce' => wp_create_nonce( 'stream_nonce' ),
672 - ),
673 - admin_url( 'admin-ajax.php' )
674 - );
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 + );
675 776
676 - $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 + }
677 779
678 780 return $links;
679 781 }
680 782
@@ -684,12 +786,12 @@
684 786 public function render_list_table() {
685 787 $this->list_table->prepare_items();
686 788 ?>
687 789 <div class="wrap">
688 - <h1><?php echo esc_html( get_admin_page_title() ) ?></h1>
689 - <?php $this->list_table->display() ?>
790 + <h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
791 + <?php $this->list_table->display(); ?>
690 792 </div>
691 - <?php
793 + <?php
692 794 }
693 795
694 796 /**
695 797 * Render settings page
@@ -701,28 +803,28 @@
701 803 $page_description = apply_filters( 'wp_stream_settings_form_description', '' );
702 804
703 805 $sections = $this->plugin->settings->get_fields();
704 806 $active_tab = wp_stream_filter_input( INPUT_GET, 'tab' );
705 -
706 - 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 );
707 809 ?>
708 810 <div class="wrap">
709 - <h1><?php echo esc_html( get_admin_page_title() ) ?></h1>
811 + <h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
710 812
711 813 <?php if ( ! empty( $page_description ) ) : ?>
712 - <p><?php echo esc_html( $page_description ) ?></p>
814 + <p><?php echo esc_html( $page_description ); ?></p>
713 815 <?php endif; ?>
714 816
715 - <?php settings_errors() ?>
817 + <?php settings_errors(); ?>
716 818
717 819 <?php if ( count( $sections ) > 1 ) : ?>
718 820 <h2 class="nav-tab-wrapper">
719 - <?php $i = 0 ?>
821 + <?php $i = 0; ?>
720 822 <?php foreach ( $sections as $section => $data ) : ?>
721 - <?php $i ++ ?>
722 - <?php $is_active = ( ( 1 === $i && ! $active_tab ) || $active_tab === $section ) ?>
723 - <a href="<?php echo esc_url( add_query_arg( 'tab', $section ) ) ?>" class="nav-tab<?php if ( $is_active ) { echo esc_attr( ' nav-tab-active' ); } ?>">
724 - <?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'] ); ?>
725 827 </a>
726 828 <?php endforeach; ?>
727 829 </h2>
728 830 <?php endif; ?>
@@ -727,29 +829,29 @@
727 829 </h2>
728 830 <?php endif; ?>
729 831
730 832 <div class="nav-tab-content" id="tab-content-settings">
731 - <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">
732 834 <div class="settings-sections">
733 - <?php
734 - $i = 0;
735 - foreach ( $sections as $section => $data ) {
736 - $i++;
835 + <?php
836 + $i = 0;
837 + foreach ( $sections as $section => $data ) {
838 + $i++;
737 839
738 - $is_active = ( ( 1 === $i && ! $active_tab ) || $active_tab === $section );
840 + $is_active = ( ( 1 === $i && ! $active_tab ) || $active_tab === $section );
739 841
740 - if ( $is_active ) {
741 - settings_fields( $option_key );
742 - do_settings_sections( $option_key );
743 - }
744 - }
745 - ?>
842 + if ( $is_active ) {
843 + settings_fields( $option_key );
844 + do_settings_sections( $option_key );
845 + }
846 + }
847 + ?>
746 848 </div>
747 - <?php submit_button() ?>
849 + <?php submit_button(); ?>
748 850 </form>
749 851 </div>
750 852 </div>
751 - <?php
853 + <?php
752 854 }
753 855
754 856 /**
755 857 * Instantiate the list table
@@ -754,9 +856,14 @@
754 856 /**
755 857 * Instantiate the list table
756 858 */
757 859 public function register_list_table() {
758 - $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 + );
759 866 }
760 867
761 868 /**
762 869 * Check if a particular role has access
@@ -854,9 +961,13 @@
854 961
855 962 switch ( wp_stream_filter_input( INPUT_GET, 'filter' ) ) {
856 963 case 'user_id':
857 964 $users = array_merge(
858 - array( 0 => (object) array( 'display_name' => 'WP-CLI' ) ),
965 + array(
966 + 0 => (object) array(
967 + 'display_name' => 'WP-CLI',
968 + ),
969 + ),
859 970 get_users()
860 971 );
861 972
862 973 $search = wp_stream_filter_input( INPUT_GET, 'q' );
@@ -863,9 +974,9 @@
863 974 if ( $search ) {
864 975 // `search` arg for get_users() is not enough
865 976 $users = array_filter(
866 977 $users,
867 - function( $user ) use ( $search ) {
978 + function ( $user ) use ( $search ) {
868 979 return false !== mb_strpos( mb_strtolower( $user->display_name ), mb_strtolower( $search ) );
869 980 }
870 981 );
871 982 }
@@ -893,13 +1004,13 @@
893 1004 foreach ( $authors as $user_id => $args ) {
894 1005 $author = new Author( $args->ID );
895 1006
896 1007 $authors_records[ $user_id ] = array(
897 - 'text' => $author->get_display_name(),
898 - 'id' => $author->id,
899 - 'label' => $author->get_display_name(),
900 - 'icon' => $author->get_avatar_src( 32 ),
901 - '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' => '',
902 1013 );
903 1014 }
904 1015
905 1016 return $authors_records;
@@ -907,18 +1018,19 @@
907 1018
908 1019 /**
909 1020 * Get user meta in a way that is also safe for VIP
910 1021 *
911 - * @param int $user_id
1022 + * @param int $user_id
912 1023 * @param string $meta_key
913 - * @param bool $single (optional)
1024 + * @param bool $single (optional)
914 1025 *
915 1026 * @return mixed
916 1027 */
917 - function get_user_meta( $user_id, $meta_key, $single = true ) {
1028 + public function get_user_meta( $user_id, $meta_key, $single = true ) {
918 1029 if ( wp_stream_is_vip() && function_exists( 'get_user_attribute' ) ) {
919 1030 return get_user_attribute( $user_id, $meta_key );
920 1031 }
1032 +
921 1033 return get_user_meta( $user_id, $meta_key, $single );
922 1034 }
923 1035
924 1036 /**
@@ -923,19 +1035,20 @@
923 1035
924 1036 /**
925 1037 * Update user meta in a way that is also safe for VIP
926 1038 *
927 - * @param int $user_id
1039 + * @param int $user_id
928 1040 * @param string $meta_key
929 1041 * @param mixed $meta_value
930 - * @param mixed $prev_value (optional)
1042 + * @param mixed $prev_value (optional)
931 1043 *
932 1044 * @return int|bool
933 1045 */
934 - 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 = '' ) {
935 1047 if ( wp_stream_is_vip() && function_exists( 'update_user_attribute' ) ) {
936 1048 return update_user_attribute( $user_id, $meta_key, $meta_value );
937 1049 }
1050 +
938 1051 return update_user_meta( $user_id, $meta_key, $meta_value, $prev_value );
939 1052 }
940 1053
941 1054 /**
@@ -940,17 +1053,18 @@
940 1053
941 1054 /**
942 1055 * Delete user meta in a way that is also safe for VIP
943 1056 *
944 - * @param int $user_id
1057 + * @param int $user_id
945 1058 * @param string $meta_key
946 - * @param mixed $meta_value (optional)
1059 + * @param mixed $meta_value (optional)
947 1060 *
948 1061 * @return bool
949 1062 */
950 - function delete_user_meta( $user_id, $meta_key, $meta_value = '' ) {
1063 + public function delete_user_meta( $user_id, $meta_key, $meta_value = '' ) {
951 1064 if ( wp_stream_is_vip() && function_exists( 'delete_user_attribute' ) ) {
952 1065 return delete_user_attribute( $user_id, $meta_key, $meta_value );
953 1066 }
1067 +
954 1068 return delete_user_meta( $user_id, $meta_key, $meta_value );
955 1069 }
956 1070 }