<?php
class MyWidget_Search_Widget extends WP_Widget
{
/**
* General Setup
*/
public function __construct() {
/* Widget settings. */
$widget_ops = array(
'classname' => 'mywidget_search_widget',
'description' => __('Виджет, который выводит персональный поиск')
);
/* Create the widget. */
parent::__construct( 'mywidget_search_widget', 'mywidget | Персональный поиск', $widget_ops );
}
/**
* Display Widget
* @param array $args
* @param array $instance
*/
public function widget( $args, $instance )
{
extract( $args );
$custom_placeholder = $instance['custom_placeholder'];
// Display Widget
?>
<div class="widget widget_search">
<form role="search" method="get" id="searchform" action="<?php echo home_url("/"); ?>">
<input class="input-search" type="search" name="s" value="" placeholder="<?php echo $custom_placeholder; ?>">
<input type="hidden" name="post_type" value="post">
<input type="submit" class="submit-search" value="">
</form>
</div>
<?php
}
/**
* Update Widget
* @param array $new_instance
* @param array $old_instance
* @return array
*/
public function update( $new_instance, $old_instance )
{
$instance = $old_instance;
$instance['custom_placeholder'] = strip_tags( $new_instance['custom_placeholder'] );
return $instance;
}
/**
* Widget Settings
* @param array $instance
*/
public function form( $instance )
{
//default widget settings.
$defaults = array(
'custom_placeholder' => 'Поиск по Новостям',
);
$instance = wp_parse_args( (array) $instance, $defaults );
?>
<p>
<label for="<?php echo $this->get_field_id( 'custom_placeholder' ); ?>">Плейсхолдер</label>
<input type="text" class="widefat" id="<?php echo $this->get_field_id( 'custom_placeholder' ); ?>" name="<?php echo $this->get_field_name( 'custom_placeholder' ); ?>" value="<?php echo $instance['custom_placeholder']; ?>" />
</p>
<?php
}
}