AdSense revenue sharing plugin for WordPress-MU

This is an updated version of the AdSense revenue sharing widget for WordPress-MU (in beta).

Two things before we start:

  1. To stay updated please subscribe to my RSS feed.
  2. If you use this plugin it can make you a lot of money. Please consider a donation using the PayPal button on the right - thanks :)

The AdSense revenue sharing plugin for WordPress-MU will allow you, the owner of a WPMU site, to share Adsense revenue with your users. You can set the percentage of your share (default is 20%) and enter your AdSense publisher code via the ‘Site Admin‘ backend panel.

adsense-share-1.PNG

The user can enter his Adsense publisher code in the ‘Options‘ menu:

adsense-share-4.PNG

Download: adsense-share-mu-123.zip

Current version: 1.2.3 (view change log below)

Installation: extract the adsense-share-mu.php file and upload it to the mu-plugins directory.

How to use?

Go to ‘Site Admin‘ -> ‘Adsense share‘ and set your Adsense share and your Adsense publisher code.

There are two option to insert Google Adsense ads and they can be used together:

  1. allow users to insert an Adsense widget to their sidebar (that is the easy and simple way). All your users will have to do is drag the ‘Google Adsense‘ widget to the sidebar, click the configuration icon and enter their google_ad_client ID.
  2. hard code ads into the themes.

The second method needs some explanations. Since Google is constantly changing the structure of the ads script and adding new features, I decided that I will not deal with the ad code except for the google_ad_client which is the Adsense publisher code.

To insert ads to your themes you should log into your Google Adsense account and select the product, ad type, ad format and colors, corners style, channels and whatever Google allows you to select. Once you are done you will get a code looking something like this:

<script type="text/javascript"><!--
google_ad_client = "pub-01234567890";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
//2007-10-07: Demo
google_ad_channel = "1234567890";
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

Simply copy this code and paste it wherever you want in your theme files. Note the second line starting with google_ad_client and ending with “pub-01234567890″;. The second part is your Adsense publisher code. If we don’t change that code you will get all the revenue from the ads and your user will not be happy. So we want to enter a piece of code that will iterate between the publishers codes. This is done by replacing the “pub-01234567890″; part with a simple line of code:


<?php get_adsense_code(); ?>;

if we want to be on the safe side we can add a check for the function:


<?php if (function_exists('get_adsense_code')) {get_adsense_code();} ?>;

So now the Adsense code looks like this:


<script type="text/javascript"><!--
google_ad_client = <?php if (function_exists('get_adsense_code')) {get_adsense_code();} ?>;
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
//2007-10-07: Demo
google_ad_channel = "1234567890";
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>

If you want to ad the ads only to your themes and not allow the users to ad the widget, there is a little hack which involves editing the plugin file. Open the adsense-share-mu.php file and look at line 14. If you change the no_widgettruetrue parameter to ‘true‘ the widget will not be available.

Change log

1.2.3
Fix security issue (everybody upgrade). Thanks NK5.

1.2.2
Fix a minor php bug.

1.2.1
Added an “;” at the end of the php code.

Please report and issues in the comments below.


Did you find this post interesting? Please subscribe to my feed.

16 Responses to “AdSense revenue sharing plugin for WordPress-MU”

  1. As trackback don’t seem to be published, I just post a special thanks for your work.

    I setup the plugin last night, and everything was done in 5 min.

    Just one thing : the made the next line of the google code to be on the same line… Nothing very important, in fact.

    I keep you inform if I get a problem.

  2. Hi,

    Widget not work on my WordPress-MU:

    Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /home/blogs/public_html/wp-content/mu-plugins/adsense-share-mu.php on line 22

  3. indeepdark:
    Didn’t understand the problem.
    What php version do you have

    Zup:
    Did you ever use an older version of the plugin?
    What php version do you have

  4. php 5.2.0-8

    After some test when adsense-share-mu.php is on FTP all widgets administration fail. When i remove the file, widgets administration work normaly.

    Sorry for BAD English :p

  5. Hi,

    I was just wondering, as it is a bit hard to explain to all user the AdSense rules, why not add a feature that would not display ads from one user when visiting his blog ?

    I don’t know how you can do that, maybe by checking if the user is logged in (but you may have problem if the user visit other blogs…), or maybe with a cookie….

    Well, that’s just seems important to me at the moment, but I don’t know how to solve that.

  6. I get this same error below with the latest 121 version. It breaks my other widgets when installed. If i revert back to the older version, all functions well

    Widget not work on my WordPress-MU:

    Warning: array_merge() [function.array-merge]: Argument #2 is not an array in /home/blogs/public_html/wp-content/mu-plugins/adsense-share-mu.php on line 22

  7. Gordo, what version of PHP are you using?

  8. hello

    i am using PHP 5.2.3

  9. Same error! using PHP 5.1.6

  10. Hi,
    It doesnt show any “AdSense Publisher’ submenu in the options menu for a normal user who owns a wpmu subdomain. Only shows it when I login as admin.

  11. Thanks for a great plugin

    This works a treat until you have more than one google ad unit on a page.

    If you have more than one ad unit in your template and each time it calls get_adsense_code() you could end up with two ad units u sing different publisher id’s which is against the Adsense ToC’s.

    I am sure there are ways round this but thought it was worth pointing out.

  12. Greg,

    Before I started to work on the plugin I asked Google Adsense support about it. My question was:
    “Can I place ads with two different publisher ids on the same page?”

    Their answer:
    “This does comply with our policies”

    I have the writing on record if you want it.

  13. Hey Greg, Elad,

    A simple workaround to the problem would be to store the publisher’s code into a variable, ie.,

    $pubcode=get_adsense_code();

    then use $pubcode in replacement with get_adsense_code() function.

    However, you’ll prob. need to get into get_adsense_code() function to return the publisher’s code, rather than echoing it out.

    Will be implementing your plugin on my parenting tips website!

  14. Steve

    I did exactly that - well almost.

    I have modified the plugin so the user can enter an adsense channel aswell as their own colors, using a default set of colors if none are entered. I have then at the top of each template I call a routine in the plugin which sets some javascript vars and these are then applied to all adsense units used on the page.

    I am neither a php or wordpresss expert hence my hack is not pretty so I have not gone public with it but it works for my needs.

    Elad, I’m glad that is the case, I had heard that someone else had been told the same thing but knowing Google I tend to urge on the side of caution:)

  15. I installed this plugin just now and i dont get that field where i can select how many % i want to share with my users.

    Is this feature removed or am i missing something? :|

  16. Please disregard my previous statement. I did not se the “adsense share” thingy in “Site Admin”.

    This really sounds like a great plugin. I hope its all that and a bag of lard!

    Thanks.

Leave a Reply