PluginProbe
Stream – Activity Log & Audit Trail / 3.8.2
Stream – Activity Log & Audit Trail v3.8.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-settings.php +278 -167 3.2.13.8.2 View file →
@@ -1,5 +1,11 @@
1 1 <?php
2 +/**
3 + * Renders and manages the plugin Settings page.
4 + *
5 + * @package WP_Stream
6 + */
7 +
2 8 namespace WP_Stream;
3 9
4 10 use \WP_Roles;
5 11 use \WP_User;
@@ -4,11 +10,16 @@
4 10 use \WP_Roles;
5 11 use \WP_User;
6 12 use \WP_User_Query;
7 13
14 +/**
15 + * Class - Settings
16 + */
8 17 class Settings {
18 +
9 19 /**
10 - * Hold Plugin class
20 + * Holds instance of plugin object
21 + *
11 22 * @var Plugin
12 23 */
13 24 public $plugin;
14 25
@@ -42,9 +53,9 @@
42 53
43 54 /**
44 55 * Class constructor.
45 56 *
46 - * @param Plugin $plugin The main Plugin class.
57 + * @param Plugin $plugin Instance of plugin object.
47 58 */
48 59 public function __construct( $plugin ) {
49 60 $this->plugin = $plugin;
50 61
@@ -50,21 +61,35 @@
50 61
51 62 $this->option_key = $this->get_option_key();
52 63 $this->options = $this->get_options();
53 64
54 - // Register settings, and fields
65 + // Register settings, and fields.
55 66 add_action( 'admin_init', array( $this, 'register_settings' ) );
56 67
57 - // Remove records when records TTL is shortened
58 - add_action( 'update_option_' . $this->option_key, array( $this, 'updated_option_ttl_remove_records' ), 10, 2 );
68 + // Remove records when records TTL is shortened.
69 + add_action(
70 + 'update_option_' . $this->option_key,
71 + array(
72 + $this,
73 + 'updated_option_ttl_remove_records',
74 + ),
75 + 10,
76 + 2
77 + );
59 78
60 - // Apply label translations for settings
61 - add_filter( 'wp_stream_serialized_labels', array( $this, 'get_settings_translations' ) );
79 + // Apply label translations for settings.
80 + add_filter(
81 + 'wp_stream_serialized_labels',
82 + array(
83 + $this,
84 + 'get_settings_translations',
85 + )
86 + );
62 87
63 - // Ajax callback function to search users
88 + // Ajax callback function to search users.
64 89 add_action( 'wp_ajax_stream_get_users', array( $this, 'get_users' ) );
65 90
66 - // Ajax callback function to search IPs
91 + // Ajax callback function to search IPs.
67 92 add_action( 'wp_ajax_stream_get_ips', array( $this, 'get_ips' ) );
68 93 }
69 94
70 95 /**
@@ -94,13 +119,21 @@
94 119 $request = (object) array(
95 120 'find' => $search,
96 121 );
97 122
98 - add_filter( 'user_search_columns', array( $this, 'add_display_name_search_columns' ), 10, 3 );
123 + add_filter(
124 + 'user_search_columns',
125 + array(
126 + $this,
127 + 'add_display_name_search_columns',
128 + ),
129 + 10,
130 + 3
131 + );
99 132
100 133 $users = new WP_User_Query(
101 134 array(
102 - 'search' => "*{$request->find}*",
135 + 'search' => "*{$request->find}*",
103 136 'search_columns' => array(
104 137 'user_login',
105 138 'user_nicename',
106 139 'user_email',
@@ -105,14 +138,21 @@
105 138 'user_nicename',
106 139 'user_email',
107 140 'user_url',
108 141 ),
109 - 'orderby' => 'display_name',
110 - 'number' => $this->plugin->admin->preload_users_max,
142 + 'orderby' => 'display_name',
143 + 'number' => $this->plugin->admin->preload_users_max,
111 144 )
112 145 );
113 146
114 - remove_filter( 'user_search_columns', array( $this, 'add_display_name_search_columns' ), 10 );
147 + remove_filter(
148 + 'user_search_columns',
149 + array(
150 + $this,
151 + 'add_display_name_search_columns',
152 + ),
153 + 10
154 + );
115 155
116 156 if ( 0 === $users->get_total() ) {
117 157 wp_send_json_error( $response );
118 158 }
@@ -120,21 +160,21 @@
120 160
121 161 if ( is_multisite() && is_super_admin() ) {
122 162 $super_admins = get_super_admins();
123 163 foreach ( $super_admins as $admin ) {
124 - $user = get_user_by( 'login', $admin );
164 + $user = get_user_by( 'login', $admin );
125 165 $users_array[] = $user;
126 166 }
127 167 }
128 168
129 - $response->status = true;
130 - $response->message = '';
131 - $response->roles = $this->get_roles();
132 - $response->users = array();
169 + $response->status = true;
170 + $response->message = '';
171 + $response->roles = $this->get_roles();
172 + $response->users = array();
133 173 $users_added_to_response = array();
134 174
135 175 foreach ( $users_array as $key => $user ) {
136 - // exclude duplications:
176 + // exclude duplications.
137 177 if ( array_key_exists( $user->ID, $users_added_to_response ) ) {
138 178 continue;
139 179 } else {
140 180 $users_added_to_response[ $user->ID ] = true;
@@ -148,8 +188,9 @@
148 188 );
149 189
150 190 $args['tooltip'] = esc_attr(
151 191 sprintf(
192 + /* translators: %1$d: user ID, %2$s: username, %3$s: email, %4$s: user role (e.g. "42", "administrator", "foo@bar.com", "subscriber") */
152 193 __( 'ID: %1$d\nUser: %2$s\nEmail: %3$s\nRole: %4$s', 'stream' ),
153 194 $author->id,
154 195 $author->user_login,
155 196 $author->user_email,
@@ -163,15 +204,15 @@
163 204 }
164 205
165 206 usort(
166 207 $response->users,
167 - function( $a, $b ) {
208 + function ( $a, $b ) {
168 209 return strcmp( $a['text'], $b['text'] );
169 210 }
170 211 );
171 212
172 213 if ( empty( $search ) || preg_match( '/wp|cli|system|unknown/i', $search ) ) {
173 - $author = new Author( 0 );
214 + $author = new Author( 0 );
174 215 $response->users[] = array(
175 216 'id' => '0',
176 217 'text' => $author->get_display_name(),
177 218 'icon' => $author->get_avatar_src( 32 ),
@@ -182,10 +223,10 @@
182 223 wp_send_json_success( $response );
183 224 }
184 225
185 226 /**
186 - * Ajax callback function to search IP addresses, used on exclude setting page
187 - */
227 + * Ajax callback function to search IP addresses, used on exclude setting page
228 + */
188 229 public function get_ips() {
189 230 if ( ! defined( 'DOING_AJAX' ) || ! current_user_can( $this->plugin->admin->settings_cap ) ) {
190 231 return;
191 232 }
@@ -195,11 +236,14 @@
195 236 $ips = $this->plugin->db->existing_records( 'ip' );
196 237 $find = wp_stream_filter_input( INPUT_POST, 'find' );
197 238
198 239 if ( isset( $find['term'] ) && '' !== $find['term'] ) {
199 - $ips = array_filter( $ips, function ( $ip ) use ( $find ) {
200 - return 0 === strpos( $ip, $find['term'] );
201 - } );
240 + $ips = array_filter(
241 + $ips,
242 + function ( $ip ) use ( $find ) {
243 + return 0 === strpos( $ip, $find['term'] );
244 + }
245 + );
202 246 }
203 247
204 248 if ( $ips ) {
205 249 wp_send_json_success( $ips );
@@ -210,11 +254,11 @@
210 254
211 255 /**
212 256 * Filter the columns to search in a WP_User_Query search.
213 257 *
214 - * @param array $search_columns Array of column names to be searched.
215 - * @param string $search Text being searched.
216 - * @param \WP_User_Query $query current WP_User_Query instance.
258 + * @param array $search_columns Array of column names to be searched.
259 + * @param string $search Text being searched.
260 + * @param \WP_User_Query $query current WP_User_Query instance.
217 261 *
218 262 * @return array
219 263 */
220 264 public function add_display_name_search_columns( $search_columns, $search, $query ) {
@@ -253,18 +297,18 @@
253 297 * @return array
254 298 */
255 299 public function get_fields() {
256 300 $fields = array(
257 - 'general' => array(
301 + 'general' => array(
258 302 'title' => esc_html__( 'General', 'stream' ),
259 303 'fields' => array(
260 304 array(
261 - 'name' => 'role_access',
262 - 'title' => esc_html__( 'Role Access', 'stream' ),
263 - 'type' => 'multi_checkbox',
264 - 'desc' => esc_html__( 'Users from the selected roles above will have permission to view Stream Records. However, only site Administrators can access Stream Settings.', 'stream' ),
265 - 'choices' => $this->get_roles(),
266 - 'default' => array( 'administrator' ),
305 + 'name' => 'role_access',
306 + 'title' => esc_html__( 'Role Access', 'stream' ),
307 + 'type' => 'multi_checkbox',
308 + 'desc' => esc_html__( 'Users from the selected roles above will have permission to view Stream Records. However, only site Administrators can access Stream Settings.', 'stream' ),
309 + 'choices' => $this->get_roles(),
310 + 'default' => array( 'administrator' ),
267 311 ),
268 312 array(
269 313 'name' => 'records_ttl',
270 314 'title' => esc_html__( 'Keep Records for', 'stream' ),
@@ -286,18 +330,18 @@
286 330 'default' => 0,
287 331 ),
288 332 ),
289 333 ),
290 - 'exclude' => array(
334 + 'exclude' => array(
291 335 'title' => esc_html__( 'Exclude', 'stream' ),
292 336 'fields' => array(
293 337 array(
294 - 'name' => 'rules',
295 - 'title' => esc_html__( 'Exclude Rules', 'stream' ),
296 - 'type' => 'rule_list',
297 - 'desc' => esc_html__( 'Create rules to exclude certain kinds of activity from being recorded by Stream.', 'stream' ),
298 - 'default' => array(),
299 - 'nonce' => 'stream_get_ips',
338 + 'name' => 'rules',
339 + 'title' => esc_html__( 'Exclude Rules', 'stream' ),
340 + 'type' => 'rule_list',
341 + 'desc' => esc_html__( 'Create rules to exclude certain kinds of activity from being recorded by Stream.', 'stream' ),
342 + 'default' => array(),
343 + 'nonce' => 'stream_get_ips',
300 344 ),
301 345 ),
302 346 ),
303 347 'advanced' => array(
@@ -311,28 +355,28 @@
311 355 'after_field' => esc_html__( 'Enabled', 'stream' ),
312 356 'default' => 0,
313 357 ),
314 358 array(
315 - 'name' => 'delete_all_records',
316 - 'title' => esc_html__( 'Reset Stream Database', 'stream' ),
317 - 'type' => 'link',
318 - 'href' => add_query_arg(
359 + 'name' => 'delete_all_records',
360 + 'title' => esc_html__( 'Reset Stream Database', 'stream' ),
361 + 'type' => 'link',
362 + 'href' => add_query_arg(
319 363 array(
320 - 'action' => 'wp_stream_reset',
321 - 'wp_stream_nonce' => wp_create_nonce( 'stream_nonce' ),
364 + 'action' => 'wp_stream_reset',
365 + 'wp_stream_nonce_reset' => wp_create_nonce( 'stream_nonce_reset' ),
322 366 ),
323 367 admin_url( 'admin-ajax.php' )
324 368 ),
325 - 'class' => 'warning',
326 - 'desc' => esc_html__( 'Warning: This will delete all activity records from the database.', 'stream' ),
327 - 'default' => 0,
328 - 'sticky' => 'bottom',
369 + 'class' => 'warning',
370 + 'desc' => esc_html__( 'Warning: This will delete all activity records from the database.', 'stream' ),
371 + 'default' => 0,
372 + 'sticky' => 'bottom',
329 373 ),
330 374 ),
331 375 ),
332 376 );
333 377
334 - // If Akismet is active, allow Admins to opt-in to Akismet tracking
378 + // If Akismet is active, allow Admins to opt-in to Akismet tracking.
335 379 if ( class_exists( 'Akismet' ) ) {
336 380 $akismet_tracking = array(
337 381 'name' => 'akismet_tracking',
338 382 'title' => esc_html__( 'Akismet Tracking', 'stream' ),
@@ -344,21 +388,18 @@
344 388
345 389 array_push( $fields['advanced']['fields'], $akismet_tracking );
346 390 }
347 391
348 - // If WP Cron is enabled, allow Admins to opt-in to WP Cron tracking
349 - if ( wp_stream_is_cron_enabled() ) {
350 - $wp_cron_tracking = array(
351 - 'name' => 'wp_cron_tracking',
352 - 'title' => esc_html__( 'WP Cron Tracking', 'stream' ),
353 - 'type' => 'checkbox',
354 - 'desc' => esc_html__( 'By default, Stream does not track activity performed by WordPress cron events unless you opt-in here. Enabling this is not necessary or recommended for most sites.', 'stream' ),
355 - 'after_field' => esc_html__( 'Enabled', 'stream' ),
356 - 'default' => 0,
357 - );
392 + $wp_cron_tracking = array(
393 + 'name' => 'wp_cron_tracking',
394 + 'title' => esc_html__( 'WP Cron Tracking', 'stream' ),
395 + 'type' => 'checkbox',
396 + 'desc' => esc_html__( 'By default, Stream does not track activity performed by WordPress cron events unless you opt-in here. Enabling this is not necessary or recommended for most sites.', 'stream' ),
397 + 'after_field' => esc_html__( 'Enabled', 'stream' ),
398 + 'default' => 0,
399 + );
358 400
359 - array_push( $fields['advanced']['fields'], $wp_cron_tracking );
360 - }
401 + array_push( $fields['advanced']['fields'], $wp_cron_tracking );
361 402
362 403 /**
363 404 * Filter allows for modification of options fields
364 405 *
@@ -365,9 +406,9 @@
365 406 * @return array Array of option fields
366 407 */
367 408 $this->fields = apply_filters( 'wp_stream_settings_option_fields', $fields );
368 409
369 - // Sort option fields in each tab by title ASC
410 + // Sort option fields in each tab by title ASC.
370 411 foreach ( $this->fields as $tab => $options ) {
371 412 $titles = array();
372 413
373 414 foreach ( $options['fields'] as $field ) {
@@ -437,9 +478,16 @@
437 478 */
438 479 public function register_settings() {
439 480 $sections = $this->get_fields();
440 481
441 - register_setting( $this->option_key, $this->option_key, array( $this, 'sanitize_settings' ) );
482 + register_setting(
483 + $this->option_key,
484 + $this->option_key,
485 + array(
486 + $this,
487 + 'sanitize_settings',
488 + )
489 + );
442 490
443 491 foreach ( $sections as $section_name => $section ) {
444 492 add_settings_section(
445 493 $section_name,
@@ -448,9 +496,10 @@
448 496 $this->option_key
449 497 );
450 498
451 499 foreach ( $section['fields'] as $field_idx => $field ) {
452 - if ( ! isset( $field['type'] ) ) { // No field type associated, skip, no GUI
500 + // No field type associated, skip, no GUI.
501 + if ( ! isset( $field['type'] ) ) {
453 502 continue;
454 503 }
455 504
456 505 add_settings_field(
@@ -455,14 +504,18 @@
455 504
456 505 add_settings_field(
457 506 $field['name'],
458 507 $field['title'],
459 - ( isset( $field['callback'] ) ? $field['callback'] : array( $this, 'output_field' ) ),
508 + ( isset( $field['callback'] ) ? $field['callback'] : array(
509 + $this,
510 + 'output_field',
511 + ) ),
460 512 $this->option_key,
461 513 $section_name,
462 514 $field + array(
463 515 'section' => $section_name,
464 - 'label_for' => sprintf( '%s_%s_%s', $this->option_key, $section_name, $field['name'] ), // xss ok
516 + 'label_for' => sprintf( '%s_%s_%s', $this->option_key, $section_name, $field['name'] ),
517 + // xss ok.
465 518 )
466 519 );
467 520 }
468 521 }
@@ -470,9 +523,9 @@
470 523
471 524 /**
472 525 * Sanitization callback for settings field values before save
473 526 *
474 - * @param array $input
527 + * @param array $input Raw input.
475 528 *
476 529 * @return array
477 530 */
478 531 public function sanitize_settings( $input ) {
@@ -491,9 +544,9 @@
491 544 if ( empty( $type ) || ! isset( $input[ $name ] ) || '' === $input[ $name ] ) {
492 545 continue;
493 546 }
494 547
495 - // Sanitize depending on the type of field
548 + // Sanitize depending on the type of field.
496 549 switch ( $type ) {
497 550 case 'number':
498 551 $output[ $name ] = is_numeric( $input[ $name ] ) ? intval( trim( $input[ $name ] ) ) : '';
499 552 break;
@@ -503,14 +556,17 @@
503 556 default:
504 557 if ( is_array( $input[ $name ] ) ) {
505 558 $output[ $name ] = $input[ $name ];
506 559
507 - // Support all values in multidimentional arrays too
508 - array_walk_recursive( $output[ $name ], function( &$v, $k ) {
509 - $v = trim( $v );
510 - } );
560 + // Support all values in multidimentional arrays too.
561 + array_walk_recursive(
562 + $output[ $name ],
563 + function ( &$v ) {
564 + $v = sanitize_text_field( trim( $v ) );
565 + }
566 + );
511 567 } else {
512 - $output[ $name ] = trim( $input[ $name ] );
568 + $output[ $name ] = sanitize_text_field( trim( $input[ $name ] ) );
513 569 }
514 570 }
515 571 }
516 572 }
@@ -520,9 +576,9 @@
520 576
521 577 /**
522 578 * Compile HTML needed for displaying the field
523 579 *
524 - * @param array $field Field settings
580 + * @param array $field Field settings.
525 581 *
526 582 * @return string HTML to be displayed
527 583 */
528 584 public function render_field( $field ) {
@@ -563,11 +619,9 @@
563 619 if ( ! $type || ! $section || ! $name ) {
564 620 return '';
565 621 }
566 622
567 - if ( 'multi_checkbox' === $type
568 - && ( empty( $field['choices'] ) || ! is_array( $field['choices'] ) )
569 - ) {
623 + if ( 'multi_checkbox' === $type && ( empty( $field['choices'] ) || ! is_array( $field['choices'] ) ) ) {
570 624 return '';
571 625 }
572 626
573 627 switch ( $type ) {
@@ -626,10 +680,10 @@
626 680 esc_attr( $option_key ),
627 681 esc_attr( $section ),
628 682 esc_attr( $name )
629 683 );
630 - // Fallback if nothing is selected
631 - $output .= sprintf(
684 + // Fallback if nothing is selected.
685 + $output .= sprintf(
632 686 '<input type="hidden" name="%1$s[%2$s_%3$s][]" value="__placeholder__" />',
633 687 esc_attr( $option_key ),
634 688 esc_attr( $section ),
635 689 esc_attr( $name )
@@ -634,9 +688,9 @@
634 688 esc_attr( $section ),
635 689 esc_attr( $name )
636 690 );
637 691 $current_value = (array) $current_value;
638 - $choices = $field['choices'];
692 + $choices = $field['choices'];
639 693 if ( is_callable( $choices ) ) {
640 694 $choices = call_user_func( $choices );
641 695 }
642 696 foreach ( $choices as $value => $label ) {
@@ -701,9 +755,9 @@
701 755 esc_attr( $href ),
702 756 esc_attr( $title )
703 757 );
704 758 break;
705 - case 'select2' :
759 + case 'select2':
706 760 if ( ! isset( $current_value ) ) {
707 761 $current_value = '';
708 762 }
709 763
@@ -720,16 +774,26 @@
720 774 $child_values = array();
721 775 if ( isset( $value['children'] ) ) {
722 776 $child_values = array();
723 777 foreach ( $value['children'] as $child_key => $child_value ) {
724 - $child_values[] = array( 'id' => $child_key, 'text' => $child_value );
778 + $child_values[] = array(
779 + 'id' => $child_key,
780 + 'text' => $child_value,
781 + );
725 782 }
726 783 }
727 784 if ( isset( $value['label'] ) ) {
728 - $data_values[] = array( 'id' => $key, 'text' => $value['label'], 'children' => $child_values );
785 + $data_values[] = array(
786 + 'id' => $key,
787 + 'text' => $value['label'],
788 + 'children' => $child_values,
789 + );
729 790 }
730 791 } else {
731 - $data_values[] = array( 'id' => $key, 'text' => $value );
792 + $data_values[] = array(
793 + 'id' => $key,
794 + 'text' => $value,
795 + );
732 796 }
733 797 }
734 798 $class .= ' with-source';
735 799 }
@@ -741,8 +805,9 @@
741 805 esc_attr( $name ),
742 806 esc_attr( wp_stream_json_encode( $data_values ) ),
743 807 esc_attr( $current_value ),
744 808 esc_attr( $class ),
809 + /* translators: %s: the title of the dropdown menu (e.g. "users") */
745 810 sprintf( esc_html__( 'Any %s', 'stream' ), $title )
746 811 );
747 812
748 813 $output = sprintf(
@@ -753,14 +818,15 @@
753 818 $input_html
754 819 );
755 820
756 821 break;
757 - case 'rule_list' :
758 - $form = new Form_Generator;
822 + case 'rule_list':
823 + $users = count_users();
824 + $form = new Form_Generator();
759 825 $output = '<p class="description">' . esc_html( $description ) . '</p>';
760 826
761 - $actions_top = sprintf( '<input type="button" class="button" id="%1$s_new_rule" value="&#43; %2$s" />', esc_attr( $section . '_' . $name ), esc_html__( 'Add New Rule', 'stream' ) );
762 - $actions_bottom = sprintf( '<input type="button" class="button" id="%1$s_remove_rules" value="%2$s" />', esc_attr( $section . '_' . $name ), esc_html__( 'Delete Selected Rules', 'stream' ) );
827 + $actions_top = sprintf( '<input type="button" class="button" id="%1$s_new_rule" value="&#43; %2$s" />', esc_attr( $section . '_' . $name ), esc_html__( 'Add New Rule', 'stream' ) );
828 + $actions_bottom = sprintf( '<input type="button" class="button" id="%1$s_remove_rules" value="%2$s" />', esc_attr( $section . '_' . $name ), esc_html__( 'Delete Selected Rules', 'stream' ) );
763 829
764 830 $output .= sprintf( '<div class="tablenav top">%1$s</div>', $actions_top );
765 831 $output .= '<table class="wp-list-table widefat fixed stream-exclude-list">';
766 832
@@ -784,13 +850,18 @@
784 850 );
785 851
786 852 $exclude_rows = array();
787 853
788 - // Prepend an empty row
789 - $current_value['exclude_row'] = array( 'helper' => '' ) + ( isset( $current_value['exclude_row'] ) ? $current_value['exclude_row'] : array() );
854 + // Account for when no rules have been added yet.
855 + if ( ! is_array( $current_value ) ) {
856 + $current_value = array();
857 + }
790 858
859 + // Prepend an empty row.
860 + $current_value['exclude_row'] = ( isset( $current_value['exclude_row'] ) ? $current_value['exclude_row'] : array() ) + array( 'helper' => '' );
861 +
791 862 foreach ( $current_value['exclude_row'] as $key => $value ) {
792 - // Prepare values
863 + // Prepare values.
793 864 $author_or_role = isset( $current_value['author_or_role'][ $key ] ) ? $current_value['author_or_role'][ $key ] : '';
794 865 $connector = isset( $current_value['connector'][ $key ] ) ? $current_value['connector'][ $key ] : '';
795 866 $context = isset( $current_value['context'][ $key ] ) ? $current_value['context'][ $key ] : '';
796 867 $action = isset( $current_value['action'][ $key ] ) ? $current_value['action'][ $key ] : '';
@@ -795,18 +866,21 @@
795 866 $context = isset( $current_value['context'][ $key ] ) ? $current_value['context'][ $key ] : '';
796 867 $action = isset( $current_value['action'][ $key ] ) ? $current_value['action'][ $key ] : '';
797 868 $ip_address = isset( $current_value['ip_address'][ $key ] ) ? $current_value['ip_address'][ $key ] : '';
798 869
799 - // Author or Role dropdown menu
870 + // Author or Role dropdown menu.
800 871 $author_or_role_values = array();
801 872 $author_or_role_selected = array();
802 873
803 874 foreach ( $this->get_roles() as $role_id => $role ) {
804 - $args = array( 'value' => $role_id, 'text' => $role );
805 - $users = count_users();
875 + $args = array(
876 + 'value' => $role_id,
877 + 'text' => $role,
878 + );
806 879 $count = isset( $users['avail_roles'][ $role_id ] ) ? $users['avail_roles'][ $role_id ] : 0;
807 880
808 881 if ( ! empty( $count ) ) {
882 + /* translators: %d: a number of users (e.g. "42") */
809 883 $args['user_count'] = sprintf( _n( '%d user', '%d users', absint( $count ), 'stream' ), absint( $count ) );
810 884 }
811 885
812 886 if ( $role_id === $author_or_role ) {
@@ -819,25 +893,31 @@
819 893
820 894 if ( empty( $author_or_role_selected ) && is_numeric( $author_or_role ) ) {
821 895 $user = new WP_User( $author_or_role );
822 896 $display_name = ( 0 === $user->ID ) ? esc_html__( 'N/A', 'stream' ) : $user->display_name;
823 - $author_or_role_selected = array( 'value' => $user->ID, 'text' => $display_name );
897 + $author_or_role_selected = array(
898 + 'value' => $user->ID,
899 + 'text' => $display_name,
900 + );
824 901 $author_or_role_values[] = $author_or_role_selected;
825 902 }
826 903
827 - $author_or_role_input = $form->render_field( 'select2', array(
828 - 'name' => esc_attr( sprintf( '%1$s[%2$s_%3$s][%4$s][]' , $option_key, $section, $name, 'author_or_role' ) ),
829 - 'options' => $author_or_role_values,
830 - 'classes' => 'author_or_role',
831 - 'data' => array(
832 - 'placeholder' => esc_html__( 'Any Author or Role', 'stream' ),
833 - 'nonce' => esc_attr( wp_create_nonce( 'stream_get_users' ) ),
834 - 'selected-id' => isset( $author_or_role_selected['value'] ) ? esc_attr( $author_or_role_selected['value'] ) : '',
835 - 'selected-text' => isset( $author_or_role_selected['text'] ) ? esc_attr( $author_or_role_selected['text'] ) : '',
836 - ),
837 - ) );
904 + $author_or_role_input = $form->render_field(
905 + 'select2',
906 + array(
907 + 'name' => esc_attr( sprintf( '%1$s[%2$s_%3$s][%4$s][]', $option_key, $section, $name, 'author_or_role' ) ),
908 + 'options' => $author_or_role_values,
909 + 'classes' => 'author_or_role',
910 + 'data' => array(
911 + 'placeholder' => esc_html__( 'Any Author or Role', 'stream' ),
912 + 'nonce' => esc_attr( wp_create_nonce( 'stream_get_users' ) ),
913 + 'selected-id' => isset( $author_or_role_selected['value'] ) ? esc_attr( $author_or_role_selected['value'] ) : '',
914 + 'selected-text' => isset( $author_or_role_selected['text'] ) ? esc_attr( $author_or_role_selected['text'] ) : '',
915 + ),
916 + )
917 + );
838 918
839 - // Context dropdown menu
919 + // Context dropdown menu.
840 920 $context_values = array();
841 921
842 922 foreach ( $this->get_terms_labels( 'context' ) as $context_id => $context_data ) {
843 923 if ( is_array( $context_data ) ) {
@@ -844,71 +924,100 @@
844 924 $child_values = array();
845 925 if ( isset( $context_data['children'] ) ) {
846 926 $child_values = array();
847 927 foreach ( $context_data['children'] as $child_id => $child_value ) {
848 - $child_values[] = array( 'value' => $context_id . '-' . $child_id, 'text' => $child_value, 'parent' => $context_id );
928 + $child_values[] = array(
929 + 'value' => $context_id . '-' . $child_id,
930 + 'text' => $child_value,
931 + 'parent' => $context_id,
932 + );
849 933 }
850 934 }
851 935 if ( isset( $context_data['label'] ) ) {
852 - $context_values[] = array( 'value' => $context_id, 'text' => $context_data['label'], 'children' => $child_values );
936 + $context_values[] = array(
937 + 'value' => $context_id,
938 + 'text' => $context_data['label'],
939 + 'children' => $child_values,
940 + );
853 941 }
854 942 } else {
855 - $context_values[] = array( 'value' => $context_id, 'text' => $context_data );
943 + $context_values[] = array(
944 + 'value' => $context_id,
945 + 'text' => $context_data,
946 + );
856 947 }
857 948 }
858 949
859 - $connector_or_context_input = $form->render_field( 'select2', array(
860 - 'name' => esc_attr( sprintf( '%1$s[%2$s_%3$s][%4$s][]' , $option_key, $section, $name, 'connector_or_context' ) ),
861 - 'options' => $context_values,
862 - 'classes' => 'connector_or_context',
863 - 'data' => array(
864 - 'group' => 'connector',
865 - 'placeholder' => __( 'Any Context', 'stream' ),
866 - ),
867 - ) );
950 + $connector_or_context_input = $form->render_field(
951 + 'select2',
952 + array(
953 + 'name' => esc_attr( sprintf( '%1$s[%2$s_%3$s][%4$s][]', $option_key, $section, $name, 'connector_or_context' ) ),
954 + 'options' => $context_values,
955 + 'classes' => 'connector_or_context',
956 + 'data' => array(
957 + 'group' => 'connector',
958 + 'placeholder' => __( 'Any Context', 'stream' ),
959 + ),
960 + )
961 + );
868 962
869 - $connector_input = $form->render_field( 'hidden', array(
870 - 'name' => esc_attr( sprintf( '%1$s[%2$s_%3$s][%4$s][]' , $option_key, $section, $name, 'connector' ) ),
871 - 'value' => $connector,
872 - 'classes' => 'connector',
873 - ) );
963 + $connector_input = $form->render_field(
964 + 'hidden',
965 + array(
966 + 'name' => esc_attr( sprintf( '%1$s[%2$s_%3$s][%4$s][]', $option_key, $section, $name, 'connector' ) ),
967 + 'value' => $connector,
968 + 'classes' => 'connector',
969 + )
970 + );
874 971
875 - $context_input = $form->render_field( 'hidden', array(
876 - 'name' => esc_attr( sprintf( '%1$s[%2$s_%3$s][%4$s][]' , $option_key, $section, $name, 'context' ) ),
877 - 'value' => $context,
878 - 'classes' => 'context',
879 - ) );
972 + $context_input = $form->render_field(
973 + 'hidden',
974 + array(
975 + 'name' => esc_attr( sprintf( '%1$s[%2$s_%3$s][%4$s][]', $option_key, $section, $name, 'context' ) ),
976 + 'value' => $context,
977 + 'classes' => 'context',
978 + )
979 + );
880 980
881 - // Action dropdown menu
981 + // Action dropdown menu.
882 982 $action_values = array();
883 983
884 984 foreach ( $this->get_terms_labels( 'action' ) as $action_id => $action_data ) {
885 - $action_values[] = array( 'value' => $action_id, 'text' => $action_data );
985 + $action_values[] = array(
986 + 'value' => $action_id,
987 + 'text' => $action_data,
988 + );
886 989 }
887 990
888 - $action_input = $form->render_field( 'select2', array(
889 - 'name' => esc_attr( sprintf( '%1$s[%2$s_%3$s][%4$s][]' , $option_key, $section, $name, 'action' ) ),
890 - 'value' => $action,
891 - 'options' => $action_values,
892 - 'classes' => 'action',
893 - 'data' => array(
894 - 'placeholder' => __( 'Any Action', 'stream' ),
895 - ),
896 - ) );
991 + $action_input = $form->render_field(
992 + 'select2',
993 + array(
994 + 'name' => esc_attr( sprintf( '%1$s[%2$s_%3$s][%4$s][]', $option_key, $section, $name, 'action' ) ),
995 + 'value' => $action,
996 + 'options' => $action_values,
997 + 'classes' => 'action',
998 + 'data' => array(
999 + 'placeholder' => __( 'Any Action', 'stream' ),
1000 + ),
1001 + )
1002 + );
897 1003
898 - // IP Address input
899 - $ip_address_input = $form->render_field( 'select2', array(
900 - 'name' => esc_attr( sprintf( '%1$s[%2$s_%3$s][%4$s][]' , $option_key, $section, $name, 'ip_address' ) ),
901 - 'value' => $ip_address,
902 - 'classes' => 'ip_address',
903 - 'data' => array(
904 - 'placeholder' => esc_attr__( 'Any IP Address', 'stream' ),
905 - 'nonce' => esc_attr( wp_create_nonce( 'stream_get_ips' ) ),
906 - ),
907 - 'multiple' => true,
908 - ) );
1004 + // IP Address input.
1005 + $ip_address_input = $form->render_field(
1006 + 'select2',
1007 + array(
1008 + 'name' => esc_attr( sprintf( '%1$s[%2$s_%3$s][%4$s][]', $option_key, $section, $name, 'ip_address' ) ),
1009 + 'value' => $ip_address,
1010 + 'classes' => 'ip_address',
1011 + 'data' => array(
1012 + 'placeholder' => esc_attr__( 'Any IP Address', 'stream' ),
1013 + 'nonce' => esc_attr( wp_create_nonce( 'stream_get_ips' ) ),
1014 + ),
1015 + 'multiple' => true,
1016 + )
1017 + );
909 1018
910 - // Hidden helper input
1019 + // Hidden helper input.
911 1020 $helper_input = sprintf(
912 1021 '<input type="hidden" name="%1$s[%2$s_%3$s][%4$s][]" value="" />',
913 1022 esc_attr( $option_key ),
914 1023 esc_attr( $section ),
@@ -924,10 +1033,10 @@
924 1033 <td>%9$s</td>
925 1034 <td>%10$s</td>
926 1035 <th scope="row" class="actions-column">%11$s</th>
927 1036 </tr>',
928 - ( 0 !== $key % 2 ) ? 'alternate' : '',
929 - ( 'helper' === $key ) ? 'hidden helper' : '',
1037 + ( 0 !== (int) $key % 2 ) ? 'alternate' : '',
1038 + ( 'helper' === (string) $key ) ? 'hidden helper' : '',
930 1039 '<input class="cb-select" type="checkbox" />',
931 1040 $helper_input,
932 1041 $author_or_role_input,
933 1042 $connector_or_context_input,
@@ -961,9 +1070,9 @@
961 1070
962 1071 /**
963 1072 * Render Callback for post_types field
964 1073 *
965 - * @param array $field
1074 + * @param array $field Field to be rendered.
966 1075 *
967 1076 * @return string
968 1077 */
969 1078 public function output_field( $field ) {
@@ -974,9 +1083,9 @@
974 1083 }
975 1084
976 1085 $output = $this->render_field( $field );
977 1086
978 - echo $output; // xss ok
1087 + echo $output; // xss ok.
979 1088 }
980 1089
981 1090 /**
982 1091 * Get an array of user roles
@@ -996,9 +1105,9 @@
996 1105
997 1106 /**
998 1107 * Function will return all terms labels of given column
999 1108 *
1000 - * @param string $column string Name of the column
1109 + * @param string $column Name of the column.
1001 1110 *
1002 1111 * @return array
1003 1112 */
1004 1113 public function get_terms_labels( $column ) {
@@ -1031,14 +1140,14 @@
1031 1140 * Remove records when records TTL is shortened
1032 1141 *
1033 1142 * @action update_option_wp_stream
1034 1143 *
1035 - * @param array $old_value
1036 - * @param array $new_value
1144 + * @param array $old_value Old value.
1145 + * @param array $new_value New value.
1037 1146 */
1038 1147 public function updated_option_ttl_remove_records( $old_value, $new_value ) {
1039 - $ttl_before = isset( $old_value['general_records_ttl'] ) ? (int) $old_value['general_records_ttl'] : -1;
1040 - $ttl_after = isset( $new_value['general_records_ttl'] ) ? (int) $new_value['general_records_ttl'] : -1;
1148 + $ttl_before = isset( $old_value['general_records_ttl'] ) ? (int) $old_value['general_records_ttl'] : - 1;
1149 + $ttl_after = isset( $new_value['general_records_ttl'] ) ? (int) $new_value['general_records_ttl'] : - 1;
1041 1150
1042 1151 if ( $ttl_after < $ttl_before ) {
1043 1152 /**
1044 1153 * Action assists in purging when TTL is shortened
@@ -1050,8 +1159,10 @@
1050 1159 /**
1051 1160 * Get translations of serialized Stream settings
1052 1161 *
1053 1162 * @filter wp_stream_serialized_labels
1163 + *
1164 + * @param array $labels Setting labels.
1054 1165 *
1055 1166 * @return array Multidimensional array of fields
1056 1167 */
1057 1168 public function get_settings_translations( $labels ) {