AfterRule.php
3 weeks ago
ArrayRule.php
3 weeks ago
BaseRule.php
3 weeks ago
BooleanRule.php
3 weeks ago
DateFormatRule.php
3 weeks ago
DateRule.php
3 weeks ago
DateTimeRule.php
3 weeks ago
EmailRule.php
3 weeks ago
EmailUniqueRule.php
3 weeks ago
ExistsRule.php
3 weeks ago
FloatRule.php
3 weeks ago
GreaterThanEqualRule.php
3 weeks ago
GreaterThanRule.php
3 weeks ago
InRule.php
3 weeks ago
IntegerRule.php
3 weeks ago
IsValidImageIdRule.php
3 weeks ago
LessThanEqualRule.php
3 weeks ago
LessThanRule.php
3 weeks ago
MaxRule.php
3 weeks ago
MinRule.php
3 weeks ago
NotInRule.php
3 weeks ago
NullableRule.php
3 weeks ago
NumberRule.php
3 weeks ago
ObjectRule.php
3 weeks ago
ProhibitedIfRule.php
3 weeks ago
ProhibitedRule.php
3 weeks ago
RegexRule.php
3 weeks ago
RequiredIfExists.php
3 weeks ago
RequiredIfRule.php
3 weeks ago
RequiredIfSiblingRule.php
3 weeks ago
RequiredRule.php
3 weeks ago
SameAsRule.php
3 weeks ago
Sanitizer.php
3 weeks ago
StringRule.php
3 weeks ago
UniqueRule.php
3 weeks ago
UrlRule.php
3 weeks ago
UserExists.php
3 weeks ago
Sanitizer.php
79 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Rule to ensure the minium value. |
| 5 | * |
| 6 | * @package Framework |
| 7 | * @subpackage Validation\Rules |
| 8 | * @since 1.0.0 |
| 9 | */ |
| 10 | namespace Kirki\Framework\Validation\Rules; |
| 11 | |
| 12 | \defined('ABSPATH') || exit; |
| 13 | use function Kirki\Framework\message; |
| 14 | class Sanitizer extends BaseRule |
| 15 | { |
| 16 | /** |
| 17 | * Check if the value is valid. |
| 18 | * |
| 19 | * @return bool |
| 20 | * |
| 21 | * @since 1.0.0 |
| 22 | */ |
| 23 | public function validate_rule() |
| 24 | { |
| 25 | $this->sanitize_data(); |
| 26 | return \true; |
| 27 | } |
| 28 | /** |
| 29 | * Get the error message if the value is less than the min value. |
| 30 | * |
| 31 | * @return string |
| 32 | * |
| 33 | * @since 1.0.0 |
| 34 | */ |
| 35 | public function get_error_message() |
| 36 | { |
| 37 | return message('validator.sanitize', $this->last_key_segment()); |
| 38 | } |
| 39 | /** |
| 40 | * Sanitize the data. |
| 41 | * |
| 42 | * @return void |
| 43 | * |
| 44 | * @since 1.0.0 |
| 45 | */ |
| 46 | public function sanitize_data() |
| 47 | { |
| 48 | switch ($this->rule_value) { |
| 49 | case 'trim': |
| 50 | $this->value = \trim($this->value); |
| 51 | break; |
| 52 | case 'text': |
| 53 | $this->value = sanitize_text_field($this->value); |
| 54 | break; |
| 55 | case 'textarea': |
| 56 | $this->value = sanitize_textarea_field($this->value); |
| 57 | break; |
| 58 | case 'email': |
| 59 | $this->value = sanitize_email($this->value); |
| 60 | break; |
| 61 | case 'url': |
| 62 | $this->value = sanitize_url($this->value); |
| 63 | break; |
| 64 | case 'key': |
| 65 | $this->value = sanitize_key($this->value); |
| 66 | break; |
| 67 | case 'title': |
| 68 | $this->value = sanitize_title($this->value); |
| 69 | break; |
| 70 | case 'file-name': |
| 71 | $this->value = sanitize_file_name($this->value); |
| 72 | break; |
| 73 | case 'mime-type': |
| 74 | $this->value = sanitize_mime_type($this->value); |
| 75 | break; |
| 76 | } |
| 77 | } |
| 78 | } |
| 79 |