"", ); } // This is the function that outputs the pmetrics code. function widget_pmetrics($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. Default tags: li and h2. extract($args); // Each widget can store and retrieve its own options. // Here we retrieve any options that may have been set by the user // relying on widget defaults to fill the gaps. $options = array_merge(widget_pmetrics_options(), get_option('widget_pmetrics')); unset($options[0]); //returned by get_option(), but we don't need it // These lines generate our output. Widgets can be very complex // but as you can see here, they can also be very, very simple. // echo $before_widget . $before_title . $options['Title'] . $after_title; ?> $value) if(array_key_exists('pmetrics-'.$key, $_POST)) $options[$key] = strip_tags(stripslashes($_POST['pmetrics-'.$key])); // Save changes update_option('widget_pmetrics', $options); } // Here is our little form segment. Notice that we don't need a // complete form. This will be embedded into the existing form. // Be sure you format your options to be valid HTML attributes // before displayihng them on the page. ?>

See statistics sample here

$value): ?>

'; } // 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('pmetrics counter', 'widget_pmetrics'); // 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('pmetrics counter', 'widget_pmetrics_control', 220, 50 * count(widget_pmetrics_options())); } // Run our code later in case this loads prior to any required plugins. add_action('plugins_loaded', 'widget_pmetrics_init'); ?>