optionsframework_validate

Validate Options.

Description

optionsframework_validate( $input ); 

This runs after the submit/reset button has been clicked and validates the inputs.

Parameters (1)

0. $input
The input.

Usage

  1. if ( !function_exists( 'optionsframework_validate' ) ) { 
  2. require_once '/inc/options-framework.php'; 
  3.  
  4. // The input. 
  5. $input = null; 
  6.  
  7. // NOTICE! Understand what this does before running. 
  8. $result = optionsframework_validate($input); 
  9.  

Defined (1)

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

/inc/options-framework.php  
  1. function optionsframework_validate( $input ) { 
  2.  
  3. /** 
  4. * Restore Defaults. 
  5. * In the event that the user clicked the "Restore Defaults" 
  6. * button, the options defined in the theme's options.php 
  7. * file will be added to the option for the active theme. 
  8. */ 
  9.  
  10. if ( isset( $_POST['reset'] ) ) { 
  11. add_settings_error( 'options-framework', 'restore_defaults', __( 'Default options restored.', 'options_framework_theme' ), 'updated fade' ); 
  12.  
  13. /** 
  14. * Update Settings 
  15. * This used to check for $_POST['update'], but has been updated 
  16. * to be compatible with the theme customizer introduced in WordPress 3.4 
  17. */ 
  18.  
  19. $clean = array(); 
  20. $options =& _optionsframework_options(); 
  21. foreach ( $options as $option ) { 
  22.  
  23. if ( ! isset( $option['id'] ) ) { 
  24. continue; 
  25.  
  26. if ( ! isset( $option['type'] ) ) { 
  27. continue; 
  28.  
  29. $id = preg_replace( '/[^a-zA-Z0-9._\-]/', '', strtolower( $option['id'] ) ); 
  30.  
  31. // Set checkbox to false if it wasn't sent in the $_POST 
  32. if ( 'checkbox' == $option['type'] && ! isset( $input[$id] ) ) { 
  33. $input[$id] = false; 
  34.  
  35. // Set each item in the multicheck to false if it wasn't sent in the $_POST 
  36. if ( 'multicheck' == $option['type'] && ! isset( $input[$id] ) ) { 
  37. foreach ( $option['options'] as $key => $value ) { 
  38. $input[$id][$key] = false; 
  39.  
  40. // For a value to be submitted to database it must pass through a sanitization filter 
  41. if ( has_filter( 'of_sanitize_' . $option['type'] ) ) { 
  42. $clean[$id] = apply_filters( 'of_sanitize_' . $option['type'], $input[$id], $option ); 
  43.  
  44. // Hook to run after validation 
  45. do_action( 'optionsframework_after_validate', $clean ); 
  46.  
  47. return $clean;