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-settings.php +244 -144 3.2.13.4.2 View file →
@@ -1,5 +1,6 @@
1 1 <?php
2 +
2 3 namespace WP_Stream;
3 4
4 5 use \WP_Roles;
5 6 use \WP_User;
@@ -5,10 +6,12 @@
5 6 use \WP_User;
6 7 use \WP_User_Query;
7 8
8 9 class Settings {
10 +
9 11 /**
10 12 * Hold Plugin class
13 + *
11 14 * @var Plugin
12 15 */
13 16 public $plugin;
14 17
@@ -54,12 +57,26 @@
54 57 // Register settings, and fields
55 58 add_action( 'admin_init', array( $this, 'register_settings' ) );
56 59
57 60 // Remove records when records TTL is shortened
58 - add_action( 'update_option_' . $this->option_key, array( $this, 'updated_option_ttl_remove_records' ), 10, 2 );
61 + add_action(
62 + 'update_option_' . $this->option_key,
63 + array(
64 + $this,
65 + 'updated_option_ttl_remove_records',
66 + ),
67 + 10,
68 + 2
69 + );
59 70
60 71 // Apply label translations for settings
61 - add_filter( 'wp_stream_serialized_labels', array( $this, 'get_settings_translations' ) );
72 + add_filter(
73 + 'wp_stream_serialized_labels',
74 + array(
75 + $this,
76 + 'get_settings_translations',
77 + )
78 + );
62 79
63 80 // Ajax callback function to search users
64 81 add_action( 'wp_ajax_stream_get_users', array( $this, 'get_users' ) );
65 82
@@ -94,13 +111,21 @@
94 111 $request = (object) array(
95 112 'find' => $search,
96 113 );
97 114
98 - add_filter( 'user_search_columns', array( $this, 'add_display_name_search_columns' ), 10, 3 );
115 + add_filter(
116 + 'user_search_columns',
117 + array(
118 + $this,
119 + 'add_display_name_search_columns',
120 + ),
121 + 10,
122 + 3
123 + );
99 124
100 125 $users = new WP_User_Query(
101 126 array(
102 - 'search' => "*{$request->find}*",
127 + 'search' => "*{$request->find}*",
103 128 'search_columns' => array(
104 129 'user_login',
105 130 'user_nicename',
106 131 'user_email',
@@ -105,14 +130,21 @@
105 130 'user_nicename',
106 131 'user_email',
107 132 'user_url',
108 133 ),
109 - 'orderby' => 'display_name',
110 - 'number' => $this->plugin->admin->preload_users_max,
134 + 'orderby' => 'display_name',
135 + 'number' => $this->plugin->admin->preload_users_max,
111 136 )
112 137 );
113 138
114 - remove_filter( 'user_search_columns', array( $this, 'add_display_name_search_columns' ), 10 );
139 + remove_filter(
140 + 'user_search_columns',
141 + array(
142 + $this,
143 + 'add_display_name_search_columns',
144 + ),
145 + 10
146 + );
115 147
116 148 if ( 0 === $users->get_total() ) {
117 149 wp_send_json_error( $response );
118 150 }
@@ -120,17 +152,17 @@
120 152
121 153 if ( is_multisite() && is_super_admin() ) {
122 154 $super_admins = get_super_admins();
123 155 foreach ( $super_admins as $admin ) {
124 - $user = get_user_by( 'login', $admin );
156 + $user = get_user_by( 'login', $admin );
125 157 $users_array[] = $user;
126 158 }
127 159 }
128 160
129 - $response->status = true;
130 - $response->message = '';
131 - $response->roles = $this->get_roles();
132 - $response->users = array();
161 + $response->status = true;
162 + $response->message = '';
163 + $response->roles = $this->get_roles();
164 + $response->users = array();
133 165 $users_added_to_response = array();
134 166
135 167 foreach ( $users_array as $key => $user ) {
136 168 // exclude duplications:
@@ -148,8 +180,9 @@
148 180 );
149 181
150 182 $args['tooltip'] = esc_attr(
151 183 sprintf(
184 + // translators: Placeholders refers to a user ID, a username, an email address, and a user role (e.g. "42", "administrator", "foo@bar.com", "subscriber").
152 185 __( 'ID: %1$d\nUser: %2$s\nEmail: %3$s\nRole: %4$s', 'stream' ),
153 186 $author->id,
154 187 $author->user_login,
155 188 $author->user_email,
@@ -163,15 +196,15 @@
163 196 }
164 197
165 198 usort(
166 199 $response->users,
167 - function( $a, $b ) {
200 + function ( $a, $b ) {
168 201 return strcmp( $a['text'], $b['text'] );
169 202 }
170 203 );
171 204
172 205 if ( empty( $search ) || preg_match( '/wp|cli|system|unknown/i', $search ) ) {
173 - $author = new Author( 0 );
206 + $author = new Author( 0 );
174 207 $response->users[] = array(
175 208 'id' => '0',
176 209 'text' => $author->get_display_name(),
177 210 'icon' => $author->get_avatar_src( 32 ),
@@ -182,10 +215,10 @@
182 215 wp_send_json_success( $response );
183 216 }
184 217
185 218 /**
186 - * Ajax callback function to search IP addresses, used on exclude setting page
187 - */
219 + * Ajax callback function to search IP addresses, used on exclude setting page
220 + */
188 221 public function get_ips() {
189 222 if ( ! defined( 'DOING_AJAX' ) || ! current_user_can( $this->plugin->admin->settings_cap ) ) {
190 223 return;
191 224 }
@@ -195,11 +228,14 @@
195 228 $ips = $this->plugin->db->existing_records( 'ip' );
196 229 $find = wp_stream_filter_input( INPUT_POST, 'find' );
197 230
198 231 if ( isset( $find['term'] ) && '' !== $find['term'] ) {
199 - $ips = array_filter( $ips, function ( $ip ) use ( $find ) {
200 - return 0 === strpos( $ip, $find['term'] );
201 - } );
232 + $ips = array_filter(
233 + $ips,
234 + function ( $ip ) use ( $find ) {
235 + return 0 === strpos( $ip, $find['term'] );
236 + }
237 + );
202 238 }
203 239
204 240 if ( $ips ) {
205 241 wp_send_json_success( $ips );
@@ -210,11 +246,11 @@
210 246
211 247 /**
212 248 * Filter the columns to search in a WP_User_Query search.
213 249 *
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.
250 + * @param array $search_columns Array of column names to be searched.
251 + * @param string $search Text being searched.
252 + * @param \WP_User_Query $query current WP_User_Query instance.
217 253 *
218 254 * @return array
219 255 */
220 256 public function add_display_name_search_columns( $search_columns, $search, $query ) {
@@ -253,18 +289,18 @@
253 289 * @return array
254 290 */
255 291 public function get_fields() {
256 292 $fields = array(
257 - 'general' => array(
293 + 'general' => array(
258 294 'title' => esc_html__( 'General', 'stream' ),
259 295 'fields' => array(
260 296 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' ),
297 + 'name' => 'role_access',
298 + 'title' => esc_html__( 'Role Access', 'stream' ),
299 + 'type' => 'multi_checkbox',
300 + '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' ),
301 + 'choices' => $this->get_roles(),
302 + 'default' => array( 'administrator' ),
267 303 ),
268 304 array(
269 305 'name' => 'records_ttl',
270 306 'title' => esc_html__( 'Keep Records for', 'stream' ),
@@ -286,18 +322,18 @@
286 322 'default' => 0,
287 323 ),
288 324 ),
289 325 ),
290 - 'exclude' => array(
326 + 'exclude' => array(
291 327 'title' => esc_html__( 'Exclude', 'stream' ),
292 328 'fields' => array(
293 329 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',
330 + 'name' => 'rules',
331 + 'title' => esc_html__( 'Exclude Rules', 'stream' ),
332 + 'type' => 'rule_list',
333 + 'desc' => esc_html__( 'Create rules to exclude certain kinds of activity from being recorded by Stream.', 'stream' ),
334 + 'default' => array(),
335 + 'nonce' => 'stream_get_ips',
300 336 ),
301 337 ),
302 338 ),
303 339 'advanced' => array(
@@ -311,22 +347,22 @@
311 347 'after_field' => esc_html__( 'Enabled', 'stream' ),
312 348 'default' => 0,
313 349 ),
314 350 array(
315 - 'name' => 'delete_all_records',
316 - 'title' => esc_html__( 'Reset Stream Database', 'stream' ),
317 - 'type' => 'link',
318 - 'href' => add_query_arg(
351 + 'name' => 'delete_all_records',
352 + 'title' => esc_html__( 'Reset Stream Database', 'stream' ),
353 + 'type' => 'link',
354 + 'href' => add_query_arg(
319 355 array(
320 - 'action' => 'wp_stream_reset',
321 - 'wp_stream_nonce' => wp_create_nonce( 'stream_nonce' ),
356 + 'action' => 'wp_stream_reset',
357 + 'wp_stream_nonce_reset' => wp_create_nonce( 'stream_nonce_reset' ),
322 358 ),
323 359 admin_url( 'admin-ajax.php' )
324 360 ),
325 - 'class' => 'warning',
326 - 'desc' => esc_html__( 'Warning: This will delete all activity records from the database.', 'stream' ),
327 - 'default' => 0,
328 - 'sticky' => 'bottom',
361 + 'class' => 'warning',
362 + 'desc' => esc_html__( 'Warning: This will delete all activity records from the database.', 'stream' ),
363 + 'default' => 0,
364 + 'sticky' => 'bottom',
329 365 ),
330 366 ),
331 367 ),
332 368 );
@@ -344,21 +380,18 @@
344 380
345 381 array_push( $fields['advanced']['fields'], $akismet_tracking );
346 382 }
347 383
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 - );
384 + $wp_cron_tracking = array(
385 + 'name' => 'wp_cron_tracking',
386 + 'title' => esc_html__( 'WP Cron Tracking', 'stream' ),
387 + 'type' => 'checkbox',
388 + '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' ),
389 + 'after_field' => esc_html__( 'Enabled', 'stream' ),
390 + 'default' => 0,
391 + );
358 392
359 - array_push( $fields['advanced']['fields'], $wp_cron_tracking );
360 - }
393 + array_push( $fields['advanced']['fields'], $wp_cron_tracking );
361 394
362 395 /**
363 396 * Filter allows for modification of options fields
364 397 *
@@ -437,9 +470,16 @@
437 470 */
438 471 public function register_settings() {
439 472 $sections = $this->get_fields();
440 473
441 - register_setting( $this->option_key, $this->option_key, array( $this, 'sanitize_settings' ) );
474 + register_setting(
475 + $this->option_key,
476 + $this->option_key,
477 + array(
478 + $this,
479 + 'sanitize_settings',
480 + )
481 + );
442 482
443 483 foreach ( $sections as $section_name => $section ) {
444 484 add_settings_section(
445 485 $section_name,
@@ -455,14 +495,18 @@
455 495
456 496 add_settings_field(
457 497 $field['name'],
458 498 $field['title'],
459 - ( isset( $field['callback'] ) ? $field['callback'] : array( $this, 'output_field' ) ),
499 + ( isset( $field['callback'] ) ? $field['callback'] : array(
500 + $this,
501 + 'output_field',
502 + ) ),
460 503 $this->option_key,
461 504 $section_name,
462 505 $field + array(
463 506 'section' => $section_name,
464 - 'label_for' => sprintf( '%s_%s_%s', $this->option_key, $section_name, $field['name'] ), // xss ok
507 + 'label_for' => sprintf( '%s_%s_%s', $this->option_key, $section_name, $field['name'] ),
508 + // xss ok
465 509 )
466 510 );
467 511 }
468 512 }
@@ -491,9 +535,9 @@
491 535 if ( empty( $type ) || ! isset( $input[ $name ] ) || '' === $input[ $name ] ) {
492 536 continue;
493 537 }
494 538
495 - // Sanitize depending on the type of field
539 + // Sanitize depending on the type of field.
496 540 switch ( $type ) {
497 541 case 'number':
498 542 $output[ $name ] = is_numeric( $input[ $name ] ) ? intval( trim( $input[ $name ] ) ) : '';
499 543 break;
@@ -503,14 +547,17 @@
503 547 default:
504 548 if ( is_array( $input[ $name ] ) ) {
505 549 $output[ $name ] = $input[ $name ];
506 550
507 - // Support all values in multidimentional arrays too
508 - array_walk_recursive( $output[ $name ], function( &$v, $k ) {
509 - $v = trim( $v );
510 - } );
551 + // Support all values in multidimentional arrays too.
552 + array_walk_recursive(
553 + $output[ $name ],
554 + function ( &$v ) {
555 + $v = sanitize_text_field( trim( $v ) );
556 + }
557 + );
511 558 } else {
512 - $output[ $name ] = trim( $input[ $name ] );
559 + $output[ $name ] = sanitize_text_field( trim( $input[ $name ] ) );
513 560 }
514 561 }
515 562 }
516 563 }
@@ -563,11 +610,9 @@
563 610 if ( ! $type || ! $section || ! $name ) {
564 611 return '';
565 612 }
566 613
567 - if ( 'multi_checkbox' === $type
568 - && ( empty( $field['choices'] ) || ! is_array( $field['choices'] ) )
569 - ) {
614 + if ( 'multi_checkbox' === $type && ( empty( $field['choices'] ) || ! is_array( $field['choices'] ) ) ) {
570 615 return '';
571 616 }
572 617
573 618 switch ( $type ) {
@@ -626,10 +671,10 @@
626 671 esc_attr( $option_key ),
627 672 esc_attr( $section ),
628 673 esc_attr( $name )
629 674 );
630 - // Fallback if nothing is selected
631 - $output .= sprintf(
675 + // Fallback if nothing is selected.
676 + $output .= sprintf(
632 677 '<input type="hidden" name="%1$s[%2$s_%3$s][]" value="__placeholder__" />',
633 678 esc_attr( $option_key ),
634 679 esc_attr( $section ),
635 680 esc_attr( $name )
@@ -634,9 +679,9 @@
634 679 esc_attr( $section ),
635 680 esc_attr( $name )
636 681 );
637 682 $current_value = (array) $current_value;
638 - $choices = $field['choices'];
683 + $choices = $field['choices'];
639 684 if ( is_callable( $choices ) ) {
640 685 $choices = call_user_func( $choices );
641 686 }
642 687 foreach ( $choices as $value => $label ) {
@@ -701,9 +746,9 @@
701 746 esc_attr( $href ),
702 747 esc_attr( $title )
703 748 );
704 749 break;
705 - case 'select2' :
750 + case 'select2':
706 751 if ( ! isset( $current_value ) ) {
707 752 $current_value = '';
708 753 }
709 754
@@ -720,16 +765,26 @@
720 765 $child_values = array();
721 766 if ( isset( $value['children'] ) ) {
722 767 $child_values = array();
723 768 foreach ( $value['children'] as $child_key => $child_value ) {
724 - $child_values[] = array( 'id' => $child_key, 'text' => $child_value );
769 + $child_values[] = array(
770 + 'id' => $child_key,
771 + 'text' => $child_value,
772 + );
725 773 }
726 774 }
727 775 if ( isset( $value['label'] ) ) {
728 - $data_values[] = array( 'id' => $key, 'text' => $value['label'], 'children' => $child_values );
776 + $data_values[] = array(
777 + 'id' => $key,
778 + 'text' => $value['label'],
779 + 'children' => $child_values,
780 + );
729 781 }
730 782 } else {
731 - $data_values[] = array( 'id' => $key, 'text' => $value );
783 + $data_values[] = array(
784 + 'id' => $key,
785 + 'text' => $value,
786 + );
732 787 }
733 788 }
734 789 $class .= ' with-source';
735 790 }
@@ -741,8 +796,9 @@
741 796 esc_attr( $name ),
742 797 esc_attr( wp_stream_json_encode( $data_values ) ),
743 798 esc_attr( $current_value ),
744 799 esc_attr( $class ),
800 + // translators: Placeholder refers to the title of the dropdown menu (e.g. "users")
745 801 sprintf( esc_html__( 'Any %s', 'stream' ), $title )
746 802 );
747 803
748 804 $output = sprintf(
@@ -753,14 +809,15 @@
753 809 $input_html
754 810 );
755 811
756 812 break;
757 - case 'rule_list' :
758 - $form = new Form_Generator;
813 + case 'rule_list':
814 + $users = count_users();
815 + $form = new Form_Generator();
759 816 $output = '<p class="description">' . esc_html( $description ) . '</p>';
760 817
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' ) );
818 + $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' ) );
819 + $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 820
764 821 $output .= sprintf( '<div class="tablenav top">%1$s</div>', $actions_top );
765 822 $output .= '<table class="wp-list-table widefat fixed stream-exclude-list">';
766 823
@@ -784,13 +841,18 @@
784 841 );
785 842
786 843 $exclude_rows = array();
787 844
788 - // Prepend an empty row
789 - $current_value['exclude_row'] = array( 'helper' => '' ) + ( isset( $current_value['exclude_row'] ) ? $current_value['exclude_row'] : array() );
845 + // Account for when no rules have been added yet.
846 + if ( ! is_array( $current_value ) ) {
847 + $current_value = array();
848 + }
790 849
850 + // Prepend an empty row.
851 + $current_value['exclude_row'] = ( isset( $current_value['exclude_row'] ) ? $current_value['exclude_row'] : array() ) + array( 'helper' => '' );
852 +
791 853 foreach ( $current_value['exclude_row'] as $key => $value ) {
792 - // Prepare values
854 + // Prepare values.
793 855 $author_or_role = isset( $current_value['author_or_role'][ $key ] ) ? $current_value['author_or_role'][ $key ] : '';
794 856 $connector = isset( $current_value['connector'][ $key ] ) ? $current_value['connector'][ $key ] : '';
795 857 $context = isset( $current_value['context'][ $key ] ) ? $current_value['context'][ $key ] : '';
796 858 $action = isset( $current_value['action'][ $key ] ) ? $current_value['action'][ $key ] : '';
@@ -800,13 +862,16 @@
800 862 $author_or_role_values = array();
801 863 $author_or_role_selected = array();
802 864
803 865 foreach ( $this->get_roles() as $role_id => $role ) {
804 - $args = array( 'value' => $role_id, 'text' => $role );
805 - $users = count_users();
866 + $args = array(
867 + 'value' => $role_id,
868 + 'text' => $role,
869 + );
806 870 $count = isset( $users['avail_roles'][ $role_id ] ) ? $users['avail_roles'][ $role_id ] : 0;
807 871
808 872 if ( ! empty( $count ) ) {
873 + // translators: Placeholder refers to a number of users (e.g. "42")
809 874 $args['user_count'] = sprintf( _n( '%d user', '%d users', absint( $count ), 'stream' ), absint( $count ) );
810 875 }
811 876
812 877 if ( $role_id === $author_or_role ) {
@@ -819,23 +884,29 @@
819 884
820 885 if ( empty( $author_or_role_selected ) && is_numeric( $author_or_role ) ) {
821 886 $user = new WP_User( $author_or_role );
822 887 $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 );
888 + $author_or_role_selected = array(
889 + 'value' => $user->ID,
890 + 'text' => $display_name,
891 + );
824 892 $author_or_role_values[] = $author_or_role_selected;
825 893 }
826 894
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 - ) );
895 + $author_or_role_input = $form->render_field(
896 + 'select2',
897 + array(
898 + 'name' => esc_attr( sprintf( '%1$s[%2$s_%3$s][%4$s][]', $option_key, $section, $name, 'author_or_role' ) ),
899 + 'options' => $author_or_role_values,
900 + 'classes' => 'author_or_role',
901 + 'data' => array(
902 + 'placeholder' => esc_html__( 'Any Author or Role', 'stream' ),
903 + 'nonce' => esc_attr( wp_create_nonce( 'stream_get_users' ) ),
904 + 'selected-id' => isset( $author_or_role_selected['value'] ) ? esc_attr( $author_or_role_selected['value'] ) : '',
905 + 'selected-text' => isset( $author_or_role_selected['text'] ) ? esc_attr( $author_or_role_selected['text'] ) : '',
906 + ),
907 + )
908 + );
838 909
839 910 // Context dropdown menu
840 911 $context_values = array();
841 912
@@ -844,69 +915,98 @@
844 915 $child_values = array();
845 916 if ( isset( $context_data['children'] ) ) {
846 917 $child_values = array();
847 918 foreach ( $context_data['children'] as $child_id => $child_value ) {
848 - $child_values[] = array( 'value' => $context_id . '-' . $child_id, 'text' => $child_value, 'parent' => $context_id );
919 + $child_values[] = array(
920 + 'value' => $context_id . '-' . $child_id,
921 + 'text' => $child_value,
922 + 'parent' => $context_id,
923 + );
849 924 }
850 925 }
851 926 if ( isset( $context_data['label'] ) ) {
852 - $context_values[] = array( 'value' => $context_id, 'text' => $context_data['label'], 'children' => $child_values );
927 + $context_values[] = array(
928 + 'value' => $context_id,
929 + 'text' => $context_data['label'],
930 + 'children' => $child_values,
931 + );
853 932 }
854 933 } else {
855 - $context_values[] = array( 'value' => $context_id, 'text' => $context_data );
934 + $context_values[] = array(
935 + 'value' => $context_id,
936 + 'text' => $context_data,
937 + );
856 938 }
857 939 }
858 940
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 - ) );
941 + $connector_or_context_input = $form->render_field(
942 + 'select2',
943 + array(
944 + 'name' => esc_attr( sprintf( '%1$s[%2$s_%3$s][%4$s][]', $option_key, $section, $name, 'connector_or_context' ) ),
945 + 'options' => $context_values,
946 + 'classes' => 'connector_or_context',
947 + 'data' => array(
948 + 'group' => 'connector',
949 + 'placeholder' => __( 'Any Context', 'stream' ),
950 + ),
951 + )
952 + );
868 953
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 - ) );
954 + $connector_input = $form->render_field(
955 + 'hidden',
956 + array(
957 + 'name' => esc_attr( sprintf( '%1$s[%2$s_%3$s][%4$s][]', $option_key, $section, $name, 'connector' ) ),
958 + 'value' => $connector,
959 + 'classes' => 'connector',
960 + )
961 + );
874 962
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 - ) );
963 + $context_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, 'context' ) ),
967 + 'value' => $context,
968 + 'classes' => 'context',
969 + )
970 + );
880 971
881 972 // Action dropdown menu
882 973 $action_values = array();
883 974
884 975 foreach ( $this->get_terms_labels( 'action' ) as $action_id => $action_data ) {
885 - $action_values[] = array( 'value' => $action_id, 'text' => $action_data );
976 + $action_values[] = array(
977 + 'value' => $action_id,
978 + 'text' => $action_data,
979 + );
886 980 }
887 981
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 - ) );
982 + $action_input = $form->render_field(
983 + 'select2',
984 + array(
985 + 'name' => esc_attr( sprintf( '%1$s[%2$s_%3$s][%4$s][]', $option_key, $section, $name, 'action' ) ),
986 + 'value' => $action,
987 + 'options' => $action_values,
988 + 'classes' => 'action',
989 + 'data' => array(
990 + 'placeholder' => __( 'Any Action', 'stream' ),
991 + ),
992 + )
993 + );
897 994
898 995 // 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 - ) );
996 + $ip_address_input = $form->render_field(
997 + 'select2',
998 + array(
999 + 'name' => esc_attr( sprintf( '%1$s[%2$s_%3$s][%4$s][]', $option_key, $section, $name, 'ip_address' ) ),
1000 + 'value' => $ip_address,
1001 + 'classes' => 'ip_address',
1002 + 'data' => array(
1003 + 'placeholder' => esc_attr__( 'Any IP Address', 'stream' ),
1004 + 'nonce' => esc_attr( wp_create_nonce( 'stream_get_ips' ) ),
1005 + ),
1006 + 'multiple' => true,
1007 + )
1008 + );
909 1009
910 1010 // Hidden helper input
911 1011 $helper_input = sprintf(
912 1012 '<input type="hidden" name="%1$s[%2$s_%3$s][%4$s][]" value="" />',
@@ -924,10 +1024,10 @@
924 1024 <td>%9$s</td>
925 1025 <td>%10$s</td>
926 1026 <th scope="row" class="actions-column">%11$s</th>
927 1027 </tr>',
928 - ( 0 !== $key % 2 ) ? 'alternate' : '',
929 - ( 'helper' === $key ) ? 'hidden helper' : '',
1028 + ( 0 !== (int) $key % 2 ) ? 'alternate' : '',
1029 + ( 'helper' === (string) $key ) ? 'hidden helper' : '',
930 1030 '<input class="cb-select" type="checkbox" />',
931 1031 $helper_input,
932 1032 $author_or_role_input,
933 1033 $connector_or_context_input,
@@ -1035,10 +1135,10 @@
1035 1135 * @param array $old_value
1036 1136 * @param array $new_value
1037 1137 */
1038 1138 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;
1139 + $ttl_before = isset( $old_value['general_records_ttl'] ) ? (int) $old_value['general_records_ttl'] : - 1;
1140 + $ttl_after = isset( $new_value['general_records_ttl'] ) ? (int) $new_value['general_records_ttl'] : - 1;
1041 1141
1042 1142 if ( $ttl_after < $ttl_before ) {
1043 1143 /**
1044 1144 * Action assists in purging when TTL is shortened