namespace = $namespace; $this->idAttribute = "data-stellarwp-$namespace-notice-id='{$notice->getId()}'"; $this->customLocationAttribute = "data-stellarwp-$namespace-location='{$notice->getLocation()}'"; $this->customWrapperAttributes = "$this->idAttribute $this->customLocationAttribute"; $this->customCloserAttribute = "data-stellarwp-$namespace-close-notice='{$notice->getId()}'"; } /** * @since 2.0.0 * * @param 'hide'|'mark-dismissed' $behavior */ public function customCloseBehaviorAttribute(string $behavior = self::CLOSE_BEHAVIOR_HIDE): string { if (!$this->behaviorIsValid($behavior)) { throw new InvalidArgumentException('Invalid behavior for custom closer attribute.'); } return "data-stellarwp-{$this->namespace}-close-notice-behavior='$behavior'"; } /** * @since 2.0.0 * * @param 'hide'|'mark-dismissed' $behavior */ public function closeAttributes(string $behavior = self::CLOSE_BEHAVIOR_HIDE): string { if (!$this->behaviorIsValid($behavior)) { throw new InvalidArgumentException('Invalid behavior for custom closer attribute.'); } return "$this->customCloserAttribute {$this->customCloseBehaviorAttribute($behavior)}"; } /** * @since 2.0.0 */ private function behaviorIsValid(string $behavior): bool { return in_array($behavior, [self::CLOSE_BEHAVIOR_HIDE, self::CLOSE_BEHAVIOR_MARK_DISMISSED], true); } }