$name, 'height' => 80, 'width' => 300); if (function_exists('wp_register_sidebar_widget') ) { /* Loop through available ads and generate widget one at a time */ if(is_array($_adsensem['ads'])){ foreach($_adsensem['ads'] as $name => $ad){ $args = array('n' => $name, 'height' => 80, 'width' => 300); //$id, $name, $output_callback, $_adsensem = array() wp_register_sidebar_widget('adsensem-' . $name,'Ad #' . $name, array('adsensem','widget'), $args, $name); wp_register_widget_control('adsensem-' . $name,'Ad #' . $name, array('adsensem','widget_control'), $args, $name); } } } } // This is the function that outputs adsensem widget. function widget($args, $n=0) { // $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); global $_adsensem; // Each widget can store its own options. We keep strings here. $ad = $_adsensem['ads'][$n]; // 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; if($ad->title!=''){ echo $before_title . $ad->title . $after_title; } echo $ad->get_ad(); //Output the selected ad echo $after_widget; } /* Widget admin block for each Ad element on the page, allows movement of them around the sidebar */ function widget_control($name) { global $_adsensem; if ( $_POST['adsensem-' . $name . '-submit'] ) { global $_adsensem; // Remember to sanitize and format use input appropriately. $_adsensem['ads'][$name]->title = strip_tags(stripslashes($_POST['adsensem-' . $name . '-title'])); update_option('plugin_adsensem', $_adsensem); } ?> for named ad or for default */ function filter_ads($content) { global $_adsensem; if(is_object($_adsensem['ads'][$_adsensem['default-ad']])){ //Insert default ad first $content=str_replace(array("",""),$_adsensem['ads'][$_adsensem['default-ad']]->get_ad(),$content); foreach($_adsensem['ads'] as $name=>$ad) { $content = str_replace(array("",""), $ad->get_ad(), $content); } } return $content; } } /* SHOW ALTERNATE AD UNITS */ if ($_REQUEST['adsensem-show-ad']){ ?>