epm_settings_sanitize

Settings Sanitization.

Description

epm_settings_sanitize( (array) $input = array() ); 

Parameters (1)

0. $input — Optional. (array) => array()
The input.

Usage

  1. if ( !function_exists( 'epm_settings_sanitize' ) ) { 
  2. require_once ABSPATH . PLUGINDIR . 'easy-peasy-mailchimp-ajax-form/includes/admin/settings/register-settings.php'; 
  3.  
  4. // The input. 
  5. $input = array(); 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = epm_settings_sanitize($input); 
  9.  

Defined (1)

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

/includes/admin/settings/register-settings.php  
  1. function epm_settings_sanitize( $input = array() ) { 
  2.  
  3. global $epm_options; 
  4.  
  5. if ( empty( $_POST['_wp_http_referer'] ) ) { 
  6. return $input; 
  7.  
  8. parse_str( $_POST['_wp_http_referer'], $referrer ); 
  9.  
  10. $settings = epm_get_registered_settings(); 
  11. $tab = isset( $referrer['tab'] ) ? $referrer['tab'] : 'general'; 
  12.  
  13. $input = $input ? $input : array(); 
  14. $input = apply_filters( 'epm_settings_' . $tab . '_sanitize', $input ); 
  15.  
  16. // Loop through each setting being saved and pass it through a sanitization filter 
  17. foreach ( $input as $key => $value ) { 
  18.  
  19. // Get the setting type (checkbox, select, etc) 
  20. $type = isset( $settings[$tab][$key]['type'] ) ? $settings[$tab][$key]['type'] : false; 
  21.  
  22. if ( $type ) { 
  23. // Field type specific filter 
  24. $input[$key] = apply_filters( 'epm_settings_sanitize_' . $type, $value, $key ); 
  25.  
  26. // General filter 
  27. $input[$key] = apply_filters( 'epm_settings_sanitize', $value, $key ); 
  28.  
  29. // Loop through the whitelist and unset any that are empty for the tab being saved 
  30. if ( ! empty( $settings[$tab] ) ) { 
  31. foreach ( $settings[$tab] as $key => $value ) { 
  32.  
  33. // settings used to have numeric keys, now they have keys that match the option ID. This ensures both methods work 
  34. if ( is_numeric( $key ) ) { 
  35. $key = $value['id']; 
  36.  
  37. if ( empty( $input[$key] ) ) { 
  38. unset( $epm_options[$key] ); 
  39.  
  40.  
  41. // Merge our new settings with the existing 
  42. $output = array_merge( $epm_options, $input ); 
  43.  
  44. add_settings_error( 'epm-notices', '', __( 'Settings updated.', 'epm' ), 'updated' ); 
  45.  
  46. return $output;