add_category( 'convertkit', array( 'title' => __( 'Kit', 'convertkit' ), 'icon' => 'fa fa-plug', ) ); } /** * Registers Blocks as Elementor Widgets. * * @since 1.9.7.2 * * @param Elementor\Widgets_Manager $widgets_manager Widgets Manager, used to register/unregister Elementor Widgets. */ public function register_widgets( $widgets_manager ) { // Get blocks. $blocks = convertkit_get_blocks(); // Bail if no blocks are available. if ( ! count( $blocks ) ) { return; } // Load widget class here, as we know that Elementor is active. require_once CONVERTKIT_PLUGIN_PATH . '/includes/integrations/elementor/class-convertkit-elementor-widget.php'; // Iterate through blocks, registering them. foreach ( $blocks as $block => $properties ) { // Skip if this block doesn't have an Elementor Widget class. if ( ! file_exists( CONVERTKIT_PLUGIN_PATH . '/includes/integrations/elementor/class-convertkit-elementor-widget-' . $block . '.php' ) ) { continue; } // Load widget class for this block. require_once CONVERTKIT_PLUGIN_PATH . '/includes/integrations/elementor/class-convertkit-elementor-widget-' . $block . '.php'; $class_name = 'ConvertKit_Elementor_Widget_' . str_replace( '-', '_', $block ); // Register Widget, using applicable function depending on the Elementor version. if ( method_exists( $widgets_manager, 'register' ) ) { // @phpstan-ignore-line - older versions of Elementor don't have this method. // Use register() function, available in Elementor 3.5.0. // Required per https://developers.elementor.com/docs/managers/registering-widgets/. $widgets_manager->register( new $class_name() ); } else { // Fallback to register_widget_type(), available in Elementor < 3.5.0. $widgets_manager->register_widget_type( new $class_name() ); } } } }