'; } 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_ldbuttons_control() { // Get our options and see if we're handling a form submission. $options = get_option('widget_ldbuttons'); if ( !is_array($options) ) $options = array('title'=>'Lib Dem campaigns', 'buttonnumber'=>'0'); if ( $_POST['ldbuttons-submit'] ) { // Remember to sanitize and format use input appropriately. $options['title'] = strip_tags(stripslashes($_POST['ldbuttons-title'])); $options['buttonnumber'] = strip_tags(stripslashes($_POST['ldbuttons-buttonnumber'])); update_option('widget_ldbuttons', $options); } // Be sure you format your options to be valid HTML attributes. $title = htmlspecialchars($options['title'], ENT_QUOTES); $buttonnumber = htmlspecialchars($options['buttonnumber'], 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('Lib Dem buttons', 'widget_ldbuttons'); // 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('Lib Dem buttons', 'widget_ldbuttons_control', 300, 200); } // Run our code later in case this loads prior to any required plugins. add_action('plugins_loaded', 'widget_ldbuttons_init'); ?>