C:\xampp\htdocs\landing\wp-content\updraft\plugins-old\better-wp-security\core\lib\validator.php


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
<?php

use iThemesSecurity\User_Groups\Matchables_Source;

abstract class 
ITSEC_Validator {
    protected 
$run_validate_matching_fields true;
    protected 
$run_validate_matching_types true;

    protected 
$settings_obj;
    protected 
$defaults;
    protected 
$settings;
    protected 
$previous_settings;

    protected 
$can_save true;
    protected 
$needs_refresh false;
    protected 
$errors = array();
    protected 
$messages = array();
    protected 
$vars_to_skip_validate_matching_fields = array();
    protected 
$vars_to_skip_validate_matching_types = array();


    public function 
__construct() {
        
$this->settings_obj ITSEC_Modules::get_settings_obj$this->get_id() );

        if ( ! 
is_callable( array( $this->settings_obj'get_defaults' ) ) ) {
            return;
        }

        
$this->defaults $this->settings_obj->get_defaults();
    }

    abstract public function 
get_id();

    protected function 
sanitize_settings() { }

    protected function 
validate_settings() { }

    public function 
validate$settings ) {
        
$this->settings          $settings;
        
$this->previous_settings ITSEC_Modules::get_settings$this->get_id() );

        
$this->sanitize_settings();

        if ( 
$this->run_validate_matching_fields ) {
            
$this->validate_matching_fields();
        }

        if ( 
$this->run_validate_matching_types ) {
            
$this->validate_matching_types();
        }

        
$this->validate_settings();
    }

    protected function 
validate_matching_fields() {
        
$id $this->get_id();

        foreach ( 
array_keys$this->defaults ) as $name ) {
            if ( ! isset( 
$this->settings$name ] ) && ! in_array$name$this->vars_to_skip_validate_matching_fields ) ) {
                
$this->add_error( new WP_Error"itsec-validator-$id-validate_matching_fields-missing-name-$name"sprintf__'A validation function for %1$s received data that did not have the required entry for %2$s.''better-wp-security' ), $id$name ) ) );
                
$this->set_can_savefalse );
            }
        }

        foreach ( 
array_keys$this->settings ) as $name ) {
            if ( ! isset( 
$this->defaults$name ] ) && ! in_array$name$this->vars_to_skip_validate_matching_fields ) ) {
                
$this->add_error( new WP_Error"itsec-validator-$id-validate_matching_fields-unknown-name-$name"sprintf__'A validation function for %1$s received data that has an entry for %2$s when no such entry exists.''better-wp-security' ), $id$name ) ) );
                
$this->set_can_savefalse );
            }
        }
    }

    protected function 
validate_matching_types() {
        
$id $this->get_id();

        foreach ( 
$this->defaults as $name => $value ) {
            if ( 
in_array$name$this->vars_to_skip_validate_matching_types ) ) {
                
// This is to prevent errors for a specific var appearing twice.
                
continue;
            }

            if ( ! isset( 
$this->settings$name ] ) ) {
                
// Skip missing entries to allow implementations that use validate_matching_types() but not
                // validate_matching_fields().
                
continue;
            }

            if ( 
gettype$value ) !== gettype$this->settings$name ] ) ) {
                
$this->add_error( new WP_Error"itsec-validator-$id-validate_matching_types-inmatching-type-$name"sprintf__'A validation function for %1$s received data that does not match the expected data type for the %2$s entry. A data type of %3$s was expected, but a data type of %4$s was received.''better-wp-security' ), $id$namegettype$value ), gettype$this->settings$name ] ) ) ) );
                
$this->set_can_savefalse );
            }
        }
    }

    final protected function 
set_default_if_empty$vars ) {
        foreach ( (array) 
$vars as $var ) {
            if ( ! isset( 
$this->settings$var ] ) || '' === $this->settings$var ] ) {
                
$this->settings$var ] = $this->defaults$var ];
            }
        }
    }

    final protected function 
set_previous_if_empty$vars ) {
        foreach ( (array) 
$vars as $var ) {
            if ( ! isset( 
$this->settings$var ] ) || '' === $this->settings$var ] ) {
                
$this->settings$var ] = $this->previous_settings$var ];
            }
        }
    }

    final protected function 
