<?php
class last_post_search extends WP_Widget {

public function __construct(){
$widget_ops = array(
'classname' => 'last_post_search',
'description' => 'نمایش فرم جستجو در سایدبار',
);
parent::__construct( 'last_post_search', 'Pastor - فرم جستجو', $widget_ops );
}

function widget( $args, $instance ) {
$widget_title = apply_filters( 'widget_title', $instance['widget_title'] );
echo $args['before_widget'];
if( !empty($widget_title) ) {
echo $args['before_title'];
echo $widget_title;
echo $args['after_title'];
}
?>
<form id="searchform" class="searchform" role="search" method="get" action="<?php echo home_url(); ?>">
<input id="s" name="s" type="text">
<input id="searchsubmit" value="جستجو" type="submit">
</form>
<?php
echo $args['after_widget'];
}

function update( $new_instance, $old_instance ) {
$instance = array();
$instance['widget_title'] = ( ! empty( $new_instance['widget_title'] ) ) ? strip_tags( $new_instance['widget_title'] ) : '';
return $instance;
}

function form( $instance ) {
if ( isset( $instance[ 'widget_title' ] ) ) {
$widget_title = $instance[ 'widget_title' ];
} else {
$widget_title = 'فرم جستجو';
}
?>
<p>
<label for="<?php echo $this->get_field_id( 'widget_title' ); ?>">عنوان :</label>
<input name="<?php echo $this->get_field_name( 'widget_title' ); ?>" type="text" value="<?php echo esc_attr( $widget_title ); ?>" id="<?php echo $this->get_field_id( 'widget_title' ); ?>" class="widefat">
</p>
<?php
}
}

function qaleb_last_post_search_widget() {
register_widget( 'last_post_search' );
}

add_action( 'widgets_init', 'qaleb_last_post_search_widget' );
?>