Adsense Manager プラグインを改良(Admin のときは広告を出さないように)

Adsense Manager プラグインはよくできてるけど、管理者としてログインしているときも広告が表示されるので、CTR(クリック率)がすごく低く評価されてしまう。
これはよくない気がするので、管理者の場合は表示されないようにしてみる。

ちょっとコードを見たけどよくわからないので、以下を参考にしてみる。

<?php
global $current_user;
if (!($current_user->ID)) { ?>

(コード)

<?php } ?>

Widget の表示を抑制

adsense-manager.php にちょっと手を加える。

	// This is the function that outputs adsensem widget.
	function widget($args,$n='') {
	  // $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); //nb. $name comes out of this, hence the use of $n
	  global $_adsensem;

	  /* ADMIN FIX */
	  global $current_user;
	  if (!($current_user->ID)) { // Don't show when logged in
	  /* ADMIN FIX END */
	  
		  //If name not passed in (Sidebar Modules), extract from the widget-id (WordPress Widgets)
		  if($n==''){ $n=substr($args['widget_id'],9); } //Chop off beginning adsensem- bit
		  if($n!=='default-ad'){$ad = $_adsensem['ads'][$n];} else {$ad = $_adsensem['ads'][$_adsensem['default-ad']];}
	
		  if($ad->show_ad_here()){
			echo $before_widget;
			if($ad->title!=''){ echo $before_title . $ad->title . $after_title; }
			echo $ad->get_ad(); //Output the selected ad
			echo $after_widget;
			$ad->counter_click();
		  }
          /* ADMIN FIX */
	  }
	  /* ADMIN FIX END */

	}

Post 内の表示を抑制する

こちらはテンプレートをいじればいい。

<div id="ad" class="post_body span-13 prepend-1 last">
  <?php if(function_exists('adsensem_ad')){ adsensem_ad("ad"); } ?>
</div>

これを以下のようにする。

  <?php 
    global $current_user;
    if (!($current_user->ID)) { // Don't show when logged in ?>
<div id="ad" class="post_body span-13 prepend-1 last">
  <?php if(function_exists('adsensem_ad')){ adsensem_ad("ad"); } ?>
</div>
  <?php } ?>