Ver Mensaje Individual
  #7 (permalink)  
Antiguo 26/10/2012, 08:01
Avatar de rogertm
rogertm
Mod->Cuba
 
Fecha de Ingreso: julio-2005
Ubicación: /home/Cuba/Habana/rogertm/
Mensajes: 2.922
Antigüedad: 18 años, 9 meses
Puntos: 638
Respuesta: Problemas de validación y/o inserción en la BD. Setting API

Bueno, desde que publiqué este post hasta hoy han habido algunos cambios, ya me valida bien todo excepto un select, pero creo tener ubicado el problema así que será cuestión de dedicarle un rato...

Finalmente decidí validar según el tipo de input que sea, para así pasarlos todos por un foreach y esta es mi función de validación:
Código PHP:
Ver original
  1. function t_em_theme_options_validate( $input ){
  2.     global $excerpt_options, $slider_layout;
  3.  
  4.     // All the checkbox are either 0 or 1
  5.     foreach ( array(
  6.         'header-featured-image',
  7.     ) as $checkbox ) :
  8.         if ( !isset( $input[$checkbox] ) )
  9.             $input[$checkbox] = null;
  10.         $input[$checkbox] = ( $input[$checkbox] == 1 ? 1 : 0 );
  11.     endforeach;
  12.  
  13.     // Validate all radio options
  14.     $radio_options = array(
  15.         'header-options'    => array (
  16.             'set'        => 'header-set',
  17.             'callback'    => t_em_header_options(),
  18.         ),
  19.         'slider-options'    => array (
  20.             'set'        => 'slider-thumbnail',
  21.             'callback'    => $slider_layout,
  22.         ),
  23.         'archive-options'    => array (
  24.             'set'        => 'archive-set',
  25.             'callback'    => t_em_archive_options(),
  26.         ),
  27.         'excerpt-options'    => array (
  28.             'set'        => 'excerpt-set',
  29.             'callback'    => $excerpt_options,
  30.         ),
  31.         'layout-options'    => array (
  32.             'set'        => 'layout-set',
  33.             'callback'    => t_em_layout_options(),
  34.         ),
  35.     );
  36.     foreach ( $radio_options as $radio ) :
  37.         if ( ! isset( $input[$radio['set']] ) )
  38.             $input[$radio['set']] = null;
  39.         if ( ! array_key_exists( $input[$radio['set']], $radio['callback'] ) )
  40.             $input[$radio['set']] = null;
  41.     endforeach;
  42.  
  43.     // Validate all int (input[type="number"]) options
  44.     foreach( array (
  45.         'slider-thumbnail-width',
  46.         'slider-thumbnail-height',
  47.         'slider-number',
  48.         'excerpt-thumbnail-width',
  49.         'excerpt-thumbnail-height',
  50.         'layout-width',
  51.     ) as $int ) :
  52.         $input[$int] = wp_filter_nohtml_kses( $input[$int] );
  53.     endforeach;
  54.  
  55.     // Validate all url (input[type="url"]) options
  56.     foreach ( array (
  57.         'twitter-set',
  58.         'facebook-set',
  59.         'googlepluss-set',
  60.         'rss-set',
  61.     ) as $url ) :
  62.         $input[$url] = esc_url_raw( $input[$url] );
  63.     endforeach;
  64.  
  65.     // Validate all select list options
  66.     $select_options = array ( // No pincha
  67.         'slider-cat'        => array (
  68.             'set'        => 'slider-category',
  69.             'callback'    => t_em_slider_callback(),
  70.         ),
  71.     );
  72.     foreach ( $select_options as $select ) :
  73.         if ( ! array_key_exists( $input[$select['set']], $select['callback'] ) )
  74.             $input[$select['set']] = null;
  75.     endforeach;
  76.  
  77.     return $input;
  78. }
  79. ?>

Ahora, $excerpt_options y $slider_layout son un par de variables que me retornan el array del slider-set y el excerpt-set, que a su vez pertenecen a las funciones que llamo como callback en t_em_archive_options() y t_em_header_options(), por ejemplo:
Código PHP:
Ver original
  1. function t_em_header_options(){
  2.     $header_options = array (
  3.         'no-header-image' => array (
  4.             'value' => 'no-header-image',
  5.             'label' => __( 'No header image', 't_em' ),
  6.             'extend' => '',
  7.         ),
  8.         'header-image' => array (
  9.             'value' => 'header-image',
  10.             'label' => __( 'Header image', 't_em' ),
  11.             'extend' => t_em_header_image_callback(),
  12.         ),
  13.         'slider' => array (
  14.             'value' => 'slider',
  15.             'label' => __( 'Slider', 't_em' ),
  16.             'extend' => t_em_slider_callback(),
  17.         ),
  18.     );
  19.  
  20.     return apply_filters( 't_em_header_options', $header_options );
  21. }
Y aquí la función callback:
Código PHP:
Ver original
  1. function t_em_slider_callback(){
  2.     global $slider_layout;
  3.     $slider_layout = array (
  4.         'slider-thumbnail-left' => array (
  5.             'value' => 'slider-thumbnail-left',
  6.             'label' => __( 'Slider thumbnail on left', 't_em' ),
  7.             'thumbnail' => T_EM_FUNCTIONS_DIR_IMG . '/slider-thumbnail-left.png',
  8.         ),
  9.         'slider-thumbnail-right' => array (
  10.             'value' => 'slider-thumbnail-right',
  11.             'label' => __( 'Slider thumbnail on right', 't_em' ),
  12.             'thumbnail' => T_EM_FUNCTIONS_DIR_IMG . '/slider-thumbnail-right.png',
  13.         ),
  14.         'slider-thumbnail-full' => array (
  15.             'value' => 'slider-thumbnail-full',
  16.             'label' => __( 'Slider thumbnail on full', 't_em' ),
  17.             'thumbnail' => T_EM_FUNCTIONS_DIR_IMG . '/slider-thumbnail-full.png',
  18.         ),
  19.     );
  20. // aquí más código
  21. }
Entonces, lo que me falta, como dije antes, es validar un select, de donde escojo una categoría determinada para mostrar en el slider del theme, pero creo tener claro qué debo hacer, es que me devuelva el valor mediante un array (como los anteriores), esto es lo que tengo:
Código PHP:
Ver original
  1. function t_em_slider_callback(){
  2. // Aquí hay más código
  3.     // Display a select list of categories
  4.     $list_categories = get_categories();
  5.     $extend_slider .= '<div class="sub-extend">';
  6.     $extend_slider .=    '<label class="description">';
  7.     $extend_slider .=         '<p>'. __( 'Select the category you want to be displayed in the slider section', 't_em' ) .'</p>';
  8.     $extend_slider .=         '<select name="t_em_theme_options[slider-category]">';
  9.     foreach ( $list_categories as $slider_category ) :
  10.         $selected_option = ( $options['slider-category'] == $slider_category->cat_ID ) ? 'selected="selected"' : '';
  11.         $extend_slider .=     '<option value="'.$slider_category->cat_ID.'" '.$selected_option.'>'.$slider_category->name.'</option>';
  12.     endforeach;
  13.     $extend_slider .=         '</select>';
  14.     $extend_slider .=    '</label>';
  15.     $extend_slider .= '</div>';
  16. }

En fin, va funcionando, en cuanto lo termine publico la solución completa...

Gracias.
__________________
Friki y Blogger por Cuenta Propia:213
Twenty'em: Theming is Prose