preserve_setting_if_exists$vars ) {
        foreach ( (array) 
$vars as $var ) {
            if ( 
array_key_exists$var$this->previous_settings ) && ( ! isset( $this->settings$var ] ) || '' === $this->settings$var ] ) ) {
                
$this->settings$var ] = $this->previous_settings$var ];
            }
        }
    }

    
/**
     * Sanitizes a setting.
     *
     * @param string|callable $type                  The sanitization to apply.
     * @param string          $var                   The variable name.
     * @param string          $name                  The human facing label for the setting.
     * @param bool            $prevent_save_on_error Whether to prevent the module from saving if sanitization fails.
     * @param bool            $trim_value            Whether to trim the value if it is a string.
     * @param string          $custom_error          A custom error message to use instead of the default.
     *
     * @return bool Whether sanitization passed or not.
     */
    
final protected function sanitize_setting$type$var$name$prevent_save_on_error true$trim_value true$custom_error '' ) {
        
$id $this->get_id();

        if ( ! isset( 
$this->settings$var ] ) ) {
            
$this->add_error( new WP_Error"itsec-validator-missing-var-$id-$var"sprintf__'A validation check for %1$s failed. The %2$s value is missing. This could be due to a problem with the iThemes Security installation or an invalid modification. Please reinstall iThemes Security and try again.''better-wp-security' ), $id$name ) ) );

            return 
false;
        }

        if ( 
$trim_value && is_string$this->settings$var ] ) ) {
            
$this->settings$var ] = trim$this->settings$var ] );
        }

        
$error false;

        if ( 
'string' === $type ) {
            
$this->settings$var ] = (string) $this->settings$var ];
        } elseif ( 
'non-empty-string' === $type ) {
            
$this->settings$var ] = (string) $this->settings$var ];

            if ( empty( 
$this->settings$var ] ) ) {
                
$error sprintf__'The %1$s value cannot be empty.''better-wp-security' ), $name );
            }
        } elseif ( 
'title' === $type ) {
            
$this->settings$var ] = sanitize_title$this->settings$var ] );
        } elseif ( 
'non-empty-title' === $type ) {
            
$this->settings$var ] = sanitize_title$this->settings$var ] );

            if ( empty( 
$this->settings$var ] ) ) {
                
$error sprintf__'The %1$s value cannot be empty.''better-wp-security' ), $name );
            }
        } elseif ( 
'text' === $type || 'non-empty-text' === $type ) {
            
$string = (string) $this->settings$var ];
            
$string wp_strip_all_tags$string );

            if ( 
$trim_value ) {
                
$string trim$string );
            }

            
$this->settings$var ] = $string;

            if ( 
'non-empty-text' === $type && empty( $this->settings$var ] ) ) {
                
$error sprintf__'The %1$s value cannot be empty.''better-wp-security' ), $name );
            }
        } elseif ( 
'array' === $type ) {
            if ( ! 
is_array$this->settings$var ] ) ) {
                if ( empty( 
$this->settings$var ] ) ) {
                    
$this->settings$var ] = array();
                } else {
                    
$this->settings$var ] = array( $this->settings$var ] );
                }
            }
        } elseif ( 
'bool' === $type ) {
            if ( 
'false' === $this->settings$var ] ) {
                
$this->settings$var ] = false;
            } elseif ( 
'true' === $this->settings$var ] ) {
                
$this->settings$var ] = true;
            } else {
                
$this->settings$var ] = (bool) $this->settings$var ];
            }
        } elseif ( 
'int' === $type ) {
            
$test_val intval$this->settings$var ] );
            if ( (string) 
$test_val === (string) $this->settings$var ] ) {
                
$this->settings$var ] = $test_val;
            } else {
                
$error sprintf__'The %1$s value must be an integer.''better-wp-security' ), $name );
            }
        } elseif ( 
'positive-int' === $type ) {
            
$test_val intval$this->settings$var ] );
            if ( (string) 
$test_val === (string) $this->settings$var ] && $test_val >= ) {
                
$this->settings$var ] = $test_val;
            } else {
                
$error sprintf__'The %1$s value must be a positive integer.''better-wp-security' ), $name );
            }
        } elseif ( 
'number' === $type ) {
            if ( 
is_numeric$this->settings$var ] ) ) {
                
$this->settings$var ] = (float) $this->settings$var ];
            } else {
                
$error sprintf__'The %1$s value must be a number.''better-wp-security' ), $name );
            }
        } elseif ( 
'email' === $type ) {
            
$this->settings$var ] = sanitize_text_field$this->settings$var ] );

            if ( empty( 
$this->settings$var ] ) || ! is_email$this->settings$var ] ) ) {
                
$error sprintf__'The %1$s value must be a valid email address.''better-wp-security' ), $name );
            }
        } elseif ( 
'valid-username' === $type ) {
            
$this->settings$var ] = sanitize_text_field$this->settings$var ] );

            if ( ! empty( 
$this->settings$var ] ) && ! validate_username$this->settings$var ] ) ) {
                
$error sprintf__'The %1$s value is not a valid username.''better-wp-security' ), $name );
            }
        } elseif ( 
'date' === $type ) {
            
$val $this->settings$var ];

            
$separator '[\-/\. ]';

            if ( 
preg_match"|^(\d\d\d\d)$separator(\d\d?)$separator(\d\d?)$|"$val$match ) ) {
                
$year  intval$match[1] );
                
