Skip to content
JS Filters

lzb.editor.control.getValue

Turns what is stored for a control into what its editor component expects. This is the first of three filters a value passes through in the editor: getValue on the way in, lzb.editor.control.validate before the post can be saved, and lzb.editor.control.updateValue on the way back out.

The plugin has already picked the raw value by the time the filter runs. It comes from attributes[control.name], or from meta[control.save_in_meta_name || control.name] when the control has save_in_meta set to true, or from the parent's array at childIndex when the control lives inside a repeater.

Attributes

NameTypeDescription
valMixedthe stored value, before any coercion
controlObjectcontrol settings: type, name, default, label, child_of, save_in_meta and the rest
childIndexNumber | Booleanrow index inside a repeater, otherwise false or undefined

Additional Filters

NameDescription
lzb.editor.control.CONTROL_TYPE.getValuespecific controls only

The type-specific filter runs first and the generic one runs on its result.

Usage

JS
wp.hooks.addFilter(
  "lzb.editor.control.getValue",
  "my.custom.namespace",
  function (val, control) {
    if (control.type !== "my_json") {
      return val;
    }
 
    try {
      return JSON.parse(val || "{}");
    } catch (e) {
      return {};
    }
  },
);

After both filters, an undefined result is replaced with an empty string, so a handler cannot use undefined to mean "leave the stored value alone". Whatever shape you return here has to survive the trip back through lzb.editor.control.updateValue, which is where the value is turned back into something the block attribute or the post meta can hold.

Was this article helpful?

Copyright © 2026 Lazy Blocks.