PluginProbe
Stream – Activity Log & Audit Trail / 3.9.2
Stream – Activity Log & Audit Trail v3.9.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 +294 -120 3.0.63.9.2 View file →
@@ -1,5 +1,11 @@
1 1 <?php
2 +/**
3 + * Centralized manager for WordPress backend functionality.
4 + *
5 + * @package WP_Stream
6 + */
7 +
2 8 namespace WP_Stream;
3 9
4 10 use DateTime;
5 11 use DateTimeZone;
@@ -6,11 +12,15 @@
6 12 use DateInterval;
7 13 use \WP_CLI;
8 14 use \WP_Roles;
9 15
16 +/**
17 + * Class - Admin
18 + */
10 19 class Admin {
20 +
11 21 /**
12 - * Hold Plugin class
22 + * Holds Instance of plugin object
13 23 *
14 24 * @var Plugin
15 25 */
16 26 public $plugin;
@@ -115,9 +125,9 @@
115 125
116 126 /**
117 127 * Class constructor.
118 128 *
119 - * @param Plugin $plugin The main Plugin class.
129 + * @param Plugin $plugin Instance of plugin object.
120 130 */
121 131 public function __construct( $plugin ) {
122 132 $this->plugin = $plugin;
123 133
@@ -124,9 +134,9 @@
124 134 add_action( 'init', array( $this, 'init' ) );
125 135
126 136 // Ensure function used in various methods is pre-loaded.
127 137 if ( ! function_exists( 'is_plugin_active_for_network' ) ) {
128 - require_once( ABSPATH . '/wp-admin/includes/plugin.php' );
138 + require_once ABSPATH . '/wp-admin/includes/plugin.php';
129 139 }
130 140
131 141 // User and role caps.
132 142 add_filter( 'user_has_cap', array( $this, 'filter_user_caps' ), 10, 4 );
@@ -131,9 +141,9 @@
131 141 // User and role caps.
132 142 add_filter( 'user_has_cap', array( $this, 'filter_user_caps' ), 10, 4 );
133 143 add_filter( 'role_has_cap', array( $this, 'filter_role_caps' ), 10, 3 );
134 144
135 - 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() ) {
136 146 $options = (array) get_site_option( 'wp_stream_network', array() );
137 147 $option = isset( $options['general_site_access'] ) ? absint( $options['general_site_access'] ) : 1;
138 148
139 149 $this->disable_access = ( $option ) ? false : true;
@@ -151,27 +161,62 @@
151 161 // Add admin body class.
152 162 add_filter( 'admin_body_class', array( $this, 'admin_body_class' ) );
153 163
154 164 // Plugin action links.
155 - add_filter( 'plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2 );
165 + add_filter(
166 + 'plugin_action_links',
167 + array(
168 + $this,
169 + 'plugin_action_links',
170 + ),
171 + 10,
172 + 2
173 + );
156 174
157 175 // Load admin scripts and styles.
158 - add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) );
176 + add_action(
177 + 'admin_enqueue_scripts',
178 + array(
179 + $this,
180 + 'admin_enqueue_scripts',
181 + )
182 + );
159 183 add_action( 'admin_enqueue_scripts', array( $this, 'admin_menu_css' ) );
160 184
161 185 // Reset Streams database.
162 - add_action( 'wp_ajax_wp_stream_reset', array( $this, 'wp_ajax_reset' ) );
186 + add_action(
187 + 'wp_ajax_wp_stream_reset',
188 + array(
189 + $this,
190 + 'wp_ajax_reset',
191 + )
192 + );
163 193
164 - // Uninstall Streams and Deactivate plugin.
165 - $uninstall = new Uninstall( $this->plugin );
166 - add_action( 'wp_ajax_wp_stream_uninstall', array( $uninstall, 'uninstall' ) );
194 + /**
195 + * Uninstall Streams and Deactivate plugin.
196 + *
197 + * @todo Confirm if variable assignment is necessary.
198 + */
199 + $uninstall = $this->plugin->db->driver->purge_storage( $this->plugin );
167 200
168 201 // Auto purge setup.
169 202 add_action( 'wp_loaded', array( $this, 'purge_schedule_setup' ) );
170 - add_action( 'wp_stream_auto_purge', array( $this, 'purge_scheduled_action' ) );
203 + add_action(
204 + 'wp_stream_auto_purge',
205 + array(
206 + $this,
207 + 'purge_scheduled_action',
208 + )
209 + );
171 210
172 211 // Ajax users list.
173 - add_action( 'wp_ajax_wp_stream_filters', array( $this, 'ajax_filters' ) );
212 + add_action(
213 + 'wp_ajax_wp_stream_filters',
214 + array(
215 + $this,
216 + 'ajax_filters',
217 + )
218 + );
174 219 }
175 220
176 221 /**
177 222 * Load admin classes
@@ -208,9 +253,9 @@
208 253 * @param bool $is_error If the message is error_level (true) or warning (false).
209 254 */
210 255 public function notice( $message, $is_error = true ) {
211 256 if ( defined( 'WP_CLI' ) && WP_CLI ) {
212 - $message = strip_tags( $message );
257 + $message = wp_strip_all_tags( $message );
213 258
214 259 if ( $is_error ) {
215 260 WP_CLI::warning( $message );
216 261 } else {
@@ -299,8 +344,16 @@
299 344 $main_menu_position
300 345 );
301 346
302 347 /**
348 + * Fires before submenu items are added to the Stream menu
349 + * allowing plugins to add menu items before Settings
350 + *
351 + * @return void
352 + */
353 + do_action( 'wp_stream_admin_menu' );
354 +
355 + /**
303 356 * Filter the Settings admin page title
304 357 *
305 358 * @return string
306 359 */
@@ -323,9 +376,15 @@
323 376 */
324 377 do_action( 'wp_stream_admin_menu_screens' );
325 378
326 379 // 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' ) );
380 + add_action(
381 + 'load-' . $this->screen_id['main'],
382 + array(
383 + $this,
384 + 'register_list_table',
385 + )
386 + );
328 387 }
329 388 }
330 389
331 390 /**
@@ -332,15 +391,15 @@
332 391 * Enqueue scripts/styles for admin screen
333 392 *
334 393 * @action admin_enqueue_scripts
335 394 *
336 - * @param string $hook
395 + * @param string $hook Current hook.
337 396 *
338 397 * @return void
339 398 */
340 399 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' );
400 + wp_register_script( 'wp-stream-select2', $this->plugin->locations['url'] . 'ui/lib/select2/js/select2.full.min.js', array( 'jquery' ), '3.5.2', true );
401 + wp_register_style( 'wp-stream-select2', $this->plugin->locations['url'] . 'ui/lib/select2/css/select2.min.css', array(), '3.5.2' );
343 402 wp_register_script( 'wp-stream-timeago', $this->plugin->locations['url'] . 'ui/lib/timeago/jquery.timeago.js', array(), '1.4.1', true );
344 403
345 404 $locale = strtolower( substr( get_locale(), 0, 2 ) );
346 405 $file_tmpl = 'ui/lib/timeago/locales/jquery.timeago.%s.js';
@@ -345,14 +404,27 @@
345 404 $locale = strtolower( substr( get_locale(), 0, 2 ) );
346 405 $file_tmpl = 'ui/lib/timeago/locales/jquery.timeago.%s.js';
347 406
348 407 if ( file_exists( $this->plugin->locations['dir'] . sprintf( $file_tmpl, $locale ) ) ) {
349 - wp_register_script( 'wp-stream-timeago-locale', $this->plugin->locations['url'] . sprintf( $file_tmpl, $locale ), array( 'wp-stream-timeago' ), '1' );
408 + wp_register_script(
409 + 'wp-stream-timeago-locale',
410 + $this->plugin->locations['url'] . sprintf( $file_tmpl, $locale ),
411 + array( 'wp-stream-timeago' ),
412 + '1',
413 + false
414 + );
350 415 } else {
351 - wp_register_script( 'wp-stream-timeago-locale', $this->plugin->locations['url'] . sprintf( $file_tmpl, 'en' ), array( 'wp-stream-timeago' ), '1' );
416 + wp_register_script(
417 + 'wp-stream-timeago-locale',
418 + $this->plugin->locations['url'] . sprintf( $file_tmpl, 'en' ),
419 + array( 'wp-stream-timeago' ),
420 + '1',
421 + false
422 + );
352 423 }
353 424
354 - wp_enqueue_style( 'wp-stream-admin', $this->plugin->locations['url'] . 'ui/css/admin.css', array(), $this->plugin->get_version() );
425 + $min = wp_stream_min_suffix();
426 + wp_enqueue_style( 'wp-stream-admin', $this->plugin->locations['url'] . 'ui/css/admin.' . $min . 'css', array(), $this->plugin->get_version() );
355 427
356 428 $script_screens = array( 'plugins.php' );
357 429
358 430 if ( in_array( $hook, $this->screen_id, true ) || in_array( $hook, $script_screens, true ) ) {
@@ -361,10 +433,38 @@
361 433
362 434 wp_enqueue_script( 'wp-stream-timeago' );
363 435 wp_enqueue_script( 'wp-stream-timeago-locale' );
364 436
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() );
437 + wp_enqueue_script(
438 + 'wp-stream-admin',
439 + $this->plugin->locations['url'] . 'ui/js/admin.' . $min . 'js',
440 + array(
441 + 'jquery',
442 + 'wp-stream-select2',
443 + ),
444 + $this->plugin->get_version(),
445 + false
446 + );
447 + wp_enqueue_script(
448 + 'wp-stream-admin-exclude',
449 + $this->plugin->locations['url'] . 'ui/js/exclude.' . $min . 'js',
450 + array(
451 + 'jquery',
452 + 'wp-stream-select2',
453 + ),
454 + $this->plugin->get_version(),
455 + false
456 + );
457 + wp_enqueue_script(
458 + 'wp-stream-live-updates',
459 + $this->plugin->locations['url'] . 'ui/js/live-updates.' . $min . 'js',
460 + array(
461 + 'jquery',
462 + 'heartbeat',
463 + ),
464 + $this->plugin->get_version(),
465 + false
466 + );
367 467
368 468 wp_localize_script(
369 469 'wp-stream-admin',
370 470 'wp_stream',
@@ -378,17 +478,21 @@
378 478 'gmt_offset' => get_option( 'gmt_offset' ),
379 479 )
380 480 );
381 481
482 + $order_types = array( 'asc', 'desc' );
483 +
382 484 wp_localize_script(
383 485 'wp-stream-live-updates',
384 486 'wp_stream_live_updates',
385 487 array(
386 488 '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
489 + 'current_page' => isset( $_GET['paged'] ) ? absint( wp_unslash( $_GET['paged'] ) ) : '1', // phpcs:ignore WordPress.Security.NonceVerification.Recommended
490 + 'current_order' => isset( $_GET['order'] ) && in_array( strtolower( $_GET['order'] ), $order_types, true ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
491 + ? esc_js( $_GET['order'] ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended
492 + : 'desc',
493 + 'current_query' => wp_stream_json_encode( $_GET ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended
494 + 'current_query_count' => count( $_GET ), // phpcs:ignore WordPress.Security.NonceVerification.Recommended
391 495 )
392 496 );
393 497 }
394 498
@@ -405,15 +509,23 @@
405 509 * @return int
406 510 */
407 511 $bulk_actions_threshold = apply_filters( 'wp_stream_bulk_actions_threshold', 100 );
408 512
409 - wp_enqueue_script( 'wp-stream-global', $this->plugin->locations['url'] . 'ui/js/global.js', array( 'jquery' ), $this->plugin->get_version() );
513 + wp_enqueue_script(
514 + 'wp-stream-global',
515 + $this->plugin->locations['url'] . 'ui/js/global.' . $min . 'js',
516 + array( 'jquery' ),
517 + $this->plugin->get_version(),
518 + false
519 + );
520 +
410 521 wp_localize_script(
411 522 'wp-stream-global',
412 523 'wp_stream_global',
413 524 array(
414 - 'bulk_actions' => array(
415 - 'i18n' => array(
525 + 'bulk_actions' => array(
526 + 'i18n' => array(
527 + /* translators: %s: a number of items (e.g. "1,742") */
416 528 '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 529 ),
418 530 'threshold' => absint( $bulk_actions_threshold ),
419 531 ),
@@ -431,8 +543,13 @@
431 543 if ( is_admin() && false !== strpos( wp_stream_filter_input( INPUT_GET, 'page' ), $this->records_page_slug ) ) {
432 544 return true;
433 545 }
434 546
547 + $screen = get_current_screen();
548 + if ( is_admin() && Alerts::POST_TYPE === $screen->post_type ) {
549 + return true;
550 + }
551 +
435 552 return false;
436 553 }
437 554
438 555 /**
@@ -437,9 +554,9 @@
437 554
438 555 /**
439 556 * Add a specific body class to all Stream admin screens
440 557 *
441 - * @param string $classes CSS classes to output to body
558 + * @param string $classes CSS classes to output to body.
442 559 *
443 560 * @filter admin_body_class
444 561 *
445 562 * @return string
@@ -449,10 +566,10 @@
449 566
450 567 if ( $this->is_stream_screen() ) {
451 568 $stream_classes[] = $this->admin_body_class;
452 569
453 - if ( isset( $_GET['page'] ) ) {
454 - $stream_classes[] = sanitize_key( $_GET['page'] ); // input var okay
570 + if ( isset( $_GET['page'] ) ) { // // phpcs:ignore WordPress.Security.NonceVerification.Recommended
571 + $stream_classes[] = sanitize_key( $_GET['page'] ); // phpcs:ignore WordPress.Security.NonceVerification.Recommended
455 572 }
456 573 }
457 574
458 575 /**
@@ -473,16 +590,17 @@
473 590 *
474 591 * @action admin_enqueue_scripts
475 592 */
476 593 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() );
594 + $min = wp_stream_min_suffix();
595 + wp_register_style( 'wp-stream-datepicker', $this->plugin->locations['url'] . 'ui/css/datepicker.' . $min . 'css', array(), $this->plugin->get_version() );
478 596 wp_register_style( 'wp-stream-icons', $this->plugin->locations['url'] . 'ui/stream-icons/style.css', array(), $this->plugin->get_version() );
479 597
480 - // Make sure we're working off a clean version
598 + // Make sure we're working off a clean version.
481 599 if ( ! file_exists( ABSPATH . WPINC . '/version.php' ) ) {
482 600 return;
483 601 }
484 - include( ABSPATH . WPINC . '/version.php' );
602 + include ABSPATH . WPINC . '/version.php';
485 603
486 604 if ( ! isset( $wp_version ) ) {
487 605 return;
488 606 }
@@ -541,10 +659,15 @@
541 659
542 660 \wp_add_inline_style( 'wp-admin', $css );
543 661 }
544 662
663 + /**
664 + * Handle the reset AJAX request to reset logs.
665 + *
666 + * @return bool
667 + */
545 668 public function wp_ajax_reset() {
546 - check_ajax_referer( 'stream_nonce', 'wp_stream_nonce' );
669 + check_ajax_referer( 'stream_nonce_reset', 'wp_stream_nonce_reset' );
547 670
548 671 if ( ! current_user_can( $this->settings_cap ) ) {
549 672 wp_die(
550 673 esc_html__( "You don't have sufficient privileges to do this action.", 'stream' )
@@ -556,9 +679,9 @@
556 679 if ( defined( 'WP_STREAM_TESTS' ) && WP_STREAM_TESTS ) {
557 680 return true;
558 681 }
559 682
560 - wp_redirect(
683 + wp_safe_redirect(
561 684 add_query_arg(
562 685 array(
563 686 'page' => is_network_admin() ? $this->network->network_settings_page_slug : $this->settings_page_slug,
564 687 'message' => 'data_erased',
@@ -569,14 +692,19 @@
569 692
570 693 exit;
571 694 }
572 695
696 + /**
697 + * Clears stream records from the database.
698 + *
699 + * @return void
700 + */
573 701 private function erase_stream_records() {
574 702 global $wpdb;
575 703
576 704 $where = '';
577 705
578 - if ( is_multisite() && ! is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) {
706 + if ( is_multisite() && ! $this->plugin->is_network_activated() ) {
579 707 $where .= $wpdb->prepare( ' AND `blog_id` = %d', get_current_blog_id() );
580 708 }
581 709
582 710 $wpdb->query(
@@ -587,8 +715,13 @@
587 715 WHERE 1=1 {$where};" // @codingStandardsIgnoreLine $where already prepared
588 716 );
589 717 }
590 718
719 + /**
720 + * Schedules a purge of records.
721 + *
722 + * @return void
723 + */
591 724 public function purge_schedule_setup() {
592 725 if ( ! wp_next_scheduled( 'wp_stream_auto_purge' ) ) {
593 726 wp_schedule_event( time(), 'twicedaily', 'wp_stream_auto_purge' );
594 727 }
@@ -593,41 +726,48 @@
593 726 wp_schedule_event( time(), 'twicedaily', 'wp_stream_auto_purge' );
594 727 }
595 728 }
596 729
730 + /**
731 + * Executes a scheduled purge
732 + *
733 + * @return void
734 + */
597 735 public function purge_scheduled_action() {
598 736 global $wpdb;
599 737
600 - // Don't purge when in Network Admin unless Stream is network activated
738 + // Don't purge when in Network Admin unless Stream is network activated.
601 739 if (
602 740 is_multisite()
603 741 &&
604 742 is_network_admin()
605 743 &&
606 - ! is_plugin_active_for_network( $this->plugin->locations['plugin'] )
744 + ! $this->plugin->is_network_activated()
607 745 ) {
608 746 return;
609 747 }
610 748
611 - if ( is_multisite() && is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) {
612 - $options = (array) get_site_option( 'wp_stream_network', array() );
749 + $defaults = $this->plugin->settings->get_defaults();
750 + if ( is_multisite() && $this->plugin->is_network_activated() ) {
751 + $options = (array) get_site_option( 'wp_stream_network', $defaults );
613 752 } else {
614 - $options = (array) get_option( 'wp_stream', array() );
753 + $options = (array) get_option( 'wp_stream', $defaults );
615 754 }
616 755
617 - if ( isset( $options['general_keep_records_indefinitely'] ) || ! isset( $options['general_records_ttl'] ) ) {
756 + if ( ! empty( $options['general_keep_records_indefinitely'] ) || ! isset( $options['general_records_ttl'] ) ) {
618 757 return;
619 758 }
620 759
621 - $days = $options['general_records_ttl'];
622 - $date = new DateTime( 'now', $timezone = new DateTimeZone( 'UTC' ) );
760 + $days = $options['general_records_ttl'];
761 + $timezone = new DateTimeZone( 'UTC' );
762 + $date = new DateTime( 'now', $timezone );
623 763
624 764 $date->sub( DateInterval::createFromDateString( "$days days" ) );
625 765
626 766 $where = $wpdb->prepare( ' AND `stream`.`created` < %s', $date->format( 'Y-m-d H:i:s' ) );
627 767
628 - // Multisite but NOT network activated, only purge the current blog
629 - if ( is_multisite() && ! is_plugin_active_for_network( $this->plugin->locations['plugin'] ) ) {
768 + // Multisite but NOT network activated, only purge the current blog.
769 + if ( is_multisite() && ! $this->plugin->is_network_activated() ) {
630 770 $where .= $wpdb->prepare( ' AND `blog_id` = %d', get_current_blog_id() );
631 771 }
632 772
633 773 $wpdb->query(
@@ -639,13 +779,15 @@
639 779 );
640 780 }
641 781
642 782 /**
643 - * @param array $links
644 - * @param string $file
783 + * Returns the admin action links.
645 784 *
646 785 * @filter plugin_action_links
647 786 *
787 + * @param array $links Action links.
788 + * @param string $file Plugin file.
789 + *
648 790 * @return array
649 791 */
650 792 public function plugin_action_links( $links, $file ) {
651 793 if ( plugin_basename( $this->plugin->locations['dir'] . 'stream.php' ) !== $file ) {
@@ -651,30 +793,42 @@
651 793 if ( plugin_basename( $this->plugin->locations['dir'] . 'stream.php' ) !== $file ) {
652 794 return $links;
653 795 }
654 796
655 - // 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'] ) ) {
797 + // Also don't show links in Network Admin if Stream isn't network enabled.
798 + if ( is_network_admin() && is_multisite() && ! $this->plugin->is_network_activated() ) {
657 799 return $links;
658 800 }
659 801
660 802 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 ) );
803 + $admin_page_url = add_query_arg(
804 + array(
805 + 'page' => $this->network->network_settings_page_slug,
806 + ),
807 + network_admin_url( $this->admin_parent_page )
808 + );
662 809 } else {
663 - $admin_page_url = add_query_arg( array( 'page' => $this->settings_page_slug ), admin_url( $this->admin_parent_page ) );
810 + $admin_page_url = add_query_arg(
811 + array(
812 + 'page' => $this->settings_page_slug,
813 + ),
814 + admin_url( $this->admin_parent_page )
815 + );
664 816 }
665 817
666 818 $links[] = sprintf( '<a href="%s">%s</a>', esc_url( $admin_page_url ), esc_html__( 'Settings', 'default' ) );
667 819
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 - );
820 + if ( ! defined( 'DISALLOW_FILE_MODS' ) || false === DISALLOW_FILE_MODS ) {
821 + $url = add_query_arg(
822 + array(
823 + 'action' => 'wp_stream_uninstall',
824 + 'wp_stream_nonce' => wp_create_nonce( 'stream_nonce' ),
825 + ),
826 + admin_url( 'admin-ajax.php' )
827 + );
675 828
676 - $links[] = sprintf( '<span id="wp_stream_uninstall" class="delete"><a href="%s">%s</a></span>', esc_url( $url ), esc_html__( 'Uninstall', 'stream' ) );
829 + $links[] = sprintf( '<span id="wp_stream_uninstall" class="delete"><a href="%s">%s</a></span>', esc_url( $url ), esc_html__( 'Uninstall', 'stream' ) );
830 + }
677 831
678 832 return $links;
679 833 }
680 834
@@ -684,12 +838,12 @@
684 838 public function render_list_table() {
685 839 $this->list_table->prepare_items();
686 840 ?>
687 841 <div class="wrap">
688 - <h1><?php echo esc_html( get_admin_page_title() ) ?></h1>
689 - <?php $this->list_table->display() ?>
842 + <h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
843 + <?php $this->list_table->display(); ?>
690 844 </div>
691 - <?php
845 + <?php
692 846 }
693 847
694 848 /**
695 849 * Render settings page
@@ -701,28 +855,28 @@
701 855 $page_description = apply_filters( 'wp_stream_settings_form_description', '' );
702 856
703 857 $sections = $this->plugin->settings->get_fields();
704 858 $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 );
859 + $min = wp_stream_min_suffix();
860 + wp_enqueue_script( 'wp-stream-settings', $this->plugin->locations['url'] . 'ui/js/settings.' . $min . 'js', array( 'jquery' ), $this->plugin->get_version(), true );
707 861 ?>
708 862 <div class="wrap">
709 - <h1><?php echo esc_html( get_admin_page_title() ) ?></h1>
863 + <h1><?php echo esc_html( get_admin_page_title() ); ?></h1>
710 864
711 865 <?php if ( ! empty( $page_description ) ) : ?>
712 - <p><?php echo esc_html( $page_description ) ?></p>
866 + <p><?php echo esc_html( $page_description ); ?></p>
713 867 <?php endif; ?>
714 868
715 - <?php settings_errors() ?>
869 + <?php settings_errors(); ?>
716 870
717 871 <?php if ( count( $sections ) > 1 ) : ?>
718 872 <h2 class="nav-tab-wrapper">
719 - <?php $i = 0 ?>
873 + <?php $i = 0; ?>
720 874 <?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'] ) ?>
875 + <?php $i++; ?>
876 + <?php $is_active = ( ( 1 === $i && ! $active_tab ) || $active_tab === $section ); ?>
877 + <a href="<?php echo esc_url( add_query_arg( 'tab', $section ) ); ?>" class="nav-tab <?php echo $is_active ? esc_attr( ' nav-tab-active' ) : ''; ?>">
878 + <?php echo esc_html( $data['title'] ); ?>
725 879 </a>
726 880 <?php endforeach; ?>
727 881 </h2>
728 882 <?php endif; ?>
@@ -727,29 +881,29 @@
727 881 </h2>
728 882 <?php endif; ?>
729 883
730 884 <div class="nav-tab-content" id="tab-content-settings">
731 - <form method="post" action="<?php echo esc_attr( $form_action ) ?>" enctype="multipart/form-data">
885 + <form method="post" action="<?php echo esc_attr( $form_action ); ?>" enctype="multipart/form-data">
732 886 <div class="settings-sections">
733 - <?php
734 - $i = 0;
735 - foreach ( $sections as $section => $data ) {
736 - $i++;
887 + <?php
888 + $i = 0;
889 + foreach ( $sections as $section => $data ) {
890 + $i++;
737 891
738 - $is_active = ( ( 1 === $i && ! $active_tab ) || $active_tab === $section );
892 + $is_active = ( ( 1 === $i && ! $active_tab ) || $active_tab === $section );
739 893
740 - if ( $is_active ) {
741 - settings_fields( $option_key );
742 - do_settings_sections( $option_key );
743 - }
744 - }
745 - ?>
894 + if ( $is_active ) {
895 + settings_fields( $option_key );
896 + do_settings_sections( $option_key );
897 + }
898 + }
899 + ?>
746 900 </div>
747 - <?php submit_button() ?>
901 + <?php submit_button(); ?>
748 902 </form>
749 903 </div>
750 904 </div>
751 - <?php
905 + <?php
752 906 }
753 907
754 908 /**
755 909 * Instantiate the list table
@@ -754,15 +908,20 @@
754 908 /**
755 909 * Instantiate the list table
756 910 */
757 911 public function register_list_table() {
758 - $this->list_table = new List_Table( $this->plugin, array( 'screen' => $this->screen_id['main'] ) );
912 + $this->list_table = new List_Table(
913 + $this->plugin,
914 + array(
915 + 'screen' => $this->screen_id['main'],
916 + )
917 + );
759 918 }
760 919
761 920 /**
762 921 * Check if a particular role has access
763 922 *
764 - * @param string $role
923 + * @param string $role User role.
765 924 *
766 925 * @return bool
767 926 */
768 927 private function role_can_view( $role ) {
@@ -775,12 +934,12 @@
775 934
776 935 /**
777 936 * Filter user caps to dynamically grant our view cap based on allowed roles
778 937 *
779 - * @param $allcaps
780 - * @param $caps
781 - * @param $args
782 - * @param $user
938 + * @param array $allcaps All capabilities.
939 + * @param array $caps Required caps.
940 + * @param array $args Unused.
941 + * @param WP_User $user User.
783 942 *
784 943 * @filter user_has_cap
785 944 *
786 945 * @return array
@@ -825,11 +984,11 @@
825 984 * Filter role caps to dynamically grant our view cap based on allowed roles
826 985 *
827 986 * @filter role_has_cap
828 987 *
829 - * @param $allcaps
830 - * @param $cap
831 - * @param $role
988 + * @param array $allcaps All capabilities.
989 + * @param string $cap Require cap.
990 + * @param string $role User role.
832 991 *
833 992 * @return array
834 993 */
835 994 public function filter_role_caps( $allcaps, $cap, $role ) {
@@ -842,8 +1001,10 @@
842 1001 return $allcaps;
843 1002 }
844 1003
845 1004 /**
1005 + * Ajax callback for return a user list.
1006 + *
846 1007 * @action wp_ajax_wp_stream_filters
847 1008 */
848 1009 public function ajax_filters() {
849 1010 if ( ! defined( 'DOING_AJAX' ) || ! current_user_can( $this->plugin->admin->settings_cap ) ) {
@@ -854,9 +1015,13 @@
854 1015
855 1016 switch ( wp_stream_filter_input( INPUT_GET, 'filter' ) ) {
856 1017 case 'user_id':
857 1018 $users = array_merge(
858 - array( 0 => (object) array( 'display_name' => 'WP-CLI' ) ),
1019 + array(
1020 + 0 => (object) array(
1021 + 'display_name' => 'WP-CLI',
1022 + ),
1023 + ),
859 1024 get_users()
860 1025 );
861 1026
862 1027 $search = wp_stream_filter_input( INPUT_GET, 'q' );
@@ -863,9 +1028,9 @@
863 1028 if ( $search ) {
864 1029 // `search` arg for get_users() is not enough
865 1030 $users = array_filter(
866 1031 $users,
867 - function( $user ) use ( $search ) {
1032 + function ( $user ) use ( $search ) {
868 1033 return false !== mb_strpos( mb_strtolower( $user->display_name ), mb_strtolower( $search ) );
869 1034 }
870 1035 );
871 1036 }
@@ -873,9 +1038,9 @@
873 1038 if ( count( $users ) > $this->preload_users_max ) {
874 1039 $users = array_slice( $users, 0, $this->preload_users_max );
875 1040 }
876 1041
877 - // Get gravatar / roles for final result set
1042 + // Get gravatar / roles for final result set.
878 1043 $results = $this->get_users_record_meta( $users );
879 1044
880 1045 break;
881 1046 }
@@ -880,14 +1045,20 @@
880 1045 break;
881 1046 }
882 1047
883 1048 if ( isset( $results ) ) {
884 - echo wp_stream_json_encode( $results ); // xss ok
1049 + echo wp_stream_json_encode( $results ); // xss ok.
885 1050 }
886 1051
887 1052 die();
888 1053 }
889 1054
1055 + /**
1056 + * Return relevant user meta data.
1057 + *
1058 + * @param array $authors Author data.
1059 + * @return array
1060 + */
890 1061 public function get_users_record_meta( $authors ) {
891 1062 $authors_records = array();
892 1063
893 1064 foreach ( $authors as $user_id => $args ) {
@@ -893,13 +1064,13 @@
893 1064 foreach ( $authors as $user_id => $args ) {
894 1065 $author = new Author( $args->ID );
895 1066
896 1067 $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' => '',
1068 + 'text' => $author->get_display_name(),
1069 + 'id' => $author->id,
1070 + 'label' => $author->get_display_name(),
1071 + 'icon' => $author->get_avatar_src( 32 ),
1072 + 'title' => '',
902 1073 );
903 1074 }
904 1075
905 1076 return $authors_records;
@@ -907,18 +1078,19 @@
907 1078
908 1079 /**
909 1080 * Get user meta in a way that is also safe for VIP
910 1081 *
911 - * @param int $user_id
912 - * @param string $meta_key
913 - * @param bool $single (optional)
1082 + * @param int $user_id User ID.
1083 + * @param string $meta_key Meta key.
1084 + * @param bool $single Return first found meta value connected to the meta key (optional).
914 1085 *
915 1086 * @return mixed
916 1087 */
917 - function get_user_meta( $user_id, $meta_key, $single = true ) {
1088 + public function get_user_meta( $user_id, $meta_key, $single = true ) {
918 1089 if ( wp_stream_is_vip() && function_exists( 'get_user_attribute' ) ) {
919 1090 return get_user_attribute( $user_id, $meta_key );
920 1091 }
1092 +
921 1093 return get_user_meta( $user_id, $meta_key, $single );
922 1094 }
923 1095
924 1096 /**
@@ -923,19 +1095,20 @@
923 1095
924 1096 /**
925 1097 * Update user meta in a way that is also safe for VIP
926 1098 *
927 - * @param int $user_id
928 - * @param string $meta_key
929 - * @param mixed $meta_value
930 - * @param mixed $prev_value (optional)
1099 + * @param int $user_id User ID.
1100 + * @param string $meta_key Meta key.
1101 + * @param mixed $meta_value Meta value.
1102 + * @param mixed $prev_value Previous meta value being overwritten (optional).
931 1103 *
932 1104 * @return int|bool
933 1105 */
934 - function update_user_meta( $user_id, $meta_key, $meta_value, $prev_value = '' ) {
1106 + public function update_user_meta( $user_id, $meta_key, $meta_value, $prev_value = '' ) {
935 1107 if ( wp_stream_is_vip() && function_exists( 'update_user_attribute' ) ) {
936 1108 return update_user_attribute( $user_id, $meta_key, $meta_value );
937 1109 }
1110 +
938 1111 return update_user_meta( $user_id, $meta_key, $meta_value, $prev_value );
939 1112 }
940 1113
941 1114 /**
@@ -940,17 +1113,18 @@
940 1113
941 1114 /**
942 1115 * Delete user meta in a way that is also safe for VIP
943 1116 *
944 - * @param int $user_id
945 - * @param string $meta_key
946 - * @param mixed $meta_value (optional)
1117 + * @param int $user_id User ID.
1118 + * @param string $meta_key Meta key.
1119 + * @param mixed $meta_value Meta value (optional).
947 1120 *
948 1121 * @return bool
949 1122 */
950 - function delete_user_meta( $user_id, $meta_key, $meta_value = '' ) {
1123 + public function delete_user_meta( $user_id, $meta_key, $meta_value = '' ) {
951 1124 if ( wp_stream_is_vip() && function_exists( 'delete_user_attribute' ) ) {
952 1125 return delete_user_attribute( $user_id, $meta_key, $meta_value );
953 1126 }
1127 +
954 1128 return delete_user_meta( $user_id, $meta_key, $meta_value );
955 1129 }
956 1130 }