monsterinsights_sanitize_select_field

Sanitize select fields.

Description

monsterinsights_sanitize_select_field( $value, $id, $setting, $previous_value ); 

Parameters (4)

0. $value
The value.
1. $id
The id.
2. $setting
The setting.
3. $previous_value
The previous value.

Usage

  1. if ( !function_exists( 'monsterinsights_sanitize_select_field' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'google-analytics-for-wordpress-by-monsterinsights/includes/admin/settings/settings-api.php'; 
  3.  
  4. // The value. 
  5. $value = null; 
  6.  
  7. // The id. 
  8. $id = null; 
  9.  
  10. // The setting. 
  11. $setting = null; 
  12.  
  13. // The previous value. 
  14. $previous_value = null; 
  15.  
  16. // NOTICE! Understand what this does before running. 
  17. $result = monsterinsights_sanitize_select_field($value, $id, $setting, $previous_value); 
  18.  

Defined (1)

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

/includes/admin/settings/settings-api.php  
  1. function monsterinsights_sanitize_select_field( $value, $id, $setting, $previous_value ) { 
  2. if ( ! empty( $setting['multiple'] ) && $setting['multiple'] ) { 
  3. $save_value = array(); 
  4. } else { 
  5. $save_value = ''; 
  6. if ( ! empty( $value ) && is_array( $value ) ) { 
  7. if ( $setting['multiple'] ) { 
  8. foreach ( $value as $vid => $vname ) { 
  9. foreach( $setting['options'] as $key => $option ) { 
  10. if ( $key === $vname ) { 
  11. $save_value[] = $key; 
  12. break; 
  13. } else { 
  14. foreach( $setting['options'] as $key => $option ) { 
  15. if ( is_array( $value ) && in_array( $key, $value ) ) { 
  16. $save_value = $key; 
  17. break; 
  18. } else if ( is_string( $value ) && $key === $value ) { 
  19. $save_value = $key; 
  20. break; 
  21. return $save_value;