Categorie ‘Code’ » Archiv


Fast broken blog or working one? you choose


I just got another ticket off someone that is using a cache plugin and experiencing issues with a plugin.

BTW – Do you recommend NOT using W3TC? And, if so, is there a better one?

Here’s my response, maybe if you read it here then I wont have to type it again in a ticket!

oh that is a biggie! w3 total cache by definition will serve old copies of pages. That is what all cache plugins are designed to do.

it is quicker to serve a html copy than to generate one with php which is why they make sites faster.

unfortunately, blogs are dynamic sites with plugins that require freshly created content which don’t really work well with copies of pages that were made hours or even days ago.

static business sites that are there for information work really well with cache plugins because they rarely change but blogs with new posts and comments and ‘real time’ plugins installed don’t do so well.

w3 total cache is not yet final. That is why it is not showing as version 1.0 yet. You and me and all the others that use it are test subjects!

you have to decide if you want a fast broken blog or a working one.

there are blogs (including mine) that have w3 working with everything else but each blog is different and has different plugins active so you will have to find your own set of settings that works for you.

unforunately, w3 is the best (or the least bad) of the cache plugins but like I said, cache plugins are designed to serve old content and blogs are designed to serve fresh content. that’s the issue that comes up again and again with any cache plugin and a blog.

sorry I can’t help more but w3 is a beast of a plugin and the author keeps changing the core code so I can’t add things to commentluv to work with it, the last time I tried it worked but as soon as he updated his code it broke every commentluv blog so I don’t try any more.

the best advice I can give is to optimize your site first before considering a cache plugin, you’d be surprised at how much that can help.

and if you do decide on a cache plugin, test test test!

The takeaways…
  • If you do not know what a cache plugin does then you do not need one!
  • If you have a slow broken site, a cache plugin will not fix it!
  • If minifying breaks one script, it breaks them all!
  • Scripts that are already minified (jquery.min.js) do not need to be minified!
  • You should optimize your site before you try to speed it up with cache plugins!
  • test test test .. experiment with settings to see what gets you a working site and then test test test again!
  • Switching every option to MAX and then expecting it just to work is not really gonna happen on shared hosting with a free theme and a bazillion free plugins.

Blog News, Code


WordPress coupon plugin – special offer


Here’s a way for you to add a [hpl_link url="" tooltip="get this plugin at a discount" effect="blink" repeat="10000" speed="4" color="#ffcc00"]countdown offer timer[/hpl_link] to your site so offers and other exclusive content gives your readers and extra push to click through to them. If you want to make a wordpress countdown coupon offer then this is the plugin that you need.

WordPress Coupon Plugin makes it easy

You can get the plugin here >>

Just use the plugin to make an embedded youtube video inside the offer box and you’ve got a ready to go solution for creating a scarcity type offer.

It’s only ten buckeroos at the link above.



Which works better? – video or text based sales pages – my split test results


Split Test Your Site

Just recently I got bullied in to setting up an A/B split test for my CommentLuv Premium homepage. Well, not bullied but guilt tripped. :)

I got another email preaching about why split tests are such a good idea so finally, at long last, I decided I would set up a split test to see what type of sales page worked better for me.

I wanted to try a different page than the huge video as the focus one and so as the B part of the split test I tried a new variation that uses mainly text to describe the main benefits of the plugin.

Google Website Optimizer Makes it Easy to Split Test!

It’s dead simple to set up a new A/B split test experiment with just a little bit of help from the Website Optimizer that Google provides.

You just need to identify what page is your original (your A) and your alternate page (your B) and your conversion page.

Add a bit of script that Google gives you to each page, verify them and let the experiment run.

I could give you a blow by blow tutorial here but to be honest, you get a very good one on the site which goes in to much more detail than : Website Optimizer Documentation

Winner winner chicken dinner!

I let the experiment run for a whole week and at the end, the results were undeniable!

This is the original page

split test original (the A)

This is the variation

split test variation (the B)

Guess which one won?

