'stf-adsense', 'description' => __( 'A widget to display ads.' ) ); parent::__construct( 'adsense-widget', __( 'Adsense', 'adsense-widget' ), $widget_ops ); $this->alt_option_name = 'stf_adsense'; $this->version = "1.7"; $this->settings_key = "stf_adsense"; $this->options_page = "adsense-widget"; // Default widget options $this->widget_defaults = array( 'title' => '', 'slot' => '', 'channel' => '', 'type' => 'banner', 'content' => 'text_image', 'adsense_id' => '' ); // Ad content types $this->content_types = array( 'text', 'image', 'text_image' ); // Include ad type array require_once("adsense-ad-types.php"); $this->ad_types = $ad_types; // Include options array require_once("adsense-widget-options.php"); $this->options = $options; $this->settings = $this->get_plugin_settings(); if( !is_admin() ){ wp_enqueue_style( 'adsense-widget', WP_PLUGIN_URL . "/adsense-widget/adsense-widget.css", false, "1.0", "all"); } add_action('admin_menu', array( &$this, 'stf_adsense_admin') ); } function get_plugin_settings(){ $settings = get_option( $this->settings_key ); if( FALSE === $settings ){ $settings = array(); foreach($this->options as $option){ if( array_key_exists( 'id', $option ) ) $settings[ $option['id'] ] = $option['std']; } $adsid = get_option( 'shailan_adsense_id' ); if( !empty( $adsid ) ){ $settings['adsense_id'] = $adsid; } $settings[ 'version' ] = $this->version; update_option( $this->settings_key, $settings ); } else { if( !empty( $settings['version'] ) ){ $ver = $settings['version']; } else { $ver = ''; } if( $ver != $this->version ){ $adsid = get_option( 'shailan_adsense_id' ); if( !empty( $adsid ) ){ $settings['adsense_id'] = $adsid; } foreach($this->options as $option){ if( array_key_exists ( 'id' , $option ) && !array_key_exists ( $option['id'] ,$settings ) ){ $settings[ $option['id'] ] = $option['std']; } } update_option( $this->settings_key, $settings ); return $settings; } else { $adsid = get_option( 'shailan_adsense_id' ); if( !empty( $adsid ) ){ $settings['adsense_id'] = $adsid; update_option( $this->settings_key, $settings ); delete_option( 'shailan_adsense_id' ); } return $settings; } } } function update_plugin_setting( $key, $value ){ $settings = $this->get_plugin_settings(); $settings[$key] = $value; update_option( $this->settings_key, $settings ); } function get_plugin_setting( $key, $default = '' ) { $settings = $this->get_plugin_settings(); if( array_key_exists($key, $settings) ){ return $settings[$key]; } else { return $default; } return FALSE; } function stf_adsense_admin(){ if ( @$_GET['page'] == $this->options_page ) { if ( @$_REQUEST['action'] && 'save' == $_REQUEST['action'] ) { // Save settings // Get settings array $settings = $this->get_settings(); // Set updated values foreach($this->options as $option){ if( $option['type'] == 'checkbox' && empty( $_REQUEST[ $option['id'] ] ) ) { $settings[ $option['id'] ] = 'off'; } else { if( array_key_exists( 'id', $option ) ){ $settings[ $option['id'] ] = $_REQUEST[ $option['id'] ]; } } } // Save the settings update_option( $this->settings_key, $settings ); header("Location: admin.php?page=" . $this->options_page . "&saved=true&message=1"); die; } else if( @$_REQUEST['action'] && 'reset' == $_REQUEST['action'] ) { // Start a new settings array $settings = array(); delete_option( $this->settings_key ); header("Location: admin.php?page=" . $this->options_page . "&reset=true&message=2"); die; } // Enqueue scripts & styles wp_enqueue_style( 'adsense-widget-admin', WP_PLUGIN_URL . "/adsense-widget/wpa/wpa-base.css", false, "1.0", "all"); } $page = add_options_page( __('Adsense Widget Options', 'adsense-widget') , __('Adsense Widget', 'adsense-widget'), 'edit_themes', $this->options_page, array( &$this, 'options_page') ); } function options_page(){ global $wpa_plugin; $wpa_plugin['title'] = "Adsense Widget Options"; $wpa_plugin['options'] = $this->options; $wpa_plugin['current'] = $this->get_plugin_settings(); $wpa_plugin['messages'] = array( "1" => __("Adsense Widget settings are saved.", "adsense-widget"), "2" => __("Adsense Widget settings are reset.", "adsense-widget") ); $wpa_plugin['nav'] = 'Plugin pageUsage Shortcode Donate'; /* include_once( "stf-page-options.php" ); */ wpa_load_template( 'wpa-options' ); } function widget($args, $instance) { extract( $args ); $widget_options = wp_parse_args( $instance, $this->widget_defaults ); extract( $widget_options, EXTR_SKIP ); $settings = $this->get_plugin_settings(); if( empty( $adsense_id ) ){ $adsense_id = $this->get_plugin_setting( 'adsense_id', '' ); } $msg = ''; if( empty( $adsense_id ) ){ echo "
Please enter your google ads id in the Adsense Widget Options Panel. (Help)
"; } else { if(!empty($slot) && $slot != ""){ $ad_slot = ' google_ad_slot = "'.$slot.'"; '; } else { $ad_slot = "\n\t /* ad slot is empty */ "; $ad_colors = ""; if( !empty( $settings['google_color_border'] ) ){ $ad_colors .= "\n\tgoogle_color_border = \"".$settings['google_color_border']."\";"; } if( !empty( $settings['google_color_link'] ) ){ $ad_colors .= "\n\tgoogle_color_link = \"".$settings['google_color_link']."\";"; } if( !empty( $settings['google_color_url'] ) ){ $ad_colors .= "\n\tgoogle_color_url = \"".$settings['google_color_url']."\";"; } if( !empty( $settings['google_color_text'] ) ){ $ad_colors .= "\n\tgoogle_color_text = \"".$settings['google_color_text']."\";"; } if( !empty( $settings['google_color_bg'] ) ){ $ad_colors .= "\n\tgoogle_color_bg = \"".$settings['google_color_bg']."\";"; } if(empty($ad_colors)){ $ad_colors = "/* adcolors not defined */"; } } if(!empty($channel)){ $ad_channel = ' google_ad_channel = "'.$channel.'"; '; } else { $ad_channel = "/* ad channel is empty */"; } $ad_type = ' google_ad_type = "'.$content.'"; '; $ad = $this->ad_types[$type]; $ad_class = $ad['classname']; $ad_size = $ad['script']; if( !current_user_can( $settings['hide_ads_for'] ) ){ echo $before_widget; if (!empty($instance['title'])) echo $before_title . apply_filters('widget_title', $instance['title']) . $after_title; // Echo adsense code echo "
"; // Script part echo " "; echo "
"; echo $after_widget; } elseif( current_user_can('administrator') && 'on' == $settings['show_placeholders'] ) { echo $before_widget; if (!empty($instance['title'])) echo $before_title . apply_filters('widget_title', $instance['title']) . $after_title; // Echo adsense code echo "
"; echo "
" . __("Adsense Unit") . "
" . $ad['name'] . "
"; echo "
"; echo $after_widget; } else { // Hide everything.. } } } function update($new_instance, $old_instance) { return $new_instance; } function form($instance) { $widget_options = wp_parse_args( $instance, $this->widget_defaults ); extract( $widget_options, EXTR_SKIP ); if (!empty($instance['title'])) $title = esc_attr($instance['title']); if (!empty($instance['type'])): $type = $instance['type']; else: $type = null; endif; if(empty($adsense_id)){ $adsense_id = get_option('shailan_adsense_id', ''); } ?>





Slot id for the ad you created.( Eg. 1234567890 )


Your channel id.( Eg. 1234567890 )