. */ // Put all functions into one big function to be called at plugins_loaded. // It ensures that all required plugin functions are defined. function widget_suboptions_init() { // Check for the required plugin functions. This will prevent fatal // errors occurring when you deactivate the dynamic_sidebar plugin. if ( !function_exists('register_sidebar_widget') ) return; // This is the function that outputs the widget settings. function widget_suboptions($args) { // $args is an array of strings that help widgets to conform to the active theme: // before_widget, before_title, after_widget, and after_title are the array keys. extract($args); // Each widget can store its own options. I keep strings here. $options = get_option('widget_suboptions'); $rss_url = $options['rss_url']; $mail_url = $options['mail_url']; $twitter_url = $options['twitter_url']; $widget_title = $options['widget_title']; $rel = $options['rel']; // Not currently a user-defined option $pixels = $options['pixels']; // These lines generate the HTML output. echo $before_widget; echo '
'; echo $after_widget; } // This is the function that outputs the form to let the users edit the widget's title. function widget_suboptions_control() { // Gets the default options and checks to see if we're dealing with a form submission. $options = get_option('widget_suboptions'); if ( !is_array($options) ) { $options = array( 'rss_url' => 'Insert FeedBurner RSS feed URL here', 'mail_url' => 'Insert FeedBurner Email service URL here', 'twitter_url' => 'http://twitter.com/yourusername', 'widget_title' => 'Subscription Options:', 'rel' => 'alternate', 'pixels' => '30', ); } if ( $_POST['suboptions_submit'] ) { // Ensures that we format your input appropriately. $options['rss_url'] = strip_tags(stripslashes($_POST['suboptions_rss_url'])); $options['mail_url'] = strip_tags(stripslashes($_POST['suboptions_mail_url'])); $options['twitter_url'] = strip_tags(stripslashes($_POST['suboptions_twitter_url'])); $options['widget_title'] = strip_tags(stripslashes($_POST['suboptions_widget_title'])); $options['rel'] = strip_tags(stripslashes($_POST['suboptions_rel'])); $options['pixels'] = strip_tags(stripslashes($_POST['suboptions_pixels'])); update_option('widget_suboptions', $options); } // Ensures your options are valid HTML attributes. $rss_url = htmlspecialchars($options['rss_url'], ENT_QUOTES); $mail_url = htmlspecialchars($options['mail_url'], ENT_QUOTES); $twitter_url = htmlspecialchars($options['twitter_url'], ENT_QUOTES); $widget_title = htmlspecialchars($options['widget_title'], ENT_QUOTES); $rel = htmlspecialchars($options['rel'], ENT_QUOTES); $pixels = htmlspecialchars($options['pixels'], ENT_QUOTES); // Here is the widget form segment //Title echo ''; //Feed URL echo ''; //Mail URL echo ''; //Twitter URL echo ''; //Icon Size echo ''; //Submit Button echo ''; } // This registers the widget so that it appears with the other available // widgets and can be dragged and dropped into any active sidebars. register_sidebar_widget(array('Subscription Options', 'widgets'), 'widget_suboptions'); // This registers the optional widget control form. register_widget_control(array('Subscription Options', 'widgets'), 'widget_suboptions_control'); } // Runs the code later in case this loads prior to any required plugins. add_action('widgets_init', 'widget_suboptions_init'); ?>