*/ private static array $blocks = array(); /** * Register a block type. * * @since 1.0.0 * * @param string $type The block type slug (e.g., 'posts'). * @param string $class_name The fully qualified class name extending Wlconduit_Block_Base. * @return void */ public static function register( string $type, string $class_name ): void { if ( ! is_subclass_of( $class_name, Wlconduit_Block_Base::class ) ) { return; } self::$blocks[ $type ] = new $class_name(); } /** * Get a block instance by type. * * @since 1.0.0 * * @param string $type The block type slug. * @return Wlconduit_Block_Base|null The block instance or null if not registered. */ public static function get( string $type ): ?Wlconduit_Block_Base { return self::$blocks[ $type ] ?? null; } /** * Get all registered block instances. * * @since 1.0.0 * * @return array */ public static function get_all(): array { return self::$blocks; } /** * Get definitions for all registered blocks (for admin UI). * * Returns the available fields and filters each block offers, * so the React drag-and-drop builder knows what options to display. * * @since 1.0.0 * * @return array */ public static function get_all_definitions(): array { $definitions = array(); foreach ( self::$blocks as $type => $block ) { $definitions[ $type ] = $block->get_definition(); } return $definitions; } /** * Register all default blocks and fire the extensibility hook. * * @since 1.0.0 * * @return void */ public static function register_defaults(): void { self::register( 'posts', Wlconduit_Posts_Block::class ); self::register( 'users', Wlconduit_Users_Block::class ); self::register( 'site_info', Wlconduit_Site_Info_Block::class ); self::register( 'comments', Wlconduit_Comments_Block::class ); /** * Fires after default blocks are registered. * * Third-party plugins can use this to register custom block types. * * @since 1.0.0 */ do_action( 'wlconduit_register_blocks' ); } }