Yup, the first one did! by a factor of 2. It converted exactly twice the number of visitors as the variation so the conclusion is (as you might have guessed) that video sells twice as much as text!

In next weeks split test

Now I know which page wins, I can move on to multivariate testing where I use the same page but jiggle the things about to see if below the video a guarantee seal works better or a testimonial would convert more people.

I’ll let it run all this week and see what happens and report back. oh how exciting!

Get your own split testing done!

You can see a whole bunch of split test results here which will open your eyes to some cool things that you wouldn’t think would make a difference but do!

Code, Tutuorial


How to fix radio inputs losing focus when dragging a jquery ui sortable div


hows that for a descriptive title eh? haha, that’s the exact term I used when I ran into trouble with some wordpress meta boxes on a custom admin page I was making for the new CommentLuv. I am using the WordPress functions for add_meta_box to add, you guessed it, meta boxes to a settings page.

Draggable killed the radio bar

ok, lame Queen song title parody I know but it’s true. I had a bar of radio buttons in one of those meta boxes and if I dragged and dropped the box to a new place, it lost it’s radio button dots!

When I dropped the sortable meta box, the happy little dot in the radio input would disappear which messed things up when I saved the settings because the form would not have a radio input with a status of checked any more. :-(

jQuery rescues jQuery!

jQuery is frickin awesome and I love it. It’s the sole reason CommentLuv was able to become the plugin it is today. It’s also sometimes a little finicky and it does things in a particular way which causes some mild issues. This is one of them, it’s all due to jQuery cloning the contents of the sortable box when you drag it and then when you drop it, the radio button loses it’s happy little dot.

I did a mammoth amount of searching and could only find 2 instances of it happening elsewhere (here and here) and both instances said it was a bug/feature and didn’t provide a solution.

Geek me up, I’m goin in!

[youtube clip_id="Z9_jIa2WADc"/]

As a means to procrastinate, an unhealthily strong stubbornness bone and a burning sensation in my pants whenever I can’t do something that I want to do, I set about trying some code to re click the radio buttons after the meta box had been dropped after dragging.

Here it is, I hope you find it useful! (change the two instances of .wrap to whatever container your sortables are in)

// global script for commentluv premium settings pages
// workaround for bug that causes radio inputs to lose settings when meta box is dragged.
    // listen for drag drop of metaboxes , bind mousedown to .hndle so it only fires when starting to drag
        // set event listener for mouse up on the content .wrap and wait a tick to give the dragged div time to settle before firing the reclick function
        jQuery('.wrap').mouseup(function(){store_radio(); setTimeout('reclick_radio();',50);});
* stores object of all radio buttons that are checked for entire form
function store_radio(){
    var radioshack = {};
            radioshack[jQuery(this).attr('name')] = jQuery(this).val();
* detect mouseup and restore all radio buttons that were checked
function reclick_radio(){
    // get object of checked radio button names and values
    var radios = jQuery(document).data('radioshack');
    //step thru each object element and trigger a click on it's corresponding radio button
    for(key in radios){
    // unbind the event listener on .wrap  (prevents clicks on inputs from triggering function)

ajax, Code, jquery, PHP


Bypass / Disable print dialog box in firefox with javascript print()


Just print!

In my ePoS system project, I have the need to open a popup with javascript and print the contents without seeing the dialog box.

Everywhere I searched, there were the ‘you don’t wanna do that because….’ from know it all keyboard warriors saying it was bad because evil doers could send porn to your printer.

What about intranets and web apps?

Finally, I figured it out and as long as you’re using Firefox and you have access to it then you’re ready to make it print without a nasty dialog…

  • Open firefox and put about:config in the address bar and press enter (you will need to click the button that shows to say you know what you’re doing)
  • Type print.always_print_silent in the filter box at the top
    If you have an entry already there and it is set to false just right click it and choose ‘toggle’ to set it to true.
    If there is no entry there already then follow on…

    • right click the screen and choose New->boolean
    • enter print.always_print_silent as the preference name when asked and press enter
    • set boolean value to true and press enter

That’s it, you will no longer see the dialog box when you print. Beware though, it will try to print to the last printer you used when you had the dialog box open. If you ever need to change it then you will need to toggle the value for print.always_print_silent by following the above steps.

Open a javascript popup and print the contents

Now you can print without dialogs, you can use the following code to open a popup window and print it.

open the popup

windowname ='url.html','name',options);

the options you have available are:

Option Values Description
location yes|no Does the location bar show?
menubar yes|no Does the menubar show?
scrollbars yes|no Do scrollbars show?
status yes|no Does the status bar show|
titlebar yes|no Does the titlebar show?
toolbar yes|no Does the toolbar show?
resizable yes|no Can you resize the window?
height pixels height of window
width pixels width of window
directories yes|no Does the personal toolbar show?
innerHeight pixels specifies the inner height of window
innerWidth pixels specifies the inner width of window
screenX pixels specifies distance from left edge of screen
screenY pixels specifies distance from top edge of screen

For example, to open a pop window showing the file called example.html with no menu bar, with a width of 430 pixels, height of 700 pixels, no toolbar, with scrollbars and with the window you would use this command

winname ='/example.html','newwin','menubar=no,width=430,height=700,toolbar=no,scrollbars=yes,screenX=300');

To close that window, you can add this


To print the window, you can add this to the example.html page


or to print it from the calling page, you might need to pause for a little while before issuing the print command so it has time to load the page content first..


All the commands need to be within <script> /script tags



You’re taking the PoS!


I’ve had to put my partnership project on hold for the entire month of December so I can work on a new PoS system for our takeaway shop. OMG, I’ve been saying I was going to do it since we moved up here and took over the business and finally, I will be sitting down at the PC and attempting the job.

Why not buy one?

Hah! you do know I’m working in a CHINESE takeaway don’t you? :-D One thing I’ve learned about Chinese businesses is that if you can get away with using something that doesn’t cost money then do. LOL, the only thing that doesn’t apply to (thank heavens) is food and food preparation equipement.

Seriously though, I’ve tried all sorts of other PoS systems and to be honest, they all look like utter shite! They’re still in the old style of Windows and look like they’ve been coded for DOS. Besides, none of them have the features we need like automatic mapping and all the options that we require for menu adjustments. We also need it to be bilingual too..

Good Start

I already have my own caller id system written in Visual Basic that opens up a page on my local server that handles customers details and shows exactly where they live and directions to get there. My first step is to get that integrated into the new wordpress plugin which I’ve started that uses custom post types for the menu items.

I’m hoping that all the code I’ve been doing over the past 6 months has put me in good stead to complete the project.

Quiet please…

For the entire month I will be quiet. yup. shhhhh!



A new luv in my life


I’ve started coding the upgrade to my CommentLuv plugin, it’s going to be called CommentLuv 3.0 (original huh?) :)

More features than you can shake a stick at

This time around I want to do it all again from scratch and I’ve already got a good idea of what I’m going to add to it.

  • Dofollow
    Just for the last blog post link and it’ll be configurable like Lucia’s linky luv plugin
  • Keyword luv (sort of)
    This will allow a registered comluv user to have their registered site name next to their real name in their comment.
  • Custom CSS
    How many people have been asking for this? lol, it’ll be in the new version!
  • Use the new comment meta table
    I’ll store the last blog post, user id and request id in the comment meta so the comment text doesn’t get mangled and every link will be identifiable by the info panel. no more ‘cannot find member’ messages.
  • Auto registration
    Why not allow the blog that installs commentluv to click a button and be registered straight away? yey!
  • Premiumness
    I would like to add premium options, one would be to allow you to give your registered users a full 10 posts to choose from when they comment.

If there’s more you want to add, let me know in the comments…

[edit] I’ve just realized, this post is number 300 on this blog. Synchronicity. mmm Yummy.

Code, Wordpress


Never lose your source code, ever!


Twice. In 1 week.

I lost my code and my awesome plugin edits when my hard drive crashed, I started writing it again and I formatted the wrong partition. Seriously gutted! I tried to recover the data with undelete apps but it was gone forever.

No worry no more!

Now, I don’t need to worry because I use Dropbox and have configured my local server to use it as the document_root of my dev site. That way, all the developing work I’m doing gets saved automatically online and is accessible on any of my pc’s.

I don’t even need to worry about being able to access the SAMBA share if I want to edit a file, I just open it from my dropbox on the pc I’m using and save it back there, it’ll get automatically updated on my dev server.

Oops no more!

Another advantage is the revisions feature. You can go online and see the updates that you made to a file and revert it back to an earlier save. This has already saved me from crying, I always forget to rename a file before I start trying to add updates and before I know it, the whole thing is causing an error and I can’t remember how to put it back the way it was! just luvin the revision feature!!

Get 2GB for FREE! (and help me out)

You can apply for a Dropbox for FREE and get a full 2GB to use to store anything from simple documents to executable files to database backups or like me, use it as your code repository and never go through the pain of a lost bit of awesome code again!

You can even install it on Linux which is super helpful when it comes to transferring files between a windows->linux network.

If you click this link and install your dropbox for free, we both get extra bonus space which would help me out a lot :)