$month intval$match[2] );
                
$day   intval$match[3] );

                if ( ! 
checkdate$month$day$year ) ) {
                    
$error sprintf__'The %1$s value must be a valid date.''better-wp-security' ), $name );
                }
            } else {
                
$error sprintf__'The %1$s value must be a valid date in the format of YYYY-MM-DD.''better-wp-security' ), $name );
            }
        } elseif ( 
'writable-directory' === $type ) {
            if ( ! 
is_string$this->settings$var ] ) ) {
                
$error sprintf__'The %1$s value must be a string.''better-wp-security' ), $name );
            } else {
                require_once( 
ITSEC_Core::get_core_dir() . 'lib/class-itsec-lib-directory.php' );

                
$this->settings$var ] = rtrim$this->settings$var ], DIRECTORY_SEPARATOR );

                if ( ! 
ITSEC_Lib_Directory::is_dir$this->settings$var ] ) ) {
                    
$result ITSEC_Lib_Directory::create$this->settings$var ] );

                    if ( 
is_wp_error$result ) ) {
                        
$error sprintf_x'The directory supplied in %1$s cannot be used as a valid directory. %2$s''%1$s is the input name. %2$s is the error message.''better-wp-security' ), $name$result->get_error_message() );
                    }
                }

                if ( empty( 
$error ) && ! ITSEC_Lib_Directory::is_writable$this->settings$var ] ) ) {
                    
$error sprintf__'The directory supplied in %1$s is not writable. Please select a directory that can be written to.''better-wp-security' ), $name );
                }

                if ( empty( 
$error ) ) {
                    
ITSEC_Lib_Directory::add_file_listing_protection$this->settings$var ] );
                }
            }
        } elseif ( 
'writable-file' === $type ) {
            if ( ! 
is_string$this->settings$var ] ) ) {
                
$error sprintf__'The %1$s value must be a string.''better-wp-security' ), $name );
            } else {
                require_once( 
ITSEC_Core::get_core_dir() . 'lib/class-itsec-lib-directory.php' );

                if ( ! 
ITSEC_Lib_File::is_file$this->settings$var ] ) && ITSEC_Lib_File::exists$this->settings$var ] ) ) {
                    
$error sprintf__'The file path supplied in %1$s cannot be used as it already exists but is not a file. Please supply a valid file path.''better-wp-security' ), $name );
                } else {
                    
$result ITSEC_Lib_Directory::createdirname$this->settings$var ] ) );

                    if ( 
is_wp_error$result ) ) {
                        
$error sprintf_x'The file path supplied in %1$s cannot be used as the parent directory cannot be created. %2$s''%1$s is the input name. %2$s is the error message.''better-wp-security' ), $name$result->get_error_message() );
                    } elseif ( ! 
ITSEC_Lib_File::exists$this->settings$var ] ) ) {
                        
$result ITSEC_Lib_File::write$this->settings$var ], '' );

                        if ( 
is_wp_error$result ) ) {
                            
$error sprintf__'The file path supplied in %1$s could not be created. Please supply a file path that can be written to.''better-wp-security' ), $name );
                        } elseif ( ! 
is_writable$this->settings$var ] ) ) {
                            
$error sprintf__'The file path supplied in %1$s was successfully created, but it cannot be updated. Please supply a file path that can be written to.''better-wp-security' ), $name );
                        }
                    } elseif ( ! 
is_writable$this->settings$var ] ) ) {
                        
$error sprintf__'The file path supplied in %1$s is not writable. Please supply a file path that can be written to.''better-wp-security' ), $name );
                    }
                }
            }
        } elseif ( 
is_array$type ) && === count$type ) && $this === $type[0] ) {
            
$this->settings$var ] = $this->convert_string_to_array$this->settings$var ] );

            if ( ! 
is_array$this->settings$var ] ) ) {
                
$error sprintf__'The %1$s value must be a string with each entry separated by a new line.''better-wp-security' ), $name );
            } else {
                
$invalid_entries = array();

                foreach ( 
$this->settings$var ] as $index => $entry ) {
                    
$entry                            sanitize_text_fieldtrim$entry ) );
                    
