| @@ 157-189 (lines=33) @@ | ||
| 154 | */ |
|
| 155 | public static function sanitize_attributes(array $attributes, $custom_sanitization = array()) |
|
| 156 | { |
|
| 157 | foreach ($attributes as $key => $value) { |
|
| 158 | // is a custom sanitization callback specified ? |
|
| 159 | if ( isset($custom_sanitization[$key])) { |
|
| 160 | $callback = $custom_sanitization[$key]; |
|
| 161 | if ($callback === 'skip_sanitization') { |
|
| 162 | $attributes[$key] = $value; |
|
| 163 | continue; |
|
| 164 | } else if (function_exists($callback)){ |
|
| 165 | $attributes[$key] = $callback($value); |
|
| 166 | continue; |
|
| 167 | } |
|
| 168 | } |
|
| 169 | switch (true) { |
|
| 170 | case $value === null : |
|
| 171 | case is_int($value) : |
|
| 172 | case is_float($value) : |
|
| 173 | // typical booleans |
|
| 174 | case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true) : |
|
| 175 | $attributes[$key] = $value; |
|
| 176 | break; |
|
| 177 | case is_string($value) : |
|
| 178 | $attributes[$key] = sanitize_text_field($value); |
|
| 179 | break; |
|
| 180 | case is_array($value) : |
|
| 181 | $attributes[$key] = \EES_Shortcode::sanitize_attributes($value); |
|
| 182 | break; |
|
| 183 | default : |
|
| 184 | // only remaining data types are Object and Resource |
|
| 185 | // which are not allowed as shortcode attributes |
|
| 186 | $attributes[$key] = null; |
|
| 187 | break; |
|
| 188 | } |
|
| 189 | } |
|
| 190 | return $attributes; |
|
| 191 | } |
|
| 192 | ||
| @@ 179-212 (lines=34) @@ | ||
| 176 | private function sanitizeAttributes(array $attributes) |
|
| 177 | { |
|
| 178 | $custom_sanitization = $this->customAttributeSanitizationMap(); |
|
| 179 | foreach ($attributes as $key => $value) { |
|
| 180 | // is a custom sanitization callback specified ? |
|
| 181 | if (isset($custom_sanitization[$key])) { |
|
| 182 | $callback = $custom_sanitization[$key]; |
|
| 183 | if ($callback === 'skip_sanitization') { |
|
| 184 | $attributes[$key] = $value; |
|
| 185 | continue; |
|
| 186 | } |
|
| 187 | if (function_exists($callback)) { |
|
| 188 | $attributes[$key] = $callback($value); |
|
| 189 | continue; |
|
| 190 | } |
|
| 191 | } |
|
| 192 | switch (true) { |
|
| 193 | case $value === null : |
|
| 194 | case is_int($value) : |
|
| 195 | case is_float($value) : |
|
| 196 | // typical booleans |
|
| 197 | case in_array($value, array(true, 'true', '1', 'on', 'yes', false, 'false', '0', 'off', 'no'), true) : |
|
| 198 | $attributes[$key] = $value; |
|
| 199 | break; |
|
| 200 | case is_string($value) : |
|
| 201 | $attributes[$key] = sanitize_text_field($value); |
|
| 202 | break; |
|
| 203 | case is_array($value) : |
|
| 204 | $attributes[$key] = $this->sanitizeAttributes($value); |
|
| 205 | break; |
|
| 206 | default : |
|
| 207 | // only remaining data types are Object and Resource |
|
| 208 | // which are not allowed as shortcode attributes |
|
| 209 | $attributes[$key] = null; |
|
| 210 | break; |
|
| 211 | } |
|
| 212 | } |
|
| 213 | return $attributes; |
|
| 214 | } |
|
| 215 | ||