add_category('thinkrank', [ 'title' => __('ThinkRank', 'thinkrank'), 'icon' => 'eicon-search', ]); } /** * Register the widgets. * * @param object $widgets_manager Elementor widgets manager. * @return void */ public function register_widgets($widgets_manager): void { $widgets_manager->register(new Elementor\FAQ_Widget()); $widgets_manager->register(new Elementor\Howto_Widget()); $widgets_manager->register(new Elementor\TOC_Widget()); } /** * Register (not enqueue) the shared block stylesheets so widgets can * declare them via get_style_depends() — Elementor then loads them only * on pages that actually use the widget. * * @return void */ public function register_widget_styles(): void { foreach (['faq-block', 'howto-block', 'toc-block'] as $handle) { $css = THINKRANK_PLUGIN_DIR . "assets/{$handle}.css"; if (!file_exists($css)) { continue; } $asset_path = THINKRANK_PLUGIN_DIR . "assets/{$handle}.asset.php"; $asset = file_exists($asset_path) ? include $asset_path : []; wp_register_style( "thinkrank-{$handle}", THINKRANK_PLUGIN_URL . "assets/{$handle}.css", [], $asset['version'] ?? THINKRANK_VERSION ); } } /** * In the Elementor editor preview all styles must load up front (the * preview doesn't know which widgets will be dropped in). * * @return void */ public function enqueue_preview_styles(): void { $this->register_widget_styles(); foreach (['faq-block', 'howto-block', 'toc-block'] as $handle) { wp_enqueue_style("thinkrank-{$handle}"); } } }