我一直在开发我的第一个小部件,除了没有保存我添加到textarea框中的任何内容外,其他一切都很正常。然而,它将在网站上输出输入。
根据研究,我认为这与表单功能和更新有关,但我不太清楚是哪一部分。
这是我的小部件代码。
<?php
/*
Plugin Name: Hexagran Featured Widget
Plugin URI: http://thevisionists.com
Description: Produces a widget for use in the widget panel.
Version: 0.1
Author: Danny & Tom
Author URI: http://thevisionists.com
License:none
*/
//$args pulls in the arguments from the sidebar.php
class hexagram_featured_widget extends WP_Widget {
function __construct() {
parent::__construct(\'false\', $name = __( \'Hexagram Featured Box\'), //tranlation enabled // accessing the perant constructer
array( \'description\' => __(\'Displays the content you place inside, strips all html\'))
); // end of the construct
}
function form($instance) {
$title = strip_tags( $instance[\'title\'] );
$info = esc_textarea( $instance[\'info\'] );
?>
<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>
<p><label for="<?php echo $this->get_field_id(\'info\'); ?>"><?php _e(\'Text Goes here:\'); ?></label>
<textarea class="widefat" rows="8" cols="10" id="<?php echo $this->get_field_id(\'info\'); ?>" name="<?php echo $this->get_field_name(\'info\'); ?>"></textarea>
<?php
}
function update( $new_instance, $old_instance) {
$instance = array();
$instance[ \'title\' ] = strip_tags($new_instance[ \'title\' ]);
$instance[ \'info\' ] = strip_tags($new_instance[ \'info\' ]);
return $instance;
}
function widget($args, $instance) {
extract($args);
$title = apply_filters(\'widget_title\', $instance[\'title\'] );
$info = $instance[ \'info\' ];
echo $before_widget;
if ( ! empty( $title ) ) echo $before_title . $title . $after_title;
if ($info) print $info;
echo $after_widget;
}
} // end of the class holding all the functions
add_action(\'widgets_init\', function() {
register_widget(\'hexagram_featured_widget\');
}
)
// adds an action to register the widget
// class name is always the name of the register widget argument.
?>