PluginProbe ʕ •ᴥ•ʔ
MainWP Child Reports / 1.7
MainWP Child Reports v1.7
0.0.1 1.0 1.1 1.2 1.3 1.4 1.5 1.6 1.7 1.8 1.9.1 1.9.2 1.9.3 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 2.0.8 2.1 2.1.1 2.2 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.3 2.3.1 trunk
mainwp-child-reports / includes / settings.php
mainwp-child-reports / includes Last commit date
vendor 10 years ago admin.php 9 years ago class-wp-stream-author.php 10 years ago connector.php 9 years ago connectors.php 9 years ago context-query.php 10 years ago dashboard.php 10 years ago date-interval.php 10 years ago db.php 9 years ago filter-input.php 10 years ago functions.php 10 years ago install.php 9 years ago list-table.php 9 years ago live-update.php 9 years ago log.php 10 years ago network.php 10 years ago query.php 9 years ago settings.php 9 years ago
settings.php
700 lines
1 <?php
2 /**
3 * Settings class
4 *
5 * @author X-Team <x-team.com>
6 * @author Shady Sharaf <shady@x-team.com>
7 */
8 class MainWP_WP_Stream_Settings {
9
10 const KEY = 'mainwp_wp_stream';
11 const NETWORK_KEY = 'mainwp_wp_stream_network';
12 const DEFAULTS_KEY = 'mainwp_wp_stream_defaults';
13 public static $options = array();
14 public static $option_key = '';
15 public static $fields = array();
16 public static function load() {
17 self::$option_key = self::get_option_key();
18 self::$options = self::get_options();
19
20 // Register settings, and fields
21 add_action( 'admin_init', array( __CLASS__, 'register_settings' ) );
22
23 // Check if we need to flush rewrites rules
24 add_action( 'update_option_' . self::KEY, array( __CLASS__, 'updated_option_trigger_flush_rules' ), 10, 2 );
25
26 // Remove records when records TTL is shortened
27 add_action( 'update_option_' . self::KEY, array( __CLASS__, 'updated_option_ttl_remove_records' ), 10, 2 );
28
29 add_filter( 'mainwp_wp_stream_serialized_labels', array( __CLASS__, 'get_settings_translations' ) );
30
31 // Ajax callback function to search users
32 add_action( 'wp_ajax_mainwp_stream_get_users', array( __CLASS__, 'get_users' ) );
33
34 // Ajax callback function to search IPs
35 add_action( 'wp_ajax_mainwp_stream_get_ips', array( __CLASS__, 'get_ips' ) );
36 }
37
38 public static function get_users(){
39 if ( ! defined( 'DOING_AJAX' ) || ! current_user_can( MainWP_WP_Stream_Admin::SETTINGS_CAP ) ) {
40 return;
41 }
42
43 check_ajax_referer( 'stream_get_users', 'nonce' );
44
45 $response = (object) array(
46 'status' => false,
47 'message' => esc_html__( 'There was an error in the request', 'mainwp-child-reports' ),
48 );
49
50 $search = ( isset( $_POST['find'] )? wp_unslash( trim( $_POST['find'] ) ) : '' );
51 $request = (object) array(
52 'find' => $search,
53 );
54
55 add_filter( 'user_search_columns', array( __CLASS__, 'add_display_name_search_columns' ), 10, 3 );
56
57 $users = new WP_User_Query(
58 array(
59 'search' => "*{$request->find}*",
60 'search_columns' => array(
61 'user_login',
62 'user_nicename',
63 'user_email',
64 'user_url',
65 ),
66 'orderby' => 'display_name',
67 'number' => MainWP_WP_Stream_Admin::PRELOAD_AUTHORS_MAX,
68 )
69 );
70
71 remove_filter( 'user_search_columns', array( __CLASS__, 'add_display_name_search_columns' ), 10 );
72
73 if ( 0 === $users->get_total() ) {
74 wp_send_json_error( $response );
75 }
76
77 $response->status = true;
78 $response->message = '';
79 $response->users = array();
80
81 require_once MAINWP_WP_STREAM_INC_DIR . 'class-wp-stream-author.php';
82
83 foreach ( $users->results as $key => $user ) {
84 $author = new MainWP_WP_Stream_Author( $user->ID );
85
86 $args = array(
87 'id' => $author->ID,
88 'text' => $author->display_name,
89 );
90
91 $args['tooltip'] = esc_attr(
92 sprintf(
93 __( "ID: %d\nUser: %s\nEmail: %s\nRole: %s", 'mainwp-child-reports' ),
94 $author->id,
95 $author->user_login,
96 $author->user_email,
97 ucwords( $author->get_role() )
98 )
99 );
100
101 $args['icon'] = $author->get_avatar_src( 32 );
102
103 $response->users[] = $args;
104 }
105
106 if ( empty( $search ) || preg_match( '/wp|cli|system|unknown/i', $search ) ) {
107 $author = new MainWP_WP_Stream_Author( 0 );
108 $response->users[] = array(
109 'id' => $author->id,
110 'text' => $author->get_display_name(),
111 'icon' => $author->get_avatar_src( 32 ),
112 'tooltip' => esc_html__( 'Actions performed by the system when a user is not logged in (e.g. auto site upgrader, or invoking WP-CLI without --user)', 'mainwp-child-reports' ),
113 );
114 }
115
116 wp_send_json_success( $response );
117 }
118
119 public static function get_ips(){
120 if ( ! defined( 'DOING_AJAX' ) || ! current_user_can( MainWP_WP_Stream_Admin::SETTINGS_CAP ) ) {
121 return;
122 }
123
124 check_ajax_referer( 'stream_get_ips', 'nonce' );
125
126 global $wpdb;
127
128 $results = $wpdb->get_col(
129 $wpdb->prepare(
130 "
131 SELECT distinct(`ip`)
132 FROM `{$wpdb->mainwp_reports}`
133 WHERE `ip` LIKE %s
134 ORDER BY inet_aton(`ip`) ASC
135 LIMIT %d;
136 ",
137 like_escape( $_POST['find'] ) . '%',
138 $_POST['limit']
139 )
140 );
141
142 wp_send_json_success( $results );
143 }
144
145 public static function add_display_name_search_columns( $search_columns, $search, $query ){
146 $search_columns[] = 'display_name';
147
148 return $search_columns;
149 }
150
151 public static function get_option_key() {
152 $option_key = self::KEY;
153
154 $current_page = mainwp_wp_stream_filter_input( INPUT_GET, 'page' );
155
156 if ( ! $current_page ) {
157 $current_page = mainwp_wp_stream_filter_input( INPUT_GET, 'action' );
158 }
159
160 if ( 'mainwp_wp_stream_default_settings' === $current_page ) {
161 $option_key = self::DEFAULTS_KEY;
162 }
163
164 if ( 'mainwp_wp_stream_network_settings' === $current_page ) {
165 $option_key = self::NETWORK_KEY;
166 }
167
168 return apply_filters( 'mainwp_wp_stream_settings_option_key', $option_key );
169 }
170
171 public static function get_fields() {
172 if ( empty( self::$fields ) ) {
173 if (!class_exists('MainWP_WP_Stream_Admin'))
174 require_once MAINWP_WP_STREAM_INC_DIR . 'admin.php';
175 $branding_text = MainWP_WP_Stream_Admin::get_branding_title();
176 $branding_name = !empty($branding_text) ? $branding_text : 'MainWP Child';
177 $chk_label = 'Hide ' . $branding_name . ' Reports from reports';
178 $chk_desc = 'If selected, the ' . $branding_name . ' Reports plugin will be left out from reports for this site.';
179 $hide_child_plugins = get_option('mainwp_creport_hide_child_plugins', 'yes');
180 // to fix can not set default checked checkbox
181 $checkbox_hide_childs = '<tr><th scope="row"><label for="mainwp_creport_hide_child_plugins">' . $chk_label;
182 $checkbox_hide_childs .= '</label></th><td><label><input name="mainwp_creport_hide_child_plugins" id="mainwp_creport_hide_child_plugins" value="1" type="checkbox" ' . ($hide_child_plugins == 'yes' ? 'checked' : '') . '> ';
183 $checkbox_hide_childs .= '</label><p class="description">' . $chk_desc . '</p></td></tr>';
184
185 self::$fields = array(
186 'general' => array(
187 'title' => esc_html__( 'General', 'default' ),
188 'fields' => array(
189 array(
190 'name' => 'records_ttl',
191 'title' => esc_html__( 'Keep Records for', 'mainwp-child-reports' ),
192 'type' => 'number',
193 'class' => 'small-text',
194 'desc' => esc_html__( 'Maximum number of days to keep activity records. Leave blank to keep records forever.', 'mainwp-child-reports' ),
195 'default' => 180,
196 'after_field' => esc_html__( 'days', 'mainwp-child-reports' ),
197 ),
198 array(
199 'name' => 'period_of_time',
200 'title' => esc_html__( 'Minimum time between posts/pages update reports', 'mainwp-child-reports' ),
201 'type' => 'select',
202 'choices' => array( '0' => '0', '30' => '30', '60' => '60', '90' => '90', '120' => '120'),
203 'desc' => '',
204 'default' => 30,
205 'current_value' => array( '30' ),
206 'after_field' => esc_html__( 'minutes', 'mainwp-child-reports' ) . $checkbox_hide_childs, // to add checkbox
207 ),
208 array(
209 'name' => 'delete_all_records',
210 'title' => 'Reset ' . $branding_name . ' Reports Database',
211 'type' => 'link',
212 'href' => add_query_arg(
213 array(
214 'action' => 'mainwp_wp_stream_reset',
215 'mainwp_wp_stream_nonce' => wp_create_nonce( 'stream_nonce' ),
216 ),
217 admin_url( 'admin-ajax.php' )
218 ),
219 'desc' => esc_html__( 'Warning: Clicking this will delete all activity records from the database.', 'mainwp-child-reports' ),
220 'default' => 0,
221 ),
222 ),
223 ),
224 );
225 }
226
227 return self::$fields;
228 }
229
230 public static function get_options() {
231 $option_key = self::$option_key;
232
233 $defaults = self::get_defaults( $option_key );
234
235 if ( self::DEFAULTS_KEY === $option_key ) {
236 return $defaults;
237 }
238
239 return apply_filters(
240 'mainwp_wp_stream_options',
241 wp_parse_args(
242 (array) get_option( $option_key, array() ),
243 $defaults
244 ),
245 $option_key
246 );
247 }
248
249 public static function get_defaults() {
250 $fields = self::get_fields();
251 $defaults = array();
252
253 foreach ( $fields as $section_name => $section ) {
254 foreach ( $section['fields'] as $field ) {
255 $defaults[ $section_name.'_'.$field['name'] ] = isset( $field['default'] )
256 ? $field['default']
257 : null;
258 }
259 }
260
261 return apply_filters(
262 'mainwp_wp_stream_option_defaults',
263 wp_parse_args(
264 (array) get_site_option( self::DEFAULTS_KEY, array() ),
265 $defaults
266 )
267 );
268 }
269
270 public static function register_settings() {
271 $sections = self::get_fields();
272
273 register_setting( self::$option_key, self::$option_key, array( 'MainWP_WP_Stream_Settings', 'sanitize_settings' ) );
274
275 foreach ( $sections as $section_name => $section ) {
276 add_settings_section(
277 $section_name,
278 null,
279 '__return_false',
280 self::$option_key
281 );
282
283 foreach ( $section['fields'] as $field_idx => $field ) {
284 if ( ! isset( $field['type'] ) ) { // No field type associated, skip, no GUI
285 continue;
286 }
287 add_settings_field(
288 $field['name'],
289 $field['title'],
290 ( isset( $field['callback'] ) ? $field['callback'] : array( __CLASS__, 'output_field' ) ),
291 self::$option_key,
292 $section_name,
293 $field + array(
294 'section' => $section_name,
295 'label_for' => sprintf( '%s_%s_%s', self::$option_key, $section_name, $field['name'] ), // xss ok
296 )
297 );
298 }
299 }
300 }
301
302 public static function sanitize_settings( $input ) {
303 if (isset($_POST['mainwp_creport_hide_child_plugins'])) {
304 update_option('mainwp_creport_hide_child_plugins', 'yes');
305 } else {
306 update_option('mainwp_creport_hide_child_plugins', 'no');
307 }
308 return $input;
309 }
310
311 public static function updated_option_trigger_flush_rules( $old_value, $new_value ) {
312 if ( is_array( $new_value ) && is_array( $old_value ) ) {
313 $new_value = ( array_key_exists( 'general_private_feeds', $new_value ) ) ? $new_value['general_private_feeds'] : 0;
314 $old_value = ( array_key_exists( 'general_private_feeds', $old_value ) ) ? $old_value['general_private_feeds'] : 0;
315
316 if ( $new_value !== $old_value ) {
317 delete_option( 'rewrite_rules' );
318 }
319 }
320 }
321
322 public static function render_field( $field ) {
323 $output = null;
324 $type = isset( $field['type'] ) ? $field['type'] : null;
325 $section = isset( $field['section'] ) ? $field['section'] : null;
326 $name = isset( $field['name'] ) ? $field['name'] : null;
327 $class = isset( $field['class'] ) ? $field['class'] : null;
328 $placeholder = isset( $field['placeholder'] ) ? $field['placeholder'] : null;
329 $description = isset( $field['desc'] ) ? $field['desc'] : null;
330 $href = isset( $field['href'] ) ? $field['href'] : null;
331 $after_field = isset( $field['after_field'] ) ? $field['after_field'] : null;
332 $default = isset( $field['default'] ) ? $field['default'] : null;
333 $title = isset( $field['title'] ) ? $field['title'] : null;
334 $nonce = isset( $field['nonce'] ) ? $field['nonce'] : null;
335 $current_value = self::$options[ $section . '_' . $name ];
336 $option_key = self::$option_key;
337
338
339 if ( is_callable( $current_value ) ) {
340 $current_value = call_user_func( $current_value );
341 }
342
343 if ( ! $type || ! $section || ! $name ) {
344 return;
345 }
346
347 if ( 'multi_checkbox' === $type
348 && ( empty( $field['choices'] ) || ! is_array( $field['choices'] ) )
349 ) {
350 return;
351 }
352
353 switch ( $type ) {
354 case 'text':
355 case 'number':
356 $output = sprintf(
357 '<input type="%1$s" name="%2$s[%3$s_%4$s]" id="%2$s_%3$s_%4$s" class="%5$s" placeholder="%6$s" value="%7$s" /> %8$s',
358 esc_attr( $type ),
359 esc_attr( $option_key ),
360 esc_attr( $section ),
361 esc_attr( $name ),
362 esc_attr( $class ),
363 esc_attr( $placeholder ),
364 esc_attr( $current_value ),
365 $after_field // xss ok
366 );
367 break;
368 case 'checkbox':
369 $output = sprintf(
370 '<label><input type="checkbox" name="%1$s[%2$s_%3$s]" id="%1$s[%2$s_%3$s]" value="1" %4$s /> %5$s</label>',
371 esc_attr( $option_key ),
372 esc_attr( $section ),
373 esc_attr( $name ),
374 checked( $current_value, 1, false ),
375 $after_field // xss ok
376 );
377 break;
378 case 'multi_checkbox':
379 $output = sprintf(
380 '<div id="%1$s[%2$s_%3$s]"><fieldset>',
381 esc_attr( $option_key ),
382 esc_attr( $section ),
383 esc_attr( $name )
384 );
385 // Fallback if nothing is selected
386 $output .= sprintf(
387 '<input type="hidden" name="%1$s[%2$s_%3$s][]" value="__placeholder__" />',
388 esc_attr( $option_key ),
389 esc_attr( $section ),
390 esc_attr( $name )
391 );
392 $current_value = (array) $current_value;
393 $choices = $field['choices'];
394 if ( is_callable( $choices ) ) {
395 $choices = call_user_func( $choices );
396 }
397 foreach ( $choices as $value => $label ) {
398 $output .= sprintf(
399 '<label>%1$s <span>%2$s</span></label><br />',
400 sprintf(
401 '<input type="checkbox" name="%1$s[%2$s_%3$s][]" value="%4$s" %5$s />',
402 esc_attr( $option_key ),
403 esc_attr( $section ),
404 esc_attr( $name ),
405 esc_attr( $value ),
406 checked( in_array( $value, $current_value ), true, false )
407 ),
408 esc_html( $label )
409 );
410 }
411 $output .= '</fieldset></div>';
412 break;
413 case 'select':
414 $current_value = (array) self::$options[ $section . '_' . $name ];
415 $default_value = isset( $default['value'] ) ? $default['value'] : '-1';
416 $default_name = isset( $default['name'] ) ? $default['name'] : 'Choose Setting';
417
418 $output = sprintf(
419 '<select name="%1$s[%2$s_%3$s]" id="%1$s_%2$s_%3$s">',
420 esc_attr( $option_key ),
421 esc_attr( $section ),
422 esc_attr( $name )
423 );
424 $output .= sprintf(
425 '<option value="%1$s" %2$s>%3$s</option>',
426 esc_attr( $default_value ),
427 selected( in_array( $default_value, $current_value ), true, false ),
428 esc_html( $default_name )
429 );
430 foreach ( $field['choices'] as $value => $label ) {
431 $output .= sprintf(
432 '<option value="%1$s" %2$s>%3$s</option>',
433 esc_attr( $value ),
434 selected( in_array( $value, $current_value ), true, false ),
435 esc_html( $label )
436 );
437 }
438 $output .= '</select>';
439 $output .= $after_field;
440 break;
441 case 'file':
442 $output = sprintf(
443 '<input type="file" name="%1$s[%2$s_%3$s]" id="%1$s_%2$s_%3$s" class="%4$s">',
444 esc_attr( $option_key ),
445 esc_attr( $section ),
446 esc_attr( $name ),
447 esc_attr( $class )
448 );
449 break;
450 case 'link':
451 $output = sprintf(
452 '<a id="%1$s_%2$s_%3$s" class="%4$s" href="%5$s">%6$s</a>',
453 esc_attr( $option_key ),
454 esc_attr( $section ),
455 esc_attr( $name ),
456 esc_attr( $class ),
457 esc_attr( $href ),
458 esc_attr( $title )
459 );
460 break;
461 case 'select2' :
462 if ( ! isset ( $current_value ) ) {
463 $current_value = array();
464 }
465
466 if ( false !== ( $key = array_search( '__placeholder__', $current_value ) ) ) {
467 unset( $current_value[ $key ] );
468 }
469
470 $data_values = array();
471 $selected_values = array();
472 if ( isset( $field['choices'] ) ) {
473 $choices = $field['choices'];
474 if ( is_callable( $choices ) ) {
475 $param = ( isset( $field['param'] ) ) ? $field['param'] : null;
476 $choices = call_user_func( $choices, $param );
477 }
478 foreach ( $choices as $key => $value ) {
479 $data_values[] = array( 'id' => $key, 'text' => $value );
480 if ( in_array( $key, $current_value ) ) {
481 $selected_values[] = array( 'id' => $key, 'text' => $value );
482 }
483 }
484 $class .= ' with-source';
485 } else {
486 foreach ( $current_value as $value ) {
487 if ( '__placeholder__' === $value || '' === $value ) {
488 continue;
489 }
490 $selected_values[] = array( 'id' => $value, 'text' => $value );
491 }
492 }
493
494 $output = sprintf(
495 '<div id="%1$s[%2$s_%3$s]">',
496 esc_attr( $option_key ),
497 esc_attr( $section ),
498 esc_attr( $name )
499 );
500 $output .= sprintf(
501 '<input type="hidden" data-values=\'%1$s\' data-selected=\'%2$s\' value="%3$s" class="select2-select %4$s" data-select-placeholder="%5$s-%6$s-select-placeholder" %7$s />',
502 esc_attr( json_encode( $data_values ) ),
503 esc_attr( json_encode( $selected_values ) ),
504 esc_attr( implode( ',', $current_value ) ),
505 $class,
506 esc_attr( $section ),
507 esc_attr( $name ),
508 isset( $nonce ) ? sprintf( ' data-nonce="%s"', esc_attr( wp_create_nonce( $nonce ) ) ) : ''
509 );
510 // to store data with default value if nothing is selected
511 $output .= sprintf(
512 '<input type="hidden" name="%1$s[%2$s_%3$s][]" class="%2$s-%3$s-select-placeholder" value="__placeholder__" />',
513 esc_attr( $option_key ),
514 esc_attr( $section ),
515 esc_attr( $name )
516 );
517 $output .= '</div>';
518 break;
519 case 'select2_user_role':
520 $current_value = (array)$current_value;
521 $data_values = array();
522
523 if ( isset( $field['choices'] ) ) {
524 $choices = $field['choices'];
525 if ( is_callable( $choices ) ) {
526 $param = ( isset( $field['param'] ) ) ? $field['param'] : null;
527 $choices = call_user_func( $choices, $param );
528 }
529 } else {
530 $choices = array();
531 }
532
533 foreach ( $choices as $key => $role ) {
534 $args = array( 'id' => $key, 'text' => $role );
535 $users = get_users( array( 'role' => $key ) );
536 if ( count( $users ) ) {
537 $args['user_count'] = sprintf( _n( '1 user', '%s users', count( $users ), 'mainwp-child-reports' ), count( $users ) );
538 }
539 $data_values[] = $args;
540 }
541
542 $selected_values = array();
543 foreach ( $current_value as $value ) {
544 if ( ! is_string( $value ) && ! is_numeric( $value ) ) {
545 continue;
546 }
547
548 if ( '__placeholder__' === $value || '' === $value ) {
549 continue;
550 }
551
552 if ( is_numeric( $value ) ) {
553 $user = new WP_User( $value );
554 $selected_values[] = array( 'id' => $user->ID, 'text' => $user->display_name );
555 } else {
556 foreach ( $data_values as $role ) {
557 if ( $role['id'] !== $value ) {
558 continue;
559 }
560 $selected_values[] = $role;
561 }
562 }
563 }
564
565 $output = sprintf(
566 '<div id="%1$s[%2$s_%3$s]">',
567 esc_attr( $option_key ),
568 esc_attr( $section ),
569 esc_attr( $name )
570 );
571 $output .= sprintf(
572 '<input type="hidden" data-values=\'%1$s\' data-selected=\'%2$s\' value="%3$s" class="select2-select %5$s" data-select-placeholder="%4$s-%5$s-select-placeholder" data-nonce="%6$s" />',
573 json_encode( $data_values ),
574 json_encode( $selected_values ),
575 esc_attr( implode( ',', $current_value ) ),
576 esc_attr( $section ),
577 esc_attr( $name ),
578 esc_attr( wp_create_nonce( 'stream_get_users' ) )
579 );
580 // to store data with default value if nothing is selected
581 $output .= sprintf(
582 '<input type="hidden" name="%1$s[%2$s_%3$s][]" class="%2$s-%3$s-select-placeholder" value="__placeholder__" />',
583 esc_attr( $option_key ),
584 esc_attr( $section ),
585 esc_attr( $name )
586 );
587 $output .= '</div>';
588 break;
589 }
590 $output .= ! empty( $description ) ? sprintf( '<p class="description">%s</p>', $description /* xss ok */ ) : null;
591
592 return $output;
593 }
594
595 public static function output_field( $field ) {
596 $method = 'output_' . $field['name'];
597
598 if ( method_exists( __CLASS__, $method ) ) {
599 return call_user_func( array( __CLASS__, $method ), $field );
600 }
601
602 $output = self::render_field( $field );
603
604 echo $output; // xss okay
605 }
606
607 public static function get_roles() {
608 $wp_roles = new WP_Roles();
609 $roles = array();
610
611 foreach ( $wp_roles->get_names() as $role => $label ) {
612 $roles[ $role ] = translate_user_role( $label );
613 }
614
615 return $roles;
616 }
617
618 public static function get_connectors() {
619 return MainWP_WP_Stream_Connectors::$term_labels['stream_connector'];
620 }
621
622 public static function get_default_connectors() {
623 return array_keys( MainWP_WP_Stream_Connectors::$term_labels['stream_connector'] );
624 }
625
626 public static function get_terms_labels( $column ) {
627 $return_labels = array();
628
629 if ( isset ( MainWP_WP_Stream_Connectors::$term_labels[ 'stream_' . $column ] ) ) {
630 $return_labels = MainWP_WP_Stream_Connectors::$term_labels[ 'stream_' . $column ];
631 ksort( $return_labels );
632 }
633
634 return $return_labels;
635 }
636
637 public static function get_active_connectors() {
638 $excluded_connectors = self::get_excluded_by_key( 'connectors' );
639 $active_connectors = array_diff( array_keys( self::get_terms_labels( 'connector' ) ), $excluded_connectors );
640 $active_connectors = wp_list_filter( $active_connectors, array( '__placeholder__' ), 'NOT' );
641
642 return $active_connectors;
643 }
644
645 public static function get_excluded_by_key( $column ) {
646 $option_name = ( 'authors' === $column || 'roles' === $column ) ? 'exclude_authors_and_roles' : 'exclude_' . $column;
647
648 $excluded_values = ( isset( self::$options[ $option_name ] ) ) ? self::$options[ $option_name ] : array();
649
650 if ( is_callable( $excluded_values ) ) {
651 $excluded_values = call_user_func( $excluded_values );
652 }
653
654 $excluded_values = wp_list_filter( $excluded_values, array( '__placeholder__' ), 'NOT' );
655
656 if ( 'exclude_authors_and_roles' === $option_name ) {
657 // Convert numeric strings to integers
658 array_walk( $excluded_values,
659 function ( &$value ) {
660 if ( is_numeric( $value ) ) {
661 $value = absint( $value );
662 }
663 }
664 );
665
666 $filter = ( 'roles' === $column ) ? 'is_string' : 'is_int'; // Author roles are always strings and author ID's are always integers
667
668 $excluded_values = array_values( array_filter( $excluded_values, $filter ) ); // Reset the array keys
669 }
670
671 return $excluded_values;
672 }
673
674 public static function get_settings_translations( $labels ) {
675 if ( ! isset( $labels[ self::KEY ] ) ) {
676 $labels[ self::KEY ] = array();
677 }
678
679 foreach ( self::get_fields() as $section_slug => $section ) {
680 foreach ( $section['fields'] as $field ) {
681 $labels[ self::KEY ][ sprintf( '%s_%s', $section_slug, $field['name'] ) ] = $field['title'];
682 }
683 }
684
685 return $labels;
686 }
687
688 public static function updated_option_ttl_remove_records( $old_value, $new_value ) {
689 $ttl_before = isset( $old_value['general_records_ttl'] ) ? (int) $old_value['general_records_ttl'] : -1;
690 $ttl_after = isset( $new_value['general_records_ttl'] ) ? (int) $new_value['general_records_ttl'] : -1;
691
692 if ( $ttl_after < $ttl_before ) {
693 /**
694 * Action assists in purging when TTL is shortened
695 */
696 do_action( 'mainwp_wp_stream_auto_purge' );
697 }
698 }
699 }
700