Blog Tools, Code, Uncategorized


Taming the Upgrades plugin from


If you’re lucky enough to have a subscription to Premium WPMU Dev account then you’ll have access to great monetization plugins like the Upgrades or Supporter which take all the pain out of providing a ‘pay for’ service that can handle payments through Paypal, Google or even Amazon gateways.

I downloaded and installed the upgrades plugin a while ago and I’ve used it to monetize certain parts of my ComLuv site. There’s the usual way of adding plugins to the Upgrades directory and configuring them to be used which I’ll go into in a future post but I wanted to use the system slightly differently, and that was to charge users for adding new URLs to an account or to add default links to their returned list of posts.

The advantage of premium

Some of the advantages to using wpmupremium plugins is the support you receive, knowledge that the plugin will be updated to keep it compatible with new changes and my favourite is, the quality of the code.

When you’re getting premium, you’re getting premium code which for me personally, has taught me a LOT about how wordpress works. Particularly custom hooks and actions and filters. That was always a mystery to me until I dissected the plugins I downloaded from their site so it was a breeze to modify the upgrades plugin to work for users who don’t have blogs and start using the internal functions in a daughter template to do what I wanted.

Modifying the upgrades plugin

I needed to allow the upgrades menu to show for regular users because not everyone who joins the Comluv site starts a blog. This was just a simple case of changing the user level so that everyone, not just blog owners can see the menu and buy credits.

