SanitizeProfileData.php
85 lines
| 1 | <?php |
| 2 | |
| 3 | namespace Give\DonorDashboards\Helpers; |
| 4 | |
| 5 | /** |
| 6 | * Normalize format of location type lists. |
| 7 | * @since 2.10.0 |
| 8 | */ |
| 9 | class SanitizeProfileData { |
| 10 | |
| 11 | /** |
| 12 | * Sanitize int passed, and return 0 if somehting other than an integer was passed |
| 13 | * |
| 14 | * @param string $avatarId |
| 15 | * |
| 16 | * @return int |
| 17 | * |
| 18 | * @since 2.10.0 |
| 19 | */ |
| 20 | public static function sanitizeInt( $avatarId ) { |
| 21 | if ( ! empty( $avatarId ) ) { |
| 22 | return intval( $avatarId ); |
| 23 | } else { |
| 24 | return 0; |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | /** |
| 29 | * Sanitize array of addresses passed |
| 30 | * |
| 31 | * @param array $addresses |
| 32 | * |
| 33 | * @return array |
| 34 | * |
| 35 | * @since 2.10.0 |
| 36 | */ |
| 37 | public static function sanitizeAdditionalAddresses( $addresses ) { |
| 38 | if ( ! empty( $addresses ) ) { |
| 39 | return array_map( [ __CLASS__, 'sanitizeAddress' ], $addresses ); |
| 40 | } else { |
| 41 | return []; |
| 42 | } |
| 43 | } |
| 44 | |
| 45 | /** |
| 46 | * Sanitize address object passed |
| 47 | * |
| 48 | * @param object $address |
| 49 | * |
| 50 | * @return object |
| 51 | * |
| 52 | * @since 2.10.0 |
| 53 | */ |
| 54 | public static function sanitizeAddress( $address ) { |
| 55 | if ( ! empty( $address ) ) { |
| 56 | foreach ( $address as $key => $value ) { |
| 57 | $address->{$key} = sanitize_text_field( $value ); |
| 58 | } |
| 59 | return $address; |
| 60 | } else { |
| 61 | return []; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | /** |
| 66 | * Sanitize array of emails passed |
| 67 | * |
| 68 | * @param array $emails |
| 69 | * |
| 70 | * @return array |
| 71 | * |
| 72 | * @since 2.10.0 |
| 73 | */ |
| 74 | public static function sanitizeAdditionalEmails( $emails ) { |
| 75 | if ( ! empty( $emails ) ) { |
| 76 | foreach ( $emails as $key => $value ) { |
| 77 | $emails[ $key ] = sanitize_email( $value ); |
| 78 | } |
| 79 | return $emails; |
| 80 | } else { |
| 81 | return []; |
| 82 | } |
| 83 | } |
| 84 | } |
| 85 |