'adinjwidget', 'description' => 'Insert Ad Injection adverts into your sidebars/widget areas.' ); $control_ops = array( 'width' => 500, 'height' => 300, 'id_base' => 'adinj' ); $this->WP_Widget( 'adinj', 'Ad Injection', $widget_ops, $control_ops ); } function widget( $args, $instance ) { if (adinj_ads_completely_disabled_from_page()) return; if ((is_front_page() && adinj_ticked('widget_exclude_front')) || (is_home() && adinj_ticked('widget_exclude_home')) || (is_page() && adinj_ticked('widget_exclude_page')) || (is_single() && adinj_ticked('widget_exclude_single')) || (is_archive() && adinj_ticked('widget_exclude_archive')) || (is_search() && adinj_ticked('widget_exclude_search')) || (is_404() && adinj_ticked('widget_exclude_404'))){ return; } if (!adinj_allowed_in_category('widget', $instance)) return; if (!adinj_allowed_in_tag('widget', $instance)) return; if (!adinj_allowed_in_author('widget', $instance)) return; extract( $args ); $ops = adinj_options(); $include = ""; if ($ops['ad_insertion_mode'] == 'mfunc'){ $include = adinj_ad_code_include(); } $title = apply_filters('widget_title', $instance['title'] ); // The old 'non upgraded' db will be passed here if the widget hasn't // been resaved. We can't upgrade as doing so would mean we'd have to // re-save the widget files - which we can't do as we can't re-write // the settings back to the db (at least not without a bit more work) $adcode = adinj_get_ad_code('widget_'.$this->get_id(), $instance); echo $before_widget; if ( $title ) { echo $before_title . $title . $after_title; } if ( !empty($adcode) ){ echo $include; echo $adcode; } echo $after_widget; } function update( $new_instance, $old_instance ){ $updated = $this->adinj_upgrade_widget_db($new_instance, $old_instance); // Only strip tags when potential for updated title $updated['title'] = strip_tags( $new_instance['title'] ); // After first save mark it as saved $updated['saved'] = 1; for ($i=1; $i<=10; ++$i){ write_ad_to_file($updated['advert_'.$i], $this->get_ad_file_path($i)); } for ($i=1; $i<=3; ++$i){ write_ad_to_file($updated['advert_alt_'.$i], $this->get_alt_file_path($i)); } return $updated; } function default_options(){ /* Set up some default widget settings. */ return array( 'title' => '', //adverts 'advert_1' => '', 'advert_1_split' => '100', 'advert_2' => '', 'advert_2_split' => '100', 'advert_3' => '', 'advert_3_split' => '100', 'advert_4' => '', 'advert_4_split' => '100', 'advert_5' => '', 'advert_5_split' => '100', 'advert_6' => '', 'advert_6_split' => '100', 'advert_7' => '', 'advert_7_split' => '100', 'advert_8' => '', 'advert_8_split' => '100', 'advert_9' => '', 'advert_9_split' => '100', 'advert_10' => '', 'advert_10_split' => '100', 'advert_alt_1' => '', 'advert_alt_1_split' => '100', 'advert_alt_2' => '', 'advert_alt_2_split' => '100', 'advert_alt_3' => '', 'advert_alt_3_split' => '100', //settings 'margin_top' => 'd', 'margin_bottom' => 'd', 'padding_top' => 'd', 'padding_bottom' => 'd', 'widget_category_condition_mode' => 'o', 'widget_category_condition_entries' => '', 'widget_tag_condition_mode' => 'o', 'widget_tag_condition_entries' => '', 'widget_author_condition_mode' => 'o', 'widget_author_condition_entries' => '', //ui 'ui_ad_1_show' => 'true', 'ui_conditions_show' => 'false', 'ui_spacing_show' => 'false', 'ui_ad_pool_show' => 'false', 'ui_ad_2_show' => 'false', 'ui_ad_3_show' => 'false', 'ui_ad_4_show' => 'false', 'ui_ad_5_show' => 'false', 'ui_ad_6_show' => 'false', 'ui_ad_7_show' => 'false', 'ui_ad_8_show' => 'false', 'ui_ad_9_show' => 'false', 'ui_ad_10_show' => 'false', 'ui_alt_pool_show' => 'false', 'ui_alt_1_show' => 'false', 'ui_alt_2_show' => 'false', 'ui_alt_3_show' => 'false', 'saved' => 0, // 'db_version' => ADINJ_WIDGET_DB_VERSION ); } function adinj_upgrade_widget_db($new_instance, $old_instance){ // Copy old values across to default $updated = $this->default_options(); foreach ($updated as $key => $value){ if (array_key_exists($key, $new_instance)){ $updated[$key] = $new_instance[$key]; } } // Upgrade any options as necessary $old_dbversion = adinj_db_version($old_instance); if ($old_dbversion == 1){ $updated['advert_1'] = $old_instance['advert']; } $updated['db_version'] = ADINJ_WIDGET_DB_VERSION; return $updated; } function form( $instance ) { $instance = $this->adinj_upgrade_widget_db($instance, $instance); $savedfieldname = $this->get_field_name('saved'); $savedfieldvalue = $instance['saved']; ?> add_name('db_version'); ?> value='' />
Title:
Make sure any title complies with your ad provider's TOS. More info for AdSense users.
| get_field_name('margin_top'), $this->get_field_name('margin_bottom') ); ?> | get_field_name('padding_top'), $this->get_field_name('padding_bottom') ); ?> |
Other options to define who sees these adverts (by page age, IP, referrer) are on the main Ad Injection settings page. You can also set which page types the widgets appear on.