There are two places to modify:

line ~ 197-200 (upgrades plug pages framework function)
change add menu and submenu calls to

add_menu_page($upgrades_branding_plural, $upgrades_branding_plural, 0, 'upgrades.php');
add_submenu_page('upgrades.php', __('Credits'), __('Credits'), 0, 'credits', 'upgrades_credits_output' );
add_submenu_page('upgrades.php', __('History'), __('History'), 0, 'history', 'upgrades_log_output' );

line ~ 1919 (upgrades_credits_output function)
change user check to

if(!current_user_can('level_0')) {

Creating the daughter template

Adding another page you can use as a template is pretty easy, you just need to create a new php file in your theme directory and make sure it has the correct remarks at the top to identify it as a template page.

Template Name: ComLuv purchase url

Next just copy and paste the main calls from another template, you’ll be deleting most of it like the loop to display posts and replacing it with your own hard coded form and text. Be sure to keep the divs that surround the content intact.

I wrote a description of the item being sold and added a form.
(DON’T copy and paste from this page, I had to remove the beginning < characters from the code so it displays properly)

form action='/member/additional-urls/' method="POST">
input name="addurl" type="text" size="30"/>
input type="submit" name="submit1" value="Submit"/>


I also added a finish_page() function which just closes the /div tags so I could easily break out of what I was displaying without rendering the rest of the custom code below it.

You set the action to the page slug you’re publishing the page as and put a nonce field in there so you can check it with the next bit of code to prevent a naughty user from trying to call the purchase directly.

Handling the purchase

Next, you need to handle the data that gets submitted by your form and do the magic with the users credits.

echo 'Page request deformed, please go back and try again. (b1s1)';
echo 'Please go back and enter a value';
// check if user has enough credits
global $user_ID;
$credits = upgrades_user_credits_available($user_ID);
if($credits < 3){
echo 'h2>Error - Insufficient Credits/h2>';
echo 'p>You will need to purchase some credits to register another URL, you currently have strong>'.$credits.'/strong>';
echo 'p>a href="/wp-admin/upgrades.php?page=credits">Click here to visit the purchase page/a>';
// if we're here then everything is ok to provide service and deduct credits
$credits = upgrades_user_credits_available($user_ID);
$credits -= 3;
upgrades_log_add_msg($user_ID,'You paid 3 credits for an additional URl - '.$url);
echo 'h2>Site added, 3 credits used on your account/h2>';
echo 'p>You have '.$credits.' credits remaining';
echo 'p>a href="/member/additional-urls/">Click here to refresh the page/a>';

The first bit gets the nonce you created and checks it and displays an error message if it doesn’t match
Next, check the field you’re expecting and spit out an error if it is empty.
Next, check the user has enough credits and spit out an error if they don’t.
If everything is fine, continue.

use $credits = upgrades_user_credits_available($user_ID); to get the users current credits total
use upgrades_user_credits_update($credits); to set the users credits total to $credits (after you deduct what your item/upgrade costs)
use upgrades_log_add_msg($user_ID,’You paid 3 credits for an additional URl – ‘.$url); to add a message to the users Credits history page so they know they used some.

That’s it, easy peasy! Here’s an idea, use credits to sell digital downloads on another page, just check and deduct the users credits before allowing a dowload.

I’ll post a follow up to this soon on how to use the upgrades plugin to add a new package that enables the RSS widget for a blog (I’ll show you how to disable the rss widget too)

You can get over 100 plugins and themes of premium quality at and they all help to make your wpmu site better than the jones’s :)

Blog Tools, Making / Made Money, PHP, Wordpress


They go in 3′s too


You know how the expression says that problems come in 3′s ? I get 3 lots of 3′s most of time but this week I think I have managed to get rid of 3 problems.

I was posting about my woes at Comluv and just a few days later I finally managed to track down the random freezes on my AsRock M3A790GXH – 128M motherboard and OCZ DDR3 Gold Series RAM

Random crashes on Vista/7 – AsRock M3A790GXH/128M with OCZ DDR3 Gold RAM – Solved

Shiny, SHINY! RAM!

Shiny, SHINY! RAM!

The crashes were driving me crazy, I could never repeat the action that caused the crash and there was never any entry in the event log except for after the reboot. I tried removing one stick and running it with that one to see if it was a faulty stick, it crashed on the first try so I thought that was it but after swapping it with the other stick, the pc crashed within a day. :(

It turns out that OCZ DDR3 RAM needs 1.9v instead of the regular 1.5v that it would get from the motherboard. A quick visit to the bios and I switched the DRAM voltage to 2.0v and the pc has been up and running for days without a problem. yey!

Dedicated server non responsive after high traffic – solved

They put the fast in, um, ukfast :)

They put the fast in, um, ukfast :)

Another problem was my server, it is fast and a nice bit of kit but it was getting overloaded at times with so many requests to the CommentLuv API. I had a word with UKFast explaining to them that I expected my server to be able to stay up if a lot of traffic came in. They did their utmost to help and sent me a very nicely priced invoice to beef up my server with an extra 1 GB of RAM.

It’s been up for 7 days and the CTM graphs are showing me that my CPU usage and system load are down a lot from what they’ve been.

Monthly view upgrade shows better performance

Monthly view upgrade shows better performance

Looks more dramatic on the 1 year chart

Looks more dramatic on the 1 year chart

My last issue was my laptop charger, it went poof! I did a search online for a universal charger and the best price I could see was over 60 quid! luckily, I was able to buy a Toshiba charger from ebay for 9.99 for next day delivery.

sorted! (for now)

Blog News, Code