'; echo ''; 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_librarything_control() { // Get our options and see if we're handling a form submission. $options = get_option('widget_librarything'); if ( !is_array($options) ) $options = array('title'=>'Some of my Books', 'lt_user'=>'', 'number_of_books'=>5, 'url_params'=>''); if ( $_POST['librarything-submit'] ) { // Remember to sanitize and format use input appropriately. $options['title'] = strip_tags(stripslashes($_POST['librarything-title'])); $options['lt_user'] = strip_tags(stripslashes($_POST['librarything-lt_user'])); $options['number_of_books'] = strip_tags(stripslashes($_POST['librarything-number_of_books'])); $options['url_params'] = strip_tags(stripslashes($_POST['librarything-url_params'])); update_option('widget_librarything', $options); } // Be sure you format your options to be valid HTML attributes. $title = htmlspecialchars($options['title'], ENT_QUOTES); $lt_user = htmlspecialchars($options['lt_user'], ENT_QUOTES); $number_of_books = htmlspecialchars($options['number_of_books'], ENT_QUOTES); $url_params = htmlspecialchars($options['url_params'], 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 '

'; echo '

ADVANCED: URL parameters:

'; 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('LibraryThing Books', 'widget_librarything'); // 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('LibraryThing Books', 'widget_librarything_control', 600, 140); } // Run our code later in case this loads prior to any required plugins. add_action('plugins_loaded', 'widget_librarything_init'); ?>