| | |
| | | */ |
| | | class MetaTypeManager |
| | | { |
| | | protected array $type_map = [ |
| | | protected static array $type_map = [ |
| | | 'text' => [ |
| | | 'type' => 'string', |
| | | 'sanitize' => 'sanitize_text_field', |
| | |
| | | 'sanitize' => 'sanitize_email', |
| | | 'default' => '', |
| | | ], |
| | | 'phone' => [ |
| | | 'type' => 'string', |
| | | 'sanitize' => 'sanitizeTelephone', |
| | | 'default' => '', |
| | | ], |
| | | 'url' => [ |
| | | 'type' => 'string', |
| | | 'sanitize' => 'esc_url_raw', |
| | |
| | | 'sanitize' => 'sanitizeRepeater', |
| | | 'default' => [], |
| | | ], |
| | | 'tag_list' => [ |
| | | 'type' => 'object', |
| | | 'sanitize' => 'sanitizeTagList', |
| | | 'default' => [] |
| | | ], |
| | | 'group' => [ |
| | | 'type' => 'object', |
| | | 'sanitize' => 'sanitizeGroup', |
| | |
| | | 'default' => '', |
| | | ] |
| | | ]; |
| | | public function getType(string $field_name):array |
| | | public static function getType(string $field_name):array |
| | | { |
| | | return $this->type_map[$field_name]??[]; |
| | | return static::$type_map[$field_name]??[]; |
| | | } |
| | | |
| | | public function getMetaType(string $field_type):string |
| | | public static function getMetaType(string $field_type):string |
| | | { |
| | | return $this->type_map[$field_type]['type'] ?? 'string'; |
| | | return static::$type_map[$field_type]['type'] ?? 'string'; |
| | | } |
| | | |
| | | public function getSanitizeCallback(string $field_type):string |
| | | public static function getSanitizeCallback(string $field_type):string |
| | | { |
| | | return $this->type_map[$field_type]['sanitize'] ?? 'sanitize_text_field'; |
| | | return static::$type_map[$field_type]['sanitize'] ?? 'sanitize_text_field'; |
| | | } |
| | | |
| | | public function registerType(string $type, array $config):void |
| | | public static function registerType(string $type, array $config):void |
| | | { |
| | | $this->type_map[$type] = $config; |
| | | static::$type_map[$type] = $config; |
| | | } |
| | | public static function getTypes():array |
| | | { |
| | | return static::$type_map; |
| | | } |
| | | } |