Widget no almacena los datos
-
Hola tengo el siguiente widget, que he creado viendo otros ejemplos.
El problema es que no me almacena los datos introducidos y por tanto no me los muestra.class Custom_Widget_Text extends WP_Widget {
function Custom_Widget_Text() {
$widget_ops = array(‘classname’ => ‘widget_text’, ‘description’ => __(‘Arbitrary text or HTML’, ‘base’));
$control_ops = array(‘width’ => 400, ‘height’ => 350);
$this->WP_Widget(‘text’, __(‘Text’, ‘base’), $widget_ops, $control_ops);
}function widget( $args, $instance ) {
extract($args);
$widgetId = $args[‘widget_id’];?>
<script type=”text/javascript”>
arrayidelement.push(<?php echo ‘”‘. $widgetId.'”‘; ?>);
</script><?php
$title = apply_filters( ‘widget_title’, empty($instance[‘title’]) ? ” : $instance[‘title’], $instance, $this->id_base);
$intro = apply_filters( ‘widget_text’, $instance[‘intro’], $instance );
echo $before_widget;
if ( !empty( $title ) ) {
echo $before_title . $title . $after_title;
} ?>
<div id = <?php echo $widgetId?>>
<?php echo $intro ?>
</div><?php
echo $after_widget;
}function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance[‘title’] = strip_tags($new_instance[‘title’]);
$instance[‘intro’] = strip_tags($new_instance[‘intro’]);return $instance;
}function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( ‘title’ => ”, ‘intro’ => ” ) );
$title = strip_tags($instance[‘title’]);
$intro = esc_textarea($instance[‘intro’]);
?>
<p><label for=”<?php echo $this->get_field_id(‘title’); ?>”><?php _e(‘Title:’, ‘base’); ?></label>
<input class=”widefat” id=”<?php echo $this->get_field_id(‘title’); ?>” name=”<?php echo $this->get_field_name(‘title’); ?>” type=”text” value=”<?php echo esc_attr($title); ?>” /></p><p><label for=”<?php echo $this->get_field_id(‘intro’); ?>”><?php _e(‘Introducción:’, ‘base’); ?></label>
<textarea class=”widefat” rows=”16″ cols=”20″ id=”<?php echo $this->get_field_id(‘intro’); ?>” name=”<?php echo $this->get_field_name(‘intro’); ?>”><?php echo $intro; ?></textarea><?php
}
}add_action(‘widgets_init’, create_function(”, ‘return register_widget(“Custom_Widget_Text”);’));
Supongo que el problema estara en la funcion update o form, pero por mas que comparo con otros ejemplos no consigo ver el problema.
The topic ‘Widget no almacena los datos’ is closed to new replies.