'object', 'properties' => array( 'devices' => array( 'type' => 'array', 'items' => array( 'type' => 'string', 'enum' => self::DEVICES, ), ), ), ); } /** * Gets the default value for a newly created condition of this type. * * @return mixed */ public function default_value() { return array( 'devices' => self::DEVICES, ); } /** * Validates a value against this condition's schema. * * @param mixed $value Value to validate. * @return bool */ public function is_valid_value( $value ): bool { // Legacy single-device string, still honoured by RenderService. if ( is_string( $value ) ) { return in_array( $value, self::DEVICES, true ); } if ( ! is_array( $value ) || ! isset( $value['devices'] ) || ! is_array( $value['devices'] ) ) { return false; } foreach ( $value['devices'] as $device ) { if ( ! in_array( $device, self::DEVICES, true ) ) { return false; } } return true; } /** * Evaluates the condition against the given context. * * @param Context $context Request context value object. * @param string $operator Operator identifier. * @param mixed $value Configured value. * @return bool */ public function evaluate( Context $context, string $operator, $value ): bool { // Responsive hiding is performed client-side via CSS (see RenderService // + front.css). Server-side evaluation never hides on device, so this // condition always passes and only contributes its wrapper classes. return true; } }