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
ProhibitedIfRule.php
63 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Validates that a value is present and not null. |
| 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 ProhibitedIfRule extends BaseRule |
| 15 | { |
| 16 | /** |
| 17 | * Determine if the value is present. |
| 18 | * |
| 19 | * @return bool |
| 20 | * |
| 21 | * @since 1.0.0 |
| 22 | */ |
| 23 | public function validate_rule() |
| 24 | { |
| 25 | $field_and_value = \explode(',', $this->rule_value, 2); |
| 26 | $field = $field_and_value[0]; |
| 27 | $value = $field_and_value[1]; |
| 28 | if ($value === 'false' || $value === 'FALSE') { |
| 29 | $value = \false; |
| 30 | } elseif ($value === 'true' || $value === 'TRUE') { |
| 31 | $value = \true; |
| 32 | } elseif ($value === 'null' || $value === 'NULL') { |
| 33 | $value = null; |
| 34 | } |
| 35 | if (\array_key_exists($field, $this->data) && $this->data[$field] == $value) { |
| 36 | return \is_null($this->value) || $this->value === ''; |
| 37 | } |
| 38 | return \true; |
| 39 | } |
| 40 | /** |
| 41 | * Get the error message for the prohibited field. |
| 42 | * |
| 43 | * @return string |
| 44 | * |
| 45 | * @since 1.0.0 |
| 46 | */ |
| 47 | public function get_error_message() |
| 48 | { |
| 49 | return message('validator.prohibited_if', $this->last_key_segment()); |
| 50 | } |
| 51 | /** |
| 52 | * Ignore rule check. |
| 53 | * |
| 54 | * @return void |
| 55 | * |
| 56 | * @since 1.0.0 |
| 57 | */ |
| 58 | protected function ignore_rule_check() |
| 59 | { |
| 60 | return \false; |
| 61 | } |
| 62 | } |
| 63 |