$this->settings$var ][ $index ] = $entry;

                    if ( empty( 
$entry ) ) {
                        unset( 
$this->settings$var ][ $index ] );
                    } else {
                        
$result call_user_func$type$entry );

                        if ( 
false === $result ) {
                            
$invalid_entries[] = $entry;
                        } else {
                            
$this->settings$var ][ $index ] = $result;
                        }
                    }
                }

                
$this->settings$var ] = array_unique$this->settings$var ] );

                if ( ! empty( 
$invalid_entries ) ) {
                    
$error wp_sprintf_n'The following entry in %1$s is invalid: %2$l''The following entries in %1$s are invalid: %2$l'count$invalid_entries ), 'better-wp-security' ), $name$invalid_entries );
                }
            }
        } elseif ( 
is_array$type ) ) {
            if ( 
is_array$this->settings$var ] ) ) {
                
$invalid_entries = array();

                foreach ( 
$this->settings$var ] as $index => $entry ) {
                    
$entry                            sanitize_text_fieldtrim$entry ) );
                    
$this->settings$var ][ $index ] = $entry;

                    if ( empty( 
$entry ) ) {
                        unset( 
$this->settings$var ][ $index ] );
                    } elseif ( ! 
in_array$entry$typetrue ) ) {
                        
$invalid_entries[] = $entry;
                    }
                }

                
$this->settings$var ] = array_unique$this->settings$var ] );

                if ( ! empty( 
$invalid_entries ) ) {
                    
$error wp_sprintf_n'The following entry in %1$s is invalid: %2$l''The following entries in %1$s are invalid: %2$l'count$invalid_entries ), 'better-wp-security' ), $name$invalid_entries );
                }
            } elseif ( ! 
in_array$this->settings$var ], $typetrue ) ) {
                
$error wp_sprintf_n'The valid value for %1$s is: %2$l.''The valid values for %1$s are: %2$l.'count$type ), 'better-wp-security' ), $name$type );
                
$type  'array';
            }
        } elseif ( 
'canonical-roles' === $type ) {
            
$roles = array( 'administrator''editor''author''contributor''subscriber' );

            if ( 
is_array$this->settings$var ] ) ) {
                
$invalid_entries = array();

                foreach ( 
$this->settings$var ] as $index => $entry ) {
                    
$entry                            sanitize_text_fieldtrim$entry ) );
                    
$this->settings$var ][ $index ] = $entry;

                    if ( empty( 
$entry ) ) {
                        unset( 
$this->settings$var ][ $index ] );
                    } elseif ( ! 
in_array$entry$rolestrue ) ) {
                        
$invalid_entries[] = $entry;
                    }
                }

                
$this->settings$var ] = array_unique$this->settings$var ] );

                if ( ! empty( 
$invalid_entries ) ) {
                    
$error wp_sprintf_n'The following entry in %1$s is invalid: %2$l''The following entries in %1$s are invalid: %2$l'count$invalid_entries ), 'better-wp-security' ), $name$invalid_entries );
                }
            } elseif ( ! 
in_array$this->settings$var ], $rolestrue ) ) {
                
$error wp_sprintf_n'The valid value for %1$s is: %2$l.''The valid values for %1$s are: %2$l.'count$roles ), 'better-wp-security' ), $name$roles );
                
