Support » Developing with WordPress » Setting setting parameters in Setting less Control in Customizer

  • I wanted to use setting less control as described here: https://make.wordpress.org/core/2016/03/10/customizer-improvements-in-4-5/

    But I cannot send default value for setting less control.

    I have tried following:

    $wp_customize->add_control(  'slug_title', array(
        'sanitize_callback' => 'sanitize_text_field',
        'settings'          => array( 'default' => 'Title' ),
        'label'             => esc_html__( 'Title', 'verity-pro' ),
        'section'           => 'some-section',
        'type'              => 'text',
    ) );

    and

    $wp_customize->add_control(  'slug_title', array(
        'sanitize_callback' => 'sanitize_text_field',
        'settings'          => array(),
        'default'           => 'Title',
        'label'             => esc_html__( 'Title', 'verity-pro' ),
        'section'           => 'some-section',
        'type'              => 'text',
    ) );

    Also, how to send set type, option and transport parameters that is used in add_settings? Is it not suppose to work this way?

    If this is a bug, I can create a new ticket in core trac.

Viewing 2 replies - 1 through 2 (of 2 total)
  • I’m not aware that what you are describing is possible and it doesn’t seem like a bug to me. That is, you say you want to have setting-less controls, but you want those controls to have a setting. That doesn’t make sense as an English sentence and I think it doesn’t make sense via the syntax of code either.

    The trac post that you link to says that you can create a control without an associated setting or with an empty setting that has the same id as the control, but it doesn’t say anything about the possibility for a default setting. In this case, it seems to make sense to me that you need an explicit settings declaration with a default value.

    But I could be wrong…

    Moderator bcworkz

    (@bcworkz)

    Paul made a good effort to explain. I will try as well using a different approach. We are both saying the same thing. Hopefully you will gain an understanding through one or the other if not both.

    If a setting has a default value, or any value, it is not setting-less, it is a normal setting. If you want to set a value but not allow it to be changed, do not add a control, just use the value internally. For example, define a constant and use that in your code. Should you need to change the value in the future, it can be changed in this one definition.

    You have two possibilities in the customizer for controls. One with a setting and value. One setting-less with no associated values. There are no other possibilities. You set the type in a setting-less control as you normally would. The option and transport values are illogical in setting-less controls because there is no value to save, nothing to update.

    If you want to display a value in a setting-less control for information only, one that is not possible to change, make it part of the label. Do not try to establish a value in setting-less controls.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Setting setting parameters in Setting less Control in Customizer’ is closed to new replies.