Defaults defined in set_controls not showing in Builder UI

When I set the defaults for any type of control, it doesn’t show in the builder UI. I’ve tried this with checkbox, select, text, and color elements (oddly, it works for number controls). The only way I’ve been able to have any text show up is by setting the placeholder value, which is misleading.

Example text control

$this->controls['text'] = array(
    'tab'           => 'content',
    'label'         => esc_html__( 'Some text', 'me' ),
    'type'          => 'text',
    'spellcheck'    => true,
    'inlineEditing' => true,
    'default'       => 'Here is your text...',

Example select

$this->controls['dateRange'] = array(
    'tab'           => 'content',
    'label'         => esc_html__( 'Date range', 'me' ),
    'type'          => 'select',
    'inline'        => true,
    'multiple'      => false,
    'clearable'     => true,
    'options'       => [
        '1'     => esc_html__( '1 Day', 'me' ),
        '7'     => esc_html__( '7 Days', 'me' ),
        '15'    => esc_html__( '15 Days', 'me' ),
    'default'       => '3',
    'placeholder'   => esc_html__( 'Select range', 'me' ),

Am I missing something or is this a bug?

Looks like the issue has to do with actively developing the element when it’s inserted into a template.

If a default is not set when the element is inserted into the template it doesn’t matter if you add a default later, it won’t show in the control.

Removing the element and inserting it again (after defaults are set in the controls) will show the default values correctly.

This applies even if an entirely new control is added.

Feels like it may still be a rendering bug, but I don’t have rerender set on any of the controls I’ve been testing this morning.

I don’t think this is necessarily a bug.

Imagine pushing an update to an element plugin that’s already deployed on many sites. The user would expect anything that was set as default when they placed the element to stay that way.

You could of course enforce a default value with a php argument that sets the value even if it’s empty or unset.


As @cmstew said, this should be the expected behavior :blush:

1 Like

That’s fair, especially looking at it from that angle.

1 Like