0

What is the best way to get a default customizeAction label for the Customizer sections added via JavaScript?

Here is a code with a custom action label:

customSection = new api.Section( 'my_section', {
  priority: 1,
  panel: 'my_panel',
  title: 'Testing Section',
  customizeAction: 'Custom Action'
} );

The default value of customizeAction is an empty string.

Is it possible to display a default text -- "Customizing" ?

2
  • I'm not sure I understand. Do you mean that customizeAction does not currently have a default value of "Customizing" and so you have to explicitly provide it for each instance? Commented Nov 17, 2017 at 23:44
  • Correct. The problem is that if customizeAction is not defined in a custom section then it causes a styling issue in the Customizer: snag.gy/UJZjNd.jpg
    – user85513
    Commented Nov 18, 2017 at 0:54

1 Answer 1

0

You're right. There's currently no default value for the customizeAction param.

You can add your own default value for all controls with something like this in PHP:

add_action( 'customize_controls_enqueue_scripts', function() {
    wp_add_inline_script(
        'customize-controls',
        sprintf(
            'wp.customize.Section.prototype.defaults.customizeAction = %s;',
            wp_json_encode( __( 'Customizing', 'default' ) )
        )
    );
} );

This isn't in core yet because the default value is actually variable based on whether there is a panel defined. This is something we should figure out and improve in core. See #42635.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.