'Schema_AI_Article_Schema', 'BlogPosting' => 'Schema_AI_Article_Schema', 'NewsArticle' => 'Schema_AI_Article_Schema', 'Product' => 'Schema_AI_Product_Schema', 'Recipe' => 'Schema_AI_Recipe_Schema', 'LocalBusiness' => 'Schema_AI_Local_Business_Schema', 'Service' => 'Schema_AI_Service_Schema', 'FAQPage' => 'Schema_AI_FAQ_Schema', 'HowTo' => 'Schema_AI_HowTo_Schema', 'Event' => 'Schema_AI_Event_Schema', 'Review' => 'Schema_AI_Review_Schema', 'Person' => 'Schema_AI_Person_Schema', 'Organization' => 'Schema_AI_Organization_Schema', // Non-local subtypes — all routed through Organization builder which // reads site type to output the correct @type dynamically. 'NewsMediaOrganization' => 'Schema_AI_Organization_Schema', 'EducationalOrganization'=> 'Schema_AI_Organization_Schema', 'GovernmentOrganization' => 'Schema_AI_Organization_Schema', 'BreadcrumbList' => 'Schema_AI_Breadcrumb_Schema', 'VideoObject' => 'Schema_AI_Video_Schema', 'ImageObject' => 'Schema_AI_Image_Schema', 'Course' => 'Schema_AI_Course_Schema', 'PodcastEpisode' => 'Schema_AI_Podcast_Episode_Schema', 'SoftwareApplication' => 'Schema_AI_Software_Application_Schema', 'CreativeWork' => 'Schema_AI_Creative_Work_Schema', 'WebPage' => 'Schema_AI_WebPage_Schema', // AboutPage/ContactPage reuse the WebPage builder (same fields, // just a more specific @type). Schema_AI_Schema_Generator overrides // the @type after build(), the same way it already does for // BlogPosting/NewsArticle aliasing onto the Article builder. 'AboutPage' => 'Schema_AI_WebPage_Schema', 'ContactPage' => 'Schema_AI_WebPage_Schema', 'WebSite' => 'Schema_AI_Website_Schema', // Not dispatched through get_builder() in practice — term archives are // generated via Schema_AI_Generate_Endpoint::generate_for_term(), which // instantiates Schema_AI_Collection_Page_Schema directly (its build() // takes term_id/taxonomy, not post_id/fields like every other builder // here). Registered anyway so is_supported()/get_supported_types() // report it consistently. 'CollectionPage' => 'Schema_AI_Collection_Page_Schema', ); /** * Map of builder class names to file paths (relative to types/ directory). * * @var array */ private static $file_map = array( 'Schema_AI_Article_Schema' => 'class-article-schema.php', 'Schema_AI_Product_Schema' => 'class-product-schema.php', 'Schema_AI_Recipe_Schema' => 'class-recipe-schema.php', 'Schema_AI_Local_Business_Schema' => 'class-local-business-schema.php', 'Schema_AI_Service_Schema' => 'class-service-schema.php', 'Schema_AI_FAQ_Schema' => 'class-faq-schema.php', 'Schema_AI_HowTo_Schema' => 'class-howto-schema.php', 'Schema_AI_Event_Schema' => 'class-event-schema.php', 'Schema_AI_Review_Schema' => 'class-review-schema.php', 'Schema_AI_Person_Schema' => 'class-person-schema.php', 'Schema_AI_Organization_Schema' => 'class-organization-schema.php', 'Schema_AI_Breadcrumb_Schema' => 'class-breadcrumb-schema.php', 'Schema_AI_Video_Schema' => 'class-video-schema.php', 'Schema_AI_Image_Schema' => 'class-image-schema.php', 'Schema_AI_Course_Schema' => 'class-course-schema.php', 'Schema_AI_Podcast_Episode_Schema' => 'class-podcast-episode-schema.php', 'Schema_AI_Software_Application_Schema' => 'class-software-application-schema.php', 'Schema_AI_Creative_Work_Schema' => 'class-creative-work-schema.php', 'Schema_AI_WebPage_Schema' => 'class-webpage-schema.php', 'Schema_AI_Website_Schema' => 'class-website-schema.php', 'Schema_AI_Collection_Page_Schema' => 'class-collection-page-schema.php', ); /** * Get a schema builder instance for the given schema type. * * @param string $schema_type The schema.org type name (e.g. 'Article', 'Product'). * @return Schema_AI_Base_Schema|null Builder instance or null for unknown types. */ public static function get_builder( $schema_type ) { if ( ! isset( self::$type_map[ $schema_type ] ) ) { /** * Filter to allow third-party plugins to register custom schema builders. * * @param Schema_AI_Base_Schema|null $builder The builder instance (null by default). * @param string $schema_type The requested schema type. */ return apply_filters( 'schema_ai_custom_builder', null, $schema_type ); } $class_name = self::$type_map[ $schema_type ]; // Auto-load the class file if not already loaded. if ( ! class_exists( $class_name ) ) { self::load_builder_class( $class_name ); } if ( ! class_exists( $class_name ) ) { return null; } $builder = new $class_name(); // For aliases (BlogPosting, NewsArticle), override the @type. if ( in_array( $schema_type, array( 'BlogPosting', 'NewsArticle' ), true ) ) { // The builder will set @type = Article, but we need the specific type. // We handle this via a wrapper that the generator can use. } return $builder; } /** * Get all supported schema type names. * * @return array List of supported schema type strings. */ public static function get_supported_types() { return array_keys( self::$type_map ); } /** * Check if a schema type is supported. * * @param string $schema_type The schema.org type name. * @return bool True if supported. */ public static function is_supported( $schema_type ) { if ( isset( self::$type_map[ $schema_type ] ) ) { return true; } /** * Filter to allow third-party plugins to declare support for custom types. * * @param bool $supported Whether the type is supported. * @param string $schema_type The schema type to check. */ return apply_filters( 'schema_ai_type_supported', false, $schema_type ); } /** * Load the base schema class and a specific builder class file. * * @param string $class_name The builder class name. */ private static function load_builder_class( $class_name ) { $types_dir = dirname( __FILE__ ) . '/types/'; // Always ensure the base class is loaded. if ( ! class_exists( 'Schema_AI_Base_Schema' ) ) { $base_file = $types_dir . 'class-base-schema.php'; if ( file_exists( $base_file ) ) { require_once $base_file; } } // Load the specific builder. if ( isset( self::$file_map[ $class_name ] ) ) { $file = $types_dir . self::$file_map[ $class_name ]; if ( file_exists( $file ) ) { require_once $file; } } } }