Forum Replies Created

Viewing 4 replies - 1 through 4 (of 4 total)
  • Thread Starter papascott

    (@papascott)

    @otto42 Thanks, the fix works for me.

    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");'));
    Thread Starter papascott

    (@papascott)

    Ignore my previous comment… previous instances _do_ disappear even with no other plugins activated with the default theme when a new instance is saved.

    However, since the plugin is a basically a one-line change to the default text widget, it shouldn’t be too hard to create a version to work with 2.8.

    Thread Starter papascott

    (@papascott)

    I’ve started testing with a copy of my setup… with all other plugins deactivated, multiple instances of the PHP Code Widget work as expected, both with the default theme and Thesis 1.5.1.

    When I reactivate all plugins, the problem recurs. So this seems to be a plugin conflict rather than a problem with PHP Code Widget itself.

Viewing 4 replies - 1 through 4 (of 4 total)