PluginProbe
Blocks – Reusable Content, Shortcodes & Site Variables / trunk
Blocks – Reusable Content, Shortcodes & Site Variables vtrunk
26.09.03.15 26.08.31.21 26.08.22.20 26.08.22.22 26.08.22.17 26.08.22.13 26.08.21.19 26.08.07.23 26.07.19.14 26.07.13.21 26.07.13.17 26.07.12.13 026.07.07.21 026.07.05.18 026.06.26.20 026.06.26.21 026.06.08.20 026.05.13.14 026.04.29.10 trunk 026.02.22.22 026.03.16.23 026.04.23.13
blocks / src / Transfer / PropertySanitizer.php

PropertySanitizer.php in Blocks – Reusable Content, Shortcodes & Site Variables trunk, at src/Transfer/PropertySanitizer.php

64 lines 1.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 declare(strict_types=1);
4
5 namespace RenzoJohnson\Blocks\Transfer;
6
7 \defined( 'ABSPATH' ) || exit;
8
9 final class PropertySanitizer {
10
11 /**
12 * @param array<mixed, mixed> $properties Imported properties.
13 * @return array<string, mixed>
14 */
15 public function sanitize( array $properties ): array {
16 $sanitized = array();
17
18 foreach ( $properties as $key => $value ) {
19 if ( ! \is_string( $key ) ) {
20 continue;
21 }
22
23 $key = \sanitize_key( $key );
24
25 if ( '' === $key ) {
26 continue;
27 }
28
29 if ( 'form' === $key && \is_string( $value ) ) {
30 $sanitized[ $key ] = \current_user_can( 'unfiltered_html' ) ? $value : \wp_kses_post( $value );
31 continue;
32 }
33
34 $sanitized[ $key ] = $this->sanitize_value( $value );
35 }
36
37 return $sanitized;
38 }
39
40 private function sanitize_value( mixed $value ): mixed {
41 if ( \is_array( $value ) ) {
42 $sanitized = array();
43
44 foreach ( $value as $key => $nested ) {
45 if ( \is_int( $key ) || \is_string( $key ) ) {
46 $sanitized[ $key ] = $this->sanitize_value( $nested );
47 }
48 }
49
50 return $sanitized;
51 }
52
53 if ( null === $value ) {
54 return '';
55 }
56
57 if ( \is_scalar( $value ) ) {
58 return \sanitize_text_field( (string) $value );
59 }
60
61 return '';
62 }
63 }
64