$raw */ public static function fromArray(array $raw): ?self { $id = isset($raw['id']) ? sanitize_key((string) $raw['id']) : ''; $title = isset($raw['title']) ? sanitize_text_field((string) $raw['title']) : ''; if ('' === $id || '' === $title) { return null; } $content = isset($raw['content']) ? wp_kses_post((string) $raw['content']) : ''; $enabled = ! empty($raw['enabled']); $source = isset($raw['source']) ? sanitize_key((string) $raw['source']) : self::SOURCE_GLOBAL; if (self::SOURCE_PRODUCT !== $source) { $source = self::SOURCE_GLOBAL; } return new self($id, $title, $content, $enabled, $source); } /** * @return array */ public function toArray(): array { return [ 'id' => $this->id, 'title' => $this->title, 'content' => $this->content, 'enabled' => $this->enabled, 'source' => $this->source, ]; } }