Make WordPress Core

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#54003 closed feature request (invalid)

How to Display Error in my WordPress customizer api?

Reported by: khawaga's profile khawaga Owned by:
Milestone: Priority: normal
Severity: normal Version:
Component: Customize Keywords:
Focuses: Cc:

Description (last modified by SergeyBiryukov)

I have been trying to add error to my wordpress customizer api like this error message I am trying to add custom message when the user enter invalid phone number her is my custom code

$wp_customize->add_setting('basic-banner-callout-phonenumber', array(
        'default' => '',
        'sanitize_callback' => array( $this, 'sanitize_custom_phonenumber' ),
        'validate_callback' => 'valide_custom_phonenumber'
    
    ));
    $wp_customize->add_control(new WP_Customize_Control($wp_customize, 'basic-banner-callout-control-text', array(
        'label' => 'PhoneNumber',
        'section' => 'basic-banner-callout-section',
        'settings' => 'basic-banner-callout-phonenumber',
        'type' => 'text',
        'input_attrs' => array(
            'maxlength' => 10
        )` 

how could i possible display if empty $input 'You must supply a valid phone number. for example ?

Change History (3)

#1 @dlh
4 years ago

  • Component changed from General to Customize
  • Milestone Awaiting Review deleted
  • Resolution set to invalid
  • Status changed from new to closed

Hi @khawaga, and welcome to WordPress Trac!

To add custom messages for validation errors, be sure that the validate_callback adds error messages to the WP_Error object passed to it. For more details, see the dev note written when the validation API was added to core.

Please also note that support for custom development isn't available here in Trac. If you have more questions about your project, you'll be able to find help in the support forums.

#2 @SergeyBiryukov
4 years ago

  • Description modified (diff)

#3 @khawaga
4 years ago

how could i send errors to Wp_Error?

Note: See TracTickets for help on using tickets.