My testing with the PHP Code Widget revealed that even with the default theme and no other plugins installed, multiple instances could be not saved.
The PHP Code Widget is basically a one-line edit of the standard Text Widget, which in 2.8 was adapated to the new Widget API. So I applied the edit to the new Text Widget, and came up with something that works for me. If you know how to write plugins and want to try it, here it is… I offer no guarantees that it will work for you!
class PS_PHP_Widget extends WP_Widget {
function PS_PHP_Widget() {
$widget_ops = array('classname' => 'ps_php_widget', 'description' => __('Arbitrary PHP code, text or HTML'));
$control_ops = array('width' => 400, 'height' => 350);
$this->WP_Widget('ps_php_text', __('PS PHP Text'), $widget_ops, $control_ops);
}
function widget( $args, $instance ) {
extract($args);
$title = apply_filters('widget_title', empty($instance['title']) ? '' : $instance['title']);
$text = apply_filters( 'widget_text', $instance['text'] );
echo $before_widget;
if ( !empty( $title ) ) { echo $before_title . $title . $after_title; } ?>
<div class="psphpwidget"><?php echo eval('?>'.$text); ?></div>
<?php
echo $after_widget;
}
function update( $new_instance, $old_instance ) {
$instance = $old_instance;
$instance['title'] = strip_tags($new_instance['title']);
if ( current_user_can('unfiltered_html') )
$instance['text'] = $new_instance['text'];
else
$instance['text'] = wp_filter_post_kses( $new_instance['text'] );
return $instance;
}
function form( $instance ) {
$instance = wp_parse_args( (array) $instance, array( 'title' => '', 'text' => '' ) );
$title = strip_tags($instance['title']);
$text = format_to_edit($instance['text']);
?>
<p><label for="<?php echo $this->get_field_id('title'); ?>"><?php _e('Title:'); ?></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>
<textarea class="widefat" rows="16" cols="20" id="<?php echo $this->get_field_id('text'); ?>" name="<?php echo $this->get_field_name('text'); ?>"><?php echo $text; ?></textarea>
<?php
}
}
add_action('widgets_init', create_function('', 'return register_widget("PS_PHP_Widget");'));