catchresponsive_sanitize_select

Select sanitization callback example.

Description

(string) catchresponsive_sanitize_select( (string) $input, (WP_Customize_Setting) $setting ); 

- Sanitization: select - Control: select, radio

Sanitization callback for select and radio type controls. This callback sanitizes $input as a slug, and then validates $input against the choices defined for the control.

Returns (string)

Sanitized slug if it is a valid choice; otherwise, the setting default.

Parameters (2)

0. $input (string)
Slug to sanitize.
1. $setting (WP_Customize_Setting)
Setting instance.

Usage

  1. if ( !function_exists( 'catchresponsive_sanitize_select' ) ) { 
  2. require_once '/inc/customizer-includes/catchresponsive-customizer-sanitize-functions.php'; 
  3.  
  4. // Slug to sanitize. 
  5. $input = ''; 
  6.  
  7. // Setting instance. 
  8. $setting = null; 
  9.  
  10. // NOTICE! Understand what this does before running. 
  11. $result = catchresponsive_sanitize_select($input, $setting); 
  12.  

Defined (1)

The function is defined in the following location(s).

/inc/customizer-includes/catchresponsive-customizer-sanitize-functions.php  
  1. function catchresponsive_sanitize_select( $input, $setting ) { 
  2. // Get list of choices from the control associated with the setting. 
  3. $choices = $setting->manager->get_control( $setting->id )->choices; 
  4.  
  5. // If the input is a valid key, return it; otherwise, return the default. 
  6. return ( array_key_exists( $input, $choices ) ? $input : $setting->default );