'my_element', ... ]; * return $elements; * } ); */ class ElementRegistry { /** @var array */ private static array $elements = []; /** * Register an element type. * * @param string $type Unique element type key. * @param array $schema Element schema (see CampaignElements.php for shape). */ public static function register( string $type, array $schema ): void { self::$elements[ $type ] = array_merge( $schema, [ 'type' => $type ] ); } /** * Get all registered element schemas, after applying the extension filter. * * @return array */ public static function get_all(): array { return apply_filters( 'better_payment/campaign_elements', self::$elements ); } /** * Get a single element schema by type. * * @param string $type * @return array|null */ public static function get( string $type ): ?array { $all = self::get_all(); return $all[ $type ] ?? null; } /** * Get default settings for an element type. * * @param string $type * @return array */ public static function get_defaults( string $type ): array { $schema = self::get( $type ); return $schema['defaultSettings'] ?? []; } }