1. Home
  2. Docs
  3. 3D
  4. Backend
  5. JavaScript Hooks & Actions

JavaScript Hooks & Actions

JavaScript – Lifecycle Events

Before registering editor hooks, wait for the appropriate event.

EventDescription
wp3dconf/editor:before-mountFires before the Vue editor app is mounted. event.detail.editor exposes the editor instance. Use this to register custom Vue components.
wp3dconf/editor:readyFires when the editor is fully initialised. Register all editor actions and filters here.
// Register custom Vue components before the editor mounts
window.addEventListener('wp3dconf/editor:before-mount', function(event) {
  const editor = event.detail.editor;

  editor.component('MyComponent', MyComponent);
});

// Register hooks once the editor is ready
window.addEventListener('wp3dconf/editor:ready', function(event) {
  const { addAction, addFilter } = window.WP3dConf;

  addAction('wp3dconf/editor/layer-added', function({ layer }) {
    console.log('New layer added:', layer);
  }, 10);
});

JavaScript – Global API

const { addAction, addFilter, hasAction, removeAction } = window.WP3dConf;

addAction( hook, callback, priority )
ParameterTypeDefaultDescription
hookStringThe hook name
callbackFunctionThe function to call
priorityNumber10Lower numbers run first
addFilter( hook, callback, priority )

Same signature as addAction. The callback must return the first argument (the filtered value).

JavaScript Editor Actions

wp3dconf/editor/model-loaded

Fires after the 3D model has been loaded in the editor canvas.

ParameterTypeDescription
storeObjectThe editor Pinia store
store3DObjectThe Three.js/TresJS store

wp3dconf/editor/configurator-saved

Fires after the configurator has been successfully saved.

ParameterTypeDescription
storeObjectThe editor Pinia store
window.addEventListener('wp3dconf/editor:ready', function() {
  const { addAction } = window.WP3dConf;

  addAction('wp3dconf/editor/configurator-saved', function({ store }) {
    console.log('Saved. Layers:', store.layers);
  }, 10);
});

wp3dconf/editor/layer-inserted

Fires when a new layer is inserted into the layer tree (e.g. via drag-and-drop).

ParameterTypeDescription
storeObjectThe editor Pinia store
layerObjectThe inserted layer
parentObjectThe parent layer or group

wp3dconf/editor/layer-added

Fires when a new layer is added via the Add button.

ParameterTypeDescription
storeObjectThe editor Pinia store
layerObjectThe newly added layer
window.addEventListener('wp3dconf/editor:ready', function() {
  const { addAction } = window.WP3dConf;

  addAction('wp3dconf/editor/layer-added', function({ layer }) {
    console.log('New layer added:', layer);
  }, 10);
});

wp3dconf/editor/layer-deleted

Fires when a layer is deleted from the layer tree.

ParameterTypeDescription
storeObjectThe editor Pinia store
layerObjectThe deleted layer
parentObjectThe parent layer or group

wp3dconf/editor/layer-duplicated

Fires when a layer is duplicated.

ParameterTypeDescription
storeObjectThe editor Pinia store
layerObjectThe original layer
parentObjectThe parent layer or group
newLayerObjectThe newly created duplicate

wp3dconf/editor/layer-reordered

Fires after layers have been reordered in the layer tree.

ParameterTypeDescription
storeObjectThe editor Pinia store
addAction('wp3dconf/editor/layer-reordered', function({ store }) {
  console.log('Reordered layers:', store.layers);
}, 10);

JavaScript Editor Filters

wp3dconf/editor/configurator-data

Filters the FormData object before it is submitted to the server on save. Use this to append additional fields.

ParameterTypeDescription
formDataFormDataThe form data object being submitted
storeObjectThe editor Pinia store
addFilter('wp3dconf/editor/configurator-data', function(formData, { store }) {
  formData.append('my_custom_field', 'my_value');
  return formData;
}, 10);

wp3dconf/editor/layer-classes

Filters the CSS classes applied to a layer row in the editor layer panel.

ParameterTypeDescription
classesArrayArray of CSS class strings
storeObjectThe editor Pinia store
window.addEventListener('wp3dconf/editor:ready', function() {
  const { addFilter } = window.WP3dConf;

  addFilter('wp3dconf/editor/layer-classes', function(classes, { store }) {
    classes.push('custom-class');
    return classes;
  }, 10);
});

How can we help?