Skip to content

Commit d8cab36

Browse files
Fix deep sanitization of arrays, fixes issue with GROUPINGS (and other array structures) not being sent.
1 parent a9a5b5a commit d8cab36

File tree

1 file changed

+14
-12
lines changed

1 file changed

+14
-12
lines changed

includes/class-request.php

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ protected function normalize_data( array $data ) {
9797
$data = stripslashes_deep( $data );
9898

9999
// sanitize all scalar values
100-
$data = $this->sanitize_data_array( $data );
100+
$data = $this->sanitize_deep( $data );
101101

102102
/**
103103
* @filter `mc4wp_form_data`
@@ -109,22 +109,24 @@ protected function normalize_data( array $data ) {
109109
}
110110

111111
/**
112-
* @param $dirty
112+
* @param $value
113113
*
114-
* @return array
114+
* @return array|string
115115
*/
116-
public function sanitize_data_array( $dirty ) {
117-
$clean = array();
118-
119-
foreach( $dirty as $field => $value ) {
120-
if ( is_scalar( $value ) ) {
121-
$clean[ $field ] = sanitize_text_field( $value );
122-
} elseif( is_array( $value ) ) {
123-
$clean[ $field ] = array_map( array( $this, 'sanitize_data_array' ), $value );
116+
public function sanitize_deep( $value ) {
117+
118+
if ( is_scalar( $value ) ) {
119+
$value = sanitize_text_field( $value );
120+
} elseif( is_array( $value ) ) {
121+
$value = array_map( array( $this, 'sanitize_deep' ), $value );
122+
} elseif ( is_object($value) ) {
123+
$vars = get_object_vars( $value );
124+
foreach ($vars as $key=>$data) {
125+
$value->{$key} = $this->sanitize_deep( $data );
124126
}
125127
}
126128

127-
return $clean;
129+
return $value;
128130
}
129131

130132
/**

0 commit comments

Comments
 (0)