> */ public static function type_map(): array { /** * Register block recipe implementations. * * @param array> $map type => class. */ $map = apply_filters( 'forwp_drive_block_recipe_types', array( 'core-image' => Core_Image_Recipe::class, 'faq-accordion' => Faq_Accordion_Recipe::class, 'section-wrap' => Section_Wrap_Recipe::class, ) ); return is_array( $map ) ? $map : array(); } /** * @param array $config Recipe config. */ public static function create( array $config ): ?Block_Recipe_Interface { $type = sanitize_key( (string) ( $config['type'] ?? $config['id'] ?? '' ) ); if ( '' === $type ) { return null; } $map = self::type_map(); if ( ! isset( $map[ $type ] ) || ! is_string( $map[ $type ] ) ) { return null; } $class = $map[ $type ]; if ( ! class_exists( $class ) ) { return null; } $recipe = new $class(); if ( ! $recipe instanceof Block_Recipe_Interface ) { return null; } return $recipe; } }