';
echo $after_widget;
}
// This is the function that outputs the form to let the users edit
// the widget's title. It's an optional feature that users cry for.
function widget_gsearch_control() {
// Get our options and see if we're handling a form submission.
$options = get_option('widget_gsearch');
if ( !is_array($options) )
$options = array('title'=>'', 'buttontext'=>__('Google Search', 'widgets'));
if ( $_POST['gsearch-submit'] ) {
// Remember to sanitize and format use input appropriately.
$options['title'] = strip_tags(stripslashes($_POST['gsearch-title']));
$options['buttontext'] = strip_tags(stripslashes($_POST['gsearch-buttontext']));
update_option('widget_gsearch', $options);
}
// Be sure you format your options to be valid HTML attributes.
$title = htmlspecialchars($options['title'], ENT_QUOTES);
$buttontext = htmlspecialchars($options['buttontext'], ENT_QUOTES);
// Here is our little form segment. Notice that we don't need a
// complete form. This will be embedded into the existing form.
echo '';
echo '';
echo '';
}
// This registers our widget so it appears with the other available
// widgets and can be dragged and dropped into any active sidebars.
register_sidebar_widget(array('Google Search', 'widgets'), 'widget_gsearch');
// This registers our optional widget control form. Because of this
// our widget will have a button that reveals a 300x100 pixel form.
register_widget_control(array('Google Search', 'widgets'), 'widget_gsearch_control', 300, 100);
}
// Run our code later in case this loads prior to any required plugins.
add_action('widgets_init', 'widget_gsearch_init');
?>