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.

37 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.

  17. Just installed and I get:

    “Fatal error: Call to undefined function get_site_option() in /home/[site/public_html/wp-content/plugins/adsense-share-mu.php on line 108″ Latest version of WP.

    Any ideas? Thanks

  18. Dave,
    This plugin is for WordPress-MU and not the regular WP version.

  19. This is a nice plugin.

    So when I am a sideadmin, I have blog.com and I have a user that has user.blog.com and he uses my setup adsense, he get’s a share of this ?

    Is this shown somewhere btw, what his share is over a month ?

    Now it would be possible that such a users sets this own adsense in this blog, that is not nice ofcourse.

    In such a case you need to add your adsense in the templates for sure, but a backwards compatible system where if the user adds adsense in a plugin way that the site admin get’s automaticly 20% of it ?

    If that woukd be possible, it won’t I think, that would be ideal !

    Keep up the good work :)

  20. Hello,

    I’m trying this plugin in my new Wordpress MU installation. But, only one widget is there namely “Google Adsense”. How to insert more than one AdUnit?

    Please help …

    Kaja.

  21. Mattz, the bloggers profits are not shown to the site admin. WordPress-Mu does not allow JS to be inserted so the bloggers can not place Adsense ads on their blogs.

    Kaja, there is only one widget. You can add more ads by placing them within the themes code.

  22. Elad, I want to start a free wordpress powered blog hosting with revenue sharing. I don’t want to code the themes directly. I want to give more freedom to the blog users, to select the placement & size of the Ad-Unit. Is there any way to increase the number of widgets?

  23. thanks a lot for this great script !

  24. Hi,

    I have 2 big errors:
    1. PHP error
    as a user, when i try to save the widgets after i added the Google Adsense widget, i get this error:
    Fatal error: Call to undefined function array_key_s() in /var/www/html/site/wp-content/plugins/adsense-share-mu.php on line 69

    2. JS error i think
    as a user, when i press remove button, it takes me on a page (/wp-admin/widgets.php) that is loaded forever and it says Sign up for AdSense.

    I have wordpress mu version: WordPress 2.5.1

    Please help.

    Thank you

  25. Is this plugin compatible with WPMU 1.5.1?

    I uploaded it fine and set everything up, but when I try to change the default 120 width and 240 height or anything for that matter in the backend, I get

    “Fatal error: Call to undefined function: array_key_s() in /home/sportsbl/public_html/wp-content/mu-plugins/adsense-share-mu.php on line 68″

    If i leave it alone and use the default settings it seems to work fine, but I’d really like to at least add a channel in adsense

  26. [...] dem Adsense Share for WPMU Plugin von Elad Salomons können mit Google Adsense erzielte Erträge mit anderen [...]

  27. Hey, when a user adds the Adsense Widget, the sidebar widget when activated pops up a blank page widgets.php and it just cycles. Any idea of what that is?

  28. Please please please make the widget work on wpmu 2.5+

  29. hopefully i’ll use this.
    so you 20% set admin pubId, and the rest client(publisher) ID.

    as You said “I will not deal with the ad code except for the google_ad_client which is the Adsense publisher code.”

    this will be OK until google not change the other parts of a code.

    when channels, or now, slots not from ad_client are.
    what then?

    i think you shoud exchange complete code.

    and client(publisher) can tell whitch format he used.
    you have all formats with you code in place. so use rigth this format.

    thanks
    SF

  30. Please make this compatible with WPMU version 2.6…

    i have tried it to implement but on Firefox it goes blank and on IE it simply crashes (on both cases I have tried to add it from widget menu).

  31. [...] have tried AdSense revenue sharing plugin for WordPress-MU developed by ringofblogs , it is wok for old versions and no updates for new [...]

  32. Hi all

    I have found updated version for WPMU version 2.6
    and working for me.
    http://blog.hoofoo.net/index.php/category/wordpress-mu/

    regards

  33. Gives error on line 118 when activated and crashes wp 2.6

    $default_your_adsense_share = get_site_option(’your_adsense_share’);

  34. Does this not have a version out for 2.6+?

  35. I would love for this to work… Would pay for it.

  36. This plugin is against Adsense TOS:

    Can I alter the AdSense ad code?
    Our program policies do not permit the modification of the AdSense code. Your publisher account offers a number of options when generating the ad code, that we hope will allow you to create an ad layout that fits in with your site.

    Please paste the AdSense ad code into your webpages without making any modifications.

    Again, please note that modification of the AdSense code is a violation of the AdSense program policies. For example, publishers may not:

    Alter the height or width of an ad unit from the standard options
    Implement the AdSense ad code in a “floating box script” or in a way that otherwise covers content
    Use any means to force the display of more than three AdSense ad units on a page
    Manipulate the ad targeting using hidden keywords, IFRAMEs, or any other method
    Distribute ads in emails or software

  37. Tiswa, since the output code should be the same as the one one you get from Google I don’t see the problem.

Leave a Reply