$type  'array';
            }
        } elseif ( 
'newline-separated-array' === $type ) {
            
$this->settings$var ] = $this->convert_string_to_array$this->settings$var ] );

            if ( ! 
is_array$this->settings$var ] ) ) {
                
$error sprintf__'The %1$s value must be a string with each entry separated by a new line.''better-wp-security' ), $name );
            }
        } elseif ( 
'newline-separated-emails' === $type ) {
            
$this->settings$var ] = $this->convert_string_to_array$this->settings$var ] );

            if ( ! 
is_array$this->settings$var ] ) ) {
                
$error sprintf__'The %1$s value must be a string with each entry separated by a new line.''better-wp-security' ), $name );
            } else {
                
$invalid_emails = array();

                foreach ( 
$this->settings$var ] as $index => $email ) {
                    
$email                            sanitize_text_fieldtrim$email ) );
                    
$this->settings$var ][ $index ] = $email;

                    if ( empty( 
$email ) ) {
                        unset( 
$this->settings$var ][ $index ] );
                    } elseif ( ! 
is_email$email ) ) {
                        
$invalid_emails[] = $email;
                    }
                }

                
$this->settings$var ] = array_unique$this->settings$var ] );

                if ( ! empty( 
$invalid_emails ) ) {
                    
$error wp_sprintf_n'The following email in %1$s is invalid: %2$l''The following emails in %1$s are invalid: %2$l'count$invalid_emails ), 'better-wp-security' ), $name$invalid_emails );
                }
            }
        } elseif ( 
'newline-separated-ips' === $type ) {
            
$this->settings$var ] = $this->convert_string_to_array$this->settings$var ] );

            if ( ! 
is_array$this->settings$var ] ) ) {
                
$error sprintf__'The %1$s value must be a string with each entry separated by a new line.''better-wp-security' ), $name );
            } else {
                require_once( 
ITSEC_Core::get_core_dir() . 'lib/class-itsec-lib-ip-tools.php' );

                
$invalid_ips = array();

                foreach ( 
$this->settings$var ] as $index => $ip ) {
                    
$ip trim$ip );

                    if ( 
'' === $ip ) {
                        unset( 
$this->settings$var ][ $index ] );
                    } else {
                        
$validated_ip ITSEC_Lib_IP_Tools::ip_wild_to_ip_cidr$ip );

                        if ( 
false === $validated_ip ) {
                            
$invalid_ips[] = $ip;
                        } else {
                            
$this->settings$var ][ $index ] = $validated_ip;
                        }
                    }
                }

                
$this->settings$var ] = array_unique$this->settings$var ] );

                if ( ! empty( 
$invalid_ips ) ) {
                    
$error wp_sprintf_n'The following IP in %1$s is invalid: %2$l''The following IPs in %1$s are invalid: %2$l'count$invalid_ips ), 'better-wp-security' ), $name$invalid_ips );
                }
            }
        } elseif ( 
'user-groups' === $type ) {
            
$source ITSEC_Modules::get_container()->getMatchables_Source::class );

            
$this->sanitize_setting'array'$var$name$prevent_save_on_error$trim_value$custom_error );
            
$invalid_user_groups = [];

            foreach ( 
$this->settings$var ] as $i => $group ) {
                if ( ! 
is_string$group ) ) {
                    unset( 
$this->settings$var ][ $i ] );

                    continue;
                }

                if ( 
$source->has$group ) ) {
                    continue;
                }

                if ( 
in_array$group$this->previous_settings$var ], true ) ) {
                    unset( 
$this->settings$var ][ $i ] );
                } else {
                    
$invalid_user_groups[] = $group;
                }
            }

            
$this->settings$var ] = wp_is_numeric_array$this->settings$var ] ) ? array_values$this->settings$var ] ) : $this->settings$var ];

            if ( 
$invalid_user_groups ) {
                
$error wp_sprintf_n'The following entry in %1$s is invalid: %2$l''The following entries in %1$s are invalid: %2$l'count$invalid_user_groups ), 'better-wp-security' ), $name$invalid_user_groups );
            }
        } elseif ( 
'user-group' === $type ) {
            
$source ITSEC_Modules::get_container()->getMatchables_Source::class );

            if ( ! 
$source->has$this->settings$var ] ) ) {
                
$error sprintf__'The user group selected for %1$s is invalid.''better-wp-security' ), $name );
            }
        } elseif ( 
'newline-separated-extensions' === $type ) {
            
$this->settings$var ] = $this->convert_string_to_array$this->settings$var ] );

            if ( ! 
is_array$this->settings$var ] ) ) {
                
$error sprintf__'The %1$s value must be a string with each entry separated by a new line.''better-wp-security' ), $name );
            } else {
                
$invalid_extensions = array();

                foreach ( 
$this->settings$var ] as $index => $extension ) {
                    if ( ! 
preg_match'/^(\.[^.]+)+$/'$extension ) ) {
                        
$invalid_extensions[] = $extension;
                    }
                }

                
$this->settings$var ] = array_unique$this->settings$var ] );

                if ( ! empty( 
$invalid_extensions ) ) {
                    
$error wp_sprintf_n'The following extension in %1$s is invalid: %2$l''The following extensions in %1$s are invalid: %2$l'count$invalid_extensions ), 'better-wp-security' ), $name$invalid_extensions );
                }
            }
        } elseif ( 
is_string$type ) && === strpos$type'cb-items:' ) ) {

            list( , 
$method ) = explode':'$type );

            if ( ! 
is_array$this->settings$var ] ) ) {
                
$error sprintf__'The %1$s value must be an array.''better-wp-security' ), $name );
            } else {
                
$invalid_entries = array();

                foreach ( 
$this->settings$var ] as $index => $entry ) {

                    if ( empty( 
$entry ) ) {
                        unset( 
$this->settings$var ][ $index ] );
                    } else {
                        
$result $this->{$method}( $entry$index );

                        if ( 
false === $result ) {
                            
$invalid_entries[] = is_string$entry ) ? $entry $index;
                        } elseif ( 
is_wp_error$result ) ) {
                            
$invalid_entries[] = "'{$index}': {$result->get_error_message()}";
                        } else {
                            
$this->settings$var ][ $index ] = $result;
                        }
                    }
                }

                if ( ! empty( 
$invalid_entries ) ) {
                    
$error wp_sprintf_n'The following entry in %1$s is invalid: %2$l''The following entries in %1$s are invalid: %2$l'count$invalid_entries ), 'better-wp-security' ), $name$invalid_entries );
                }
            }

        } else {
            
/* translators: 1: sanitize type, 2: input name */
            
$error sprintf__'An invalid sanitize type of "%1$s" was received for the %2$s input.''better-wp-security' ), $type$name );
        }

        if ( 
false !== $error ) {
            if ( 
$custom_error ) {
                
$error $custom_error;
            }

            
$this->add_error$this->generate_error$id$var$type$error ) );
            
$this->vars_to_skip_validate_matching_types[] = $var;

            if ( 
$prevent_save_on_error && ITSEC_Core::is_interactive() ) {
                
$this->set_can_savefalse );
            }

            return 
false;
        }

        return 
true;
    }

    protected function 
generate_error$id$var$type$error ) {
        return new 
WP_Error"itsec-validator-$id-invalid-type-$var-$type"$error );
    }

    final protected function 
convert_string_to_array$string ) {
        if ( 
is_string$string ) ) {
            
$array preg_split"/[\r\n]+/"$string );
        } elseif ( 
is_array$string ) ) {
            
$array $string;
        } else {
            return 
$string;
        }

        foreach ( 
$array as $key => $val ) {
            
$val trim$val );

            if ( empty( 
$val ) ) {
                unset( 
$array$key ] );
            } else {
                
$array$key ] = $val;
            }
        }

        return 
$array;
    }

    
/**
     * Adds an error to be displayed to the user.
     *
     * @param \WP_Error $error
     */
    
final protected function add_error$error ) {
        
$this->errors[] = $error;
    }

    final public function 
found_errors() {
        if ( empty( 
$this->errors ) ) {
            return 
false;
        } else {
            return 
true;
        }
    }

    final public function 
get_errors() {
        return 
$this->errors;
    }

    final protected function 
add_message$message ) {
        
$this->messages[] = $message;
    }

    final public function 
get_messages() {
        return 
$this->messages;
    }

    final protected function 
set_can_save$can_save ) {
        
$this->can_save = (bool) $can_save;
    }

    final public function 
can_save() {
        return 
$this->can_save;
    }

    final protected function 
set_needs_refresh$needs_refresh ) {
        
$this->needs_refresh = (bool) $needs_refresh;
    }

    final public function 
needs_refresh() {
        return 
$this->needs_refresh;
    }

    final public function 
get_settings() {
        return 
$this->settings;
    }
}
x

Windows NT KPTV 6.2 build 9200 (Windows Server 2012 Datacenter Edition) i586