| 1 |
<?php |
| 2 |
|
| 3 |
namespace forge12\contactform7\CF7DoubleOptIn; |
| 4 |
|
| 5 |
if ( ! defined( 'ABSPATH' ) ) { |
| 6 |
exit; |
| 7 |
} |
| 8 |
|
| 9 |
class SanitizeHelper { |
| 10 |
/** |
| 11 |
* Sanitizes an array by sanitizing the keys and values recursively. |
| 12 |
* |
| 13 |
* @param array $data The array to be sanitized. |
| 14 |
* |
| 15 |
* @return array The sanitized array. |
| 16 |
*/ |
| 17 |
public static function sanitize_array( $data ): array { |
| 18 |
if ( ! is_array( $data ) ) { |
| 19 |
return []; |
| 20 |
} |
| 21 |
|
| 22 |
$sanitized_data = []; |
| 23 |
foreach ( $data as $key => $value ) { |
| 24 |
if(!apply_filters('f12_cf7_doubleoptin_do_sanitize_key_'.$key, true) || $key === 'body') { |
| 25 |
$sanitized_data[$key] = $value; |
| 26 |
continue; |
| 27 |
} |
| 28 |
|
| 29 |
if ( is_array( $value ) ) { |
| 30 |
$sanitized_data[ sanitize_text_field( $key ) ] = self::sanitize_array( $value ); |
| 31 |
} else { |
| 32 |
$sanitized_data[ sanitize_text_field( $key ) ] = wp_kses_post( $value ); |
| 33 |
} |
| 34 |
} |
| 35 |
|
| 36 |
return $sanitized_data; |
| 37 |
} |
| 38 |
|
| 39 |
} |