query('bp3d-public', 'registered'); if (!$script) { return; } foreach (['jquery', 'elementor-frontend'] as $handle) { // An unregistered dependency would stop the bundle from printing // at all, so only add handles that actually exist. if (wp_script_is($handle, 'registered') && !in_array($handle, $script->deps, true)) { $script->deps[] = $handle; } } } /** * Enqueue the model viewer library for the given viewer type. * * Prefers the script module API and passes the source along, so the * library still resolves when `enqueue_block_assets` — the hook the block * integration registers the module on — never fired for this request. */ public static function enqueueViewerLibrary(string $viewer = 'modelViewer'): void { if ($viewer === 'O3DViewer') { wp_enqueue_script('bp3d-lib-o3dviewer'); return; } if (function_exists('wp_enqueue_script_module')) { wp_enqueue_script_module('bp3d-lib-model-viewer', BP3D_DIR . 'public/js/model-viewer.latest.min.js', [], BP3D_VERSION); return; } // Older WordPress: the classic handle is turned into a module tag by // EnqueueAssets::addModuleTypeAttribute(). wp_enqueue_script('bp3d-lib-model-viewer'); } /** * 2.0.0 changed the widget's width selectors; regenerate Elementor's cached CSS once. */ public function refreshElementorCss(): void { if (wp_doing_ajax() || get_option('bp3d_elementor_css_ver') === '2.0.0' || !class_exists('\\Elementor\\Plugin') || empty(\Elementor\Plugin::$instance->files_manager)) { return; } \Elementor\Plugin::$instance->files_manager->clear_cache(); update_option('bp3d_elementor_css_ver', '2.0.0'); } /** * Cube icon for the widgets in the Elementor panel (Elementor has no 3D eicon). */ public function enqueueEditorStyles(): void { $svg = ""; $mask = 'url("data:image/svg+xml,' . rawurlencode($svg) . '") center / contain no-repeat'; wp_register_style('bp3d-elementor-editor', false, [], BP3D_VERSION); wp_enqueue_style('bp3d-elementor-editor'); wp_add_inline_style('bp3d-elementor-editor', ".bp3d-eicon-cube{display:inline-block;width:1em;height:1em;background-color:currentColor;-webkit-mask:{$mask};mask:{$mask}}"); } /** * Register Elementor widgets. */ public function registerWidgets() { require_once __DIR__ . '/ModelViewer.php'; require_once __DIR__ . '/BP3DProductModel.php'; \Elementor\Plugin::instance()->widgets_manager->register(new ModelViewer()); \Elementor\Plugin::instance()->widgets_manager->register(new BP3DProductModel()); } /** * Enqueue editor scripts (libraries for the editor panel document). */ public function enqueueEditorScripts() { $this->registerFrontendScripts(); wp_enqueue_script('bp3d-lib-o3dviewer', BP3D_DIR . 'public/js/o3dv.min.js', [], BP3D_VERSION, true); self::enqueueViewerLibrary(); } /** * Enqueue scripts and styles inside the editor preview iframe. * * Widgets dropped in while editing are rendered over AJAX, where enqueues * are discarded — so the preview has to carry the bundle and both * libraries up front, whatever the document contained on load. */ public function enqueuePreviewScripts() { $this->registerFrontendScripts(); self::ensureElementorDependencies(); wp_enqueue_style('bp3d-frontend'); wp_enqueue_script('bp3d-public'); wp_enqueue_script('bp3d-lib-o3dviewer'); self::enqueueViewerLibrary(); } }