danixland

WP validation - options-register.php

May 2nd, 2013
261
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2. // Register theme_tdg_options array to hold all theme options
  3. register_setting( 'theme_tdg_options', 'theme_tdg_options', 'tdg_validate' );
  4.  
  5. function tdg_validate( $input ) {
  6.     // default options
  7.     $tdg_default_options = tdg_get_default_options(); # returns an array with the default options as stored initially on the database
  8.  
  9.     // Determine which form action was submitted
  10.     [...]
  11.     $submit_cart = ( ! empty($input['submit-cart'] ) ? true : false );
  12.     $reset_cart = ( ! empty($input['reset-cart'] ) ? true : false );
  13.  
  14.     if ( $submit_cart ) { // if cart Settings Submit
  15.         // Cart explanation text
  16.         $input['tdg_cart_explanation'] = ( '' == $input['tdg_cart_explanation'] ? $tdg_default_options['tdg_cart_explanation'] : wp_kses_data($input['tdg_cart_explanation']) );
  17.         // Cart page address
  18.         if( tdg_use_permalink() ) { # true if "pretty" permalinks are active, false otherwise
  19.         $input['tdg_cart_page'] = ( '' == $input['tdg_cart_page'] ? $tdg_default_options['tdg_cart_page'] : sanitize_title($input['tdg_cart_page']) );
  20.         } else {
  21.         $input['tdg_cart_page'] = ( '' == $input['tdg_cart_page'] ? $tdg_default_options['tdg_cart_page'] : intval($input['tdg_cart_page']) );
  22.         }
  23.  
  24.     } elseif ( $reset_cart ) { // if cart Settings Reset Defaults
  25.  
  26.         $tdg_default_options = tdg_get_default_options();
  27.         // Cart Explanation text
  28.         $input['tdg_cart_explanation'] = $tdg_default_options['tdg_cart_explanation'];
  29.         // Cart Page address
  30.         $input['tdg_cart_page'] = $tdg_default_options['tdg_cart_page'];
  31.  
  32.     }
  33.     return $input;
  34.  
  35. }
RAW Paste Data