Add a setting, specifying the sanitize_callback
:
$wp_customize->add_setting(
'my_input',
array(
'default' => '100.00',
'sanitize_callback' => 'sanitize_float',
)
);
Add the control:
$wp_customize->add_control(
'my_input',
array(
'label' => 'Please enter a number:',
'section' => 'my_section',
'type' => 'number',
'input_attrs' => array(
'min' => '0.01', 'step' => '0.01', 'max' => '10000',
),
)
);
Create a function to perform the sanitisation – filter_var
should return the sanitised float or false
:
function sanitize_float( $input ) {
return filter_var($input, FILTER_SANITIZE_NUMBER_FLOAT, FILTER_FLAG_ALLOW_FRACTION);
}
This is untested, but should get you started – it could, of course, be adapted to sanitize an integer.
[Adapted from http://themefoundation.com/wordpress-theme-customizer/]
Related Posts:
- What is the difference between sanitize_text_field() and wp_filter_nohtml_kses()?
- Can i use the same sanitize function on multiple theme mod textboxes?
- How to use sanitize_callback?
- Trouble creating custom sanitization function for user list dropdown
- how to sanitize customizer checkbox control
- I need to get the control choices to sanitize_callback
- How do I implement selective refresh with a customizer setting?
- How to create a theme customizer ‘sub’ panel?
- Use default value of wp_customizer in theme_mod output?
- How to upload multiple images with WP_Customize_Media_Control
- Is there any way to add placeholder for WordPress Customizer text input fields
- Custom editable content for front page from Theme Customizer
- Can I create customizer setting that can handle plugin shortcode?
- Add/remove controls dynamically based on other settings in Customizer
- Add custom background to div in home page
- How to mix partial and full page refresh in the same section of the customizer?
- Add a “loading” notice when Customizer is making changes
- How do I conditionally enqueue stylesheets or scripts in theme customizer settings?
- Internalize get_theme_mod CSS Into Stylesheet?
- Customiser `active_callback` not working on control with `postMessage` transport method
- How to get control choices from $setting object passed to sanitize_callback
- How to output WP_Customize_Cropped_Image_Control setting?
- How to hook on customizer section expanded/active/opened event?
- How do I use add_control to offer a list of all pages in the customiser?
- Visible Edit Shortcut for WordPress menu that uses nav walker
- Get_theme_mod not retrieving value
- Make Customizer Load Specific Page
- Panel description in Customizer does not show up
- How to extend Customizer payload sent when ‘Save & Publish’ is triggered
- Change “Display Site Title and Tagline” checkbox text in theme customizer
- Customizer, change preview url when a control changes
- Customizer Add Section argument ‘active_callback’ => “is_front_page” not working
- Is there any function that would allow me to register custom stylesheets for the Customizer itself?
- Customizer live preview not working, refreshes but nothing change
- making customizer sections sortable but items not getting sorted first time items are moved
- How to set a default color for the WordPress Customizer’s color picker?
- How do I add a customizer control dynamically?
- Need help for suitable sanitize_callback for scroll_logo in customizer
- How to immediately apply values in customizer js api
- Is it possible to get the label of a theme customizer option?
- How to filter customize_loaded_components from a theme?
- Background Color not being set in WP Customizer
- Why is action customize_register being done twice?
- How to disable cropping of the site icon?
- How do I update the wpColorPicker palette after initialization?
- Customizer’s “Imported Fonts” – How To Use Them?
- Your theme has 1 widget areas, but this particular page doesn’t display them in wordpress
- Insert content between sections in WP customizer
- Add items dynamically via Customizer [duplicate]
- Customizer: Category Select Sanitize
- Binding Serialized Setting to JS for Realtime Response
- Unset color set in Theme Customizer
- Setting dirty on customizer
- How to localize something coming from theme customizer
- Customiser sections not being displayed with `active_callback`
- How to allow certain PHP functions when using sanitize_callback in the word press customizer
- How to add Theme Customizer Color?
- Customizer related question
- Customize control does not show value of setting which was added via JS API
- Add Links to Customizer
- Customizer Values Not Saving in Custom Theme
- customiser settings for checkbox (displaying content)
- Customizer.js changes not being recognized
- where to change text for header?
- Theme Customizer for only author.php (per user baisi)
- Customizer API – Class doesn’t exist error
- WP_Filesystem in custom customize control
- Get register wp_customize settings in the front end
- Theme Customizer performance drops when adding a lot of settings
- How to Add Extra Settings to Appearance/Customizer Sections homepage
- Sanitize callback function for select controll in customizer
- Creating a WordPress Customizer control/field with react
- How to get a custom field in theme customizer to live update the element in preview window?
- What is the method to switch to specific page on entering theme customizer screen?
- How to Display Error in my WordPress customizer API?
- Unable to Auto Post In Buddy Press Activity from Elementor-Pro Form
- Theme Customization with WP CLI
- Linking to a Customizer control
- Using different header images for different devices
- Can you make sub-panels in customizer?
- Adding Custom Image To Header Via New Customizer Setting
- Is it possible to ad custom block areas through Customizer that would allow adding Gutenberg blocks?
- “Display Site Title and Tagline” checkbox without adding Header Image option
- WordPress Theme Customization error
- Why Settings API Options Override Customizer Settings?
- How can I stop widgets from re-executing every time I access the logged-in homepage?
- Customizer partial refresh issue with custom option
- Theme customizer API get functions
- How to properly delete and rename the custom settings/section/control in theme customizer?
- Theme Customizer: issue with default checkbox values
- how to make additional color options added to default color Customizer save their value
- Template tags not working in the customizer preview
- HTML inside Customizer
- Stop refresh event in customizer
- Problem with customizer setting with $id containing ‘widget’
- default custom background image not saved in database when creating a new site
- I am looking for a font used in WordPress [closed]
- What is the section ID (name) for “Menus” in the Customizer?
- How to add CSS to head by php through echo self::css();
- How to override javascript in customize-controls.js