| 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 |
/** |
| 13 |
* Sanitize int passed, and return 0 if something other than an integer was passed |
| 14 |
* |
| 15 |
* @since 2.10.0 |
| 16 |
* |
| 17 |
* @param string $avatarId |
| 18 |
* |
| 19 |
* @return int |
| 20 |
* |
| 21 |
*/ |
| 22 |
public static function sanitizeInt($avatarId) |
| 23 |
{ |
| 24 |
if ( ! empty($avatarId)) { |
| 25 |
return intval($avatarId); |
| 26 |
} else { |
| 27 |
return 0; |
| 28 |
} |
| 29 |
} |
| 30 |
|
| 31 |
/** |
| 32 |
* Sanitize array of addresses passed |
| 33 |
* |
| 34 |
* @since 2.10.0 |
| 35 |
* |
| 36 |
* @param array $addresses |
| 37 |
* |
| 38 |
* @return array |
| 39 |
* |
| 40 |
*/ |
| 41 |
public static function sanitizeAdditionalAddresses($addresses) |
| 42 |
{ |
| 43 |
if ( ! empty($addresses)) { |
| 44 |
return array_map([__CLASS__, 'sanitizeAddress'], $addresses); |
| 45 |
} else { |
| 46 |
return []; |
| 47 |
} |
| 48 |
} |
| 49 |
|
| 50 |
/** |
| 51 |
* Sanitize address object passed |
| 52 |
* |
| 53 |
* @since 2.10.0 |
| 54 |
* |
| 55 |
* @param object $address |
| 56 |
* |
| 57 |
* @return object |
| 58 |
* |
| 59 |
*/ |
| 60 |
public static function sanitizeAddress($address) |
| 61 |
{ |
| 62 |
if ( ! empty($address)) { |
| 63 |
foreach ($address as $key => $value) { |
| 64 |
$address->{$key} = sanitize_text_field($value); |
| 65 |
} |
| 66 |
|
| 67 |
return $address; |
| 68 |
} else { |
| 69 |
return []; |
| 70 |
} |
| 71 |
} |
| 72 |
|
| 73 |
/** |
| 74 |
* Sanitize array of emails passed |
| 75 |
* |
| 76 |
* @since 2.10.0 |
| 77 |
* |
| 78 |
* @param array $emails |
| 79 |
* |
| 80 |
* @return array |
| 81 |
* |
| 82 |
*/ |
| 83 |
public static function sanitizeAdditionalEmails($emails) |
| 84 |
{ |
| 85 |
if ( ! empty($emails)) { |
| 86 |
foreach ($emails as $key => $value) { |
| 87 |
$emails[$key] = sanitize_email($value); |
| 88 |
} |
| 89 |
|
| 90 |
return $emails; |
| 91 |
} else { |
| 92 |
return []; |
| 93 |
} |
| 94 |
} |
| 95 |
} |
| 96 |
|