PluginProbe
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification / 5.5.0
Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification v5.5.0
5.5.0 5.4.0 5.3.2 5.3.1 5.1.6 5.1.5 trunk 2.1.5 2.11 2.12 2.13 2.15 3.0.0 3.0.1 3.0.2 3.0.3 3.0.5 3.0.51 3.0.60 3.0.61 3.0.62 3.0.70 3.0.71 3.0.72 3.1.0 All 34 releases
double-opt-in / core / SanitizeHelper.class.php

SanitizeHelper.class.php in Double Opt-In for Contact Form 7 – Secure, GDPR-Compliant Email Verification 5.5.0, at core/SanitizeHelper.class.php

73 lines 2.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace forge12\contactform7\CF7DoubleOptIn;
4
5 use Forge12\Shared\Logger;
6
7 if ( ! defined( 'ABSPATH' ) ) {
8 exit;
9 }
10
11 class SanitizeHelper {
12 /**
13 * Sanitizes an array by sanitizing the keys and values recursively.
14 *
15 * @param array $data The array to be sanitized.
16 *
17 * @return array The sanitized array.
18 */
19 public static function sanitize_array( $data ): array {
20 $logger = Logger::getInstance();
21 $logger->info( 'Starting sanitization of an array.', [
22 'plugin' => 'double-opt-in',
23 'data_type' => gettype($data),
24 ] );
25
26 if ( ! is_array( $data ) ) {
27 $logger->warning( 'Provided data is not an array. Returning an empty array.', [
28 'plugin' => 'double-opt-in',
29 'data_type' => gettype($data),
30 ] );
31 return [];
32 }
33
34 $sanitized_data = [];
35 foreach ( $data as $key => $value ) {
36 $sanitized_key = sanitize_text_field( $key );
37
38 $do_sanitize_key_filter = apply_filters('f12_cf7_doubleoptin_do_sanitize_key_'.$key, true);
39 $logger->debug( 'Applying sanitization filter for key: ' . $key, [
40 'plugin' => 'double-opt-in',
41 'filter_result' => $do_sanitize_key_filter,
42 ] );
43
44 // Use a more explicit check for 'body' to avoid issues if the filter returns false for a different reason
45 if ( ! $do_sanitize_key_filter || $key === 'body' ) {
46 $sanitized_data[$key] = $value;
47 $logger->info( 'Skipping sanitization for key "' . $key . '" based on filter or key name.', [
48 'plugin' => 'double-opt-in',
49 ] );
50 continue;
51 }
52
53 if ( is_array( $value ) ) {
54 $sanitized_data[ $sanitized_key ] = self::sanitize_array( $value );
55 $logger->debug( 'Recursively sanitizing array value for key: ' . $sanitized_key, [
56 'plugin' => 'double-opt-in',
57 ] );
58 } else {
59 $sanitized_data[ $sanitized_key ] = wp_kses_post( $value );
60 $logger->debug( 'Sanitizing string value for key "' . $sanitized_key . '" using wp_kses_post.', [
61 'plugin' => 'double-opt-in',
62 ] );
63 }
64 }
65
66 $logger->notice( 'Array sanitization completed successfully.', [
67 'plugin' => 'double-opt-in',
68 ] );
69
70 return $sanitized_data;
71 }